2021-05-10 03:57:45 -04:00
|
|
|
// 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 (
|
2021-09-22 01:38:34 -04:00
|
|
|
"io"
|
2021-06-23 15:38:19 -04:00
|
|
|
"net/http"
|
2021-05-10 03:57:45 -04:00
|
|
|
|
|
|
|
myCtx "code.gitea.io/gitea/modules/context"
|
2021-07-24 12:03:58 -04:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
2021-06-23 15:38:19 -04:00
|
|
|
"code.gitea.io/gitea/modules/private"
|
2021-11-16 10:25:33 -05:00
|
|
|
"code.gitea.io/gitea/services/migrations"
|
2021-05-10 03:57:45 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// RestoreRepo restore a repository from data
|
|
|
|
func RestoreRepo(ctx *myCtx.PrivateContext) {
|
2021-09-22 01:38:34 -04:00
|
|
|
bs, err := io.ReadAll(ctx.Req.Body)
|
2021-05-10 03:57:45 -04:00
|
|
|
if err != nil {
|
2021-06-23 15:38:19 -04:00
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 03:57:45 -04:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2022-01-20 12:46:10 -05:00
|
|
|
params := struct {
|
2021-05-10 03:57:45 -04:00
|
|
|
RepoDir string
|
|
|
|
OwnerName string
|
|
|
|
RepoName string
|
|
|
|
Units []string
|
|
|
|
}{}
|
|
|
|
if err = json.Unmarshal(bs, ¶ms); err != nil {
|
2021-06-23 15:38:19 -04:00
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 03:57:45 -04:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := migrations.RestoreRepository(
|
2021-05-31 02:18:11 -04:00
|
|
|
ctx,
|
2021-05-10 03:57:45 -04:00
|
|
|
params.RepoDir,
|
|
|
|
params.OwnerName,
|
|
|
|
params.RepoName,
|
|
|
|
params.Units,
|
|
|
|
); err != nil {
|
2021-06-23 15:38:19 -04:00
|
|
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
|
|
|
Err: err.Error(),
|
2021-05-10 03:57:45 -04:00
|
|
|
})
|
|
|
|
} else {
|
2021-06-23 15:38:19 -04:00
|
|
|
ctx.Status(http.StatusOK)
|
2021-05-10 03:57:45 -04:00
|
|
|
}
|
|
|
|
}
|