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.1KB

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