2021-05-10 13:27:45 +05:30
|
|
|
// 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"
|
2021-06-24 01:08:19 +05:30
|
|
|
"net/http"
|
2021-05-10 13:27:45 +05:30
|
|
|
|
|
|
|
myCtx "code.gitea.io/gitea/modules/context"
|
2021-07-24 21:33:58 +05:30
|
|
|
"code.gitea.io/gitea/modules/json"
|
2021-05-10 13:27:45 +05:30
|
|
|
"code.gitea.io/gitea/modules/migrations"
|
2021-06-24 01:08:19 +05:30
|
|
|
"code.gitea.io/gitea/modules/private"
|
2021-05-10 13:27:45 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// RestoreRepo restore a repository from data
|
|
|
|
func RestoreRepo(ctx *myCtx.PrivateContext) {
|
|
|
|
bs, err := ioutil.ReadAll(ctx.Req.Body)
|
|
|
|
if err != nil {
|
2021-06-24 01:08:19 +05:30
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 13:27:45 +05:30
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var params = struct {
|
|
|
|
RepoDir string
|
|
|
|
OwnerName string
|
|
|
|
RepoName string
|
|
|
|
Units []string
|
|
|
|
}{}
|
|
|
|
if err = json.Unmarshal(bs, ¶ms); err != nil {
|
2021-06-24 01:08:19 +05:30
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 13:27:45 +05:30
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := migrations.RestoreRepository(
|
2021-05-31 11:48:11 +05:30
|
|
|
ctx,
|
2021-05-10 13:27:45 +05:30
|
|
|
params.RepoDir,
|
|
|
|
params.OwnerName,
|
|
|
|
params.RepoName,
|
|
|
|
params.Units,
|
|
|
|
); err != nil {
|
2021-06-24 01:08:19 +05:30
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 13:27:45 +05:30
|
|
|
})
|
|
|
|
} else {
|
2021-06-24 01:08:19 +05:30
|
|
|
ctx.Status(http.StatusOK)
|
2021-05-10 13:27:45 +05:30
|
|
|
}
|
|
|
|
}
|