2021-05-10 09:57:45 +02:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-05-10 09:57:45 +02:00
|
|
|
|
|
|
|
package private
|
|
|
|
|
|
|
|
import (
|
2021-09-22 07:38:34 +02:00
|
|
|
"io"
|
2021-06-23 21:38:19 +02:00
|
|
|
"net/http"
|
2021-05-10 09:57:45 +02:00
|
|
|
|
2021-07-24 18:03:58 +02:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
2021-06-23 21:38:19 +02:00
|
|
|
"code.gitea.io/gitea/modules/private"
|
2024-02-27 08:12:22 +01:00
|
|
|
myCtx "code.gitea.io/gitea/services/context"
|
2021-11-16 16:25:33 +01:00
|
|
|
"code.gitea.io/gitea/services/migrations"
|
2021-05-10 09:57:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// RestoreRepo restore a repository from data
|
|
|
|
func RestoreRepo(ctx *myCtx.PrivateContext) {
|
2021-09-22 07:38:34 +02:00
|
|
|
bs, err := io.ReadAll(ctx.Req.Body)
|
2021-05-10 09:57:45 +02:00
|
|
|
if err != nil {
|
2021-06-23 21:38:19 +02:00
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 09:57:45 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2022-01-20 18:46:10 +01:00
|
|
|
params := struct {
|
2022-01-26 10:45:51 +01:00
|
|
|
RepoDir string
|
|
|
|
OwnerName string
|
|
|
|
RepoName string
|
|
|
|
Units []string
|
|
|
|
Validation bool
|
2021-05-10 09:57:45 +02:00
|
|
|
}{}
|
|
|
|
if err = json.Unmarshal(bs, ¶ms); err != nil {
|
2021-06-23 21:38:19 +02:00
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 09:57:45 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := migrations.RestoreRepository(
|
2021-05-31 08:18:11 +02:00
|
|
|
ctx,
|
2021-05-10 09:57:45 +02:00
|
|
|
params.RepoDir,
|
|
|
|
params.OwnerName,
|
|
|
|
params.RepoName,
|
|
|
|
params.Units,
|
2022-01-26 10:45:51 +01:00
|
|
|
params.Validation,
|
2021-05-10 09:57:45 +02:00
|
|
|
); err != nil {
|
2021-06-23 21:38:19 +02:00
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 09:57:45 +02:00
|
|
|
})
|
|
|
|
} else {
|
2023-05-22 03:38:38 +02:00
|
|
|
ctx.PlainText(http.StatusOK, "success")
|
2021-05-10 09:57:45 +02:00
|
|
|
}
|
|
|
|
}
|