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