diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/private/internal.go | 1 | ||||
-rw-r--r-- | routers/private/restore_repo.go | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/routers/private/internal.go b/routers/private/internal.go index e541591a38..15a393c530 100644 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -69,6 +69,7 @@ func Routes() *web.Route { r.Post("/manager/add-logger", bind(private.LoggerOptions{}), AddLogger) r.Post("/manager/remove-logger/{group}/{name}", RemoveLogger) r.Post("/mail/send", SendEmail) + r.Post("/restore_repo", RestoreRepo) return r } diff --git a/routers/private/restore_repo.go b/routers/private/restore_repo.go new file mode 100644 index 0000000000..c002de874a --- /dev/null +++ b/routers/private/restore_repo.go @@ -0,0 +1,51 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package private + +import ( + "io/ioutil" + + myCtx "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/migrations" + jsoniter "github.com/json-iterator/go" +) + +// RestoreRepo restore a repository from data +func RestoreRepo(ctx *myCtx.PrivateContext) { + json := jsoniter.ConfigCompatibleWithStandardLibrary + bs, err := ioutil.ReadAll(ctx.Req.Body) + if err != nil { + ctx.JSON(500, map[string]string{ + "err": err.Error(), + }) + return + } + var params = struct { + RepoDir string + OwnerName string + RepoName string + Units []string + }{} + if err = json.Unmarshal(bs, ¶ms); err != nil { + ctx.JSON(500, map[string]string{ + "err": err.Error(), + }) + return + } + + if err := migrations.RestoreRepository( + ctx.Req.Context(), + params.RepoDir, + params.OwnerName, + params.RepoName, + params.Units, + ); err != nil { + ctx.JSON(500, map[string]string{ + "err": err.Error(), + }) + } else { + ctx.Status(200) + } +} |