You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

restore_repo.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package private
  5. import (
  6. "io"
  7. "net/http"
  8. myCtx "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/json"
  10. "code.gitea.io/gitea/modules/private"
  11. "code.gitea.io/gitea/services/migrations"
  12. )
  13. // RestoreRepo restore a repository from data
  14. func RestoreRepo(ctx *myCtx.PrivateContext) {
  15. bs, err := io.ReadAll(ctx.Req.Body)
  16. if err != nil {
  17. ctx.JSON(http.StatusInternalServerError, private.Response{
  18. Err: err.Error(),
  19. })
  20. return
  21. }
  22. params := struct {
  23. RepoDir string
  24. OwnerName string
  25. RepoName string
  26. Units []string
  27. Validation bool
  28. }{}
  29. if err = json.Unmarshal(bs, &params); err != nil {
  30. ctx.JSON(http.StatusInternalServerError, private.Response{
  31. Err: err.Error(),
  32. })
  33. return
  34. }
  35. if err := migrations.RestoreRepository(
  36. ctx,
  37. params.RepoDir,
  38. params.OwnerName,
  39. params.RepoName,
  40. params.Units,
  41. params.Validation,
  42. ); err != nil {
  43. ctx.JSON(http.StatusInternalServerError, private.Response{
  44. Err: err.Error(),
  45. })
  46. } else {
  47. ctx.Status(http.StatusOK)
  48. }
  49. }