2021-05-10 13:27:45 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2021-05-10 13:27:45 +05:30
|
|
|
|
|
|
|
package private
|
|
|
|
|
|
|
|
import (
|
2021-09-22 11:08:34 +05:30
|
|
|
"io"
|
2021-06-24 01:08:19 +05:30
|
|
|
"net/http"
|
2021-05-10 13:27:45 +05:30
|
|
|
|
2021-07-24 21:33:58 +05:30
|
|
|
"code.gitea.io/gitea/modules/json"
|
2021-06-24 01:08:19 +05:30
|
|
|
"code.gitea.io/gitea/modules/private"
|
2024-02-27 12:42:22 +05:30
|
|
|
myCtx "code.gitea.io/gitea/services/context"
|
2021-11-16 20:55:33 +05:30
|
|
|
"code.gitea.io/gitea/services/migrations"
|
2021-05-10 13:27:45 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// RestoreRepo restore a repository from data
|
|
|
|
func RestoreRepo(ctx *myCtx.PrivateContext) {
|
2021-09-22 11:08:34 +05:30
|
|
|
bs, err := io.ReadAll(ctx.Req.Body)
|
2021-05-10 13:27:45 +05:30
|
|
|
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
|
|
|
|
}
|
2022-01-20 23:16:10 +05:30
|
|
|
params := struct {
|
2022-01-26 15:15:51 +05:30
|
|
|
RepoDir string
|
|
|
|
OwnerName string
|
|
|
|
RepoName string
|
|
|
|
Units []string
|
|
|
|
Validation bool
|
2021-05-10 13:27:45 +05:30
|
|
|
}{}
|
|
|
|
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,
|
2022-01-26 15:15:51 +05:30
|
|
|
params.Validation,
|
2021-05-10 13:27:45 +05:30
|
|
|
); 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 {
|
2023-05-22 07:08:38 +05:30
|
|
|
ctx.PlainText(http.StatusOK, "success")
|
2021-05-10 13:27:45 +05:30
|
|
|
}
|
|
|
|
}
|