mirror of
https://github.com/acepanel/panel.git
synced 2026-02-06 18:47:31 +08:00
feat: 网站备份管理与上传备份500修复
This commit is contained in:
@@ -327,9 +327,16 @@ func (r *WebsiteController) UpdateRemark(ctx http.Context) http.Response {
|
||||
// @Tags 网站管理
|
||||
// @Produce json
|
||||
// @Security BearerToken
|
||||
// @Success 200 {object} SuccessResponse{data=[]services.BackupFile}
|
||||
// @Param data body commonrequests.Paginate true "request"
|
||||
// @Success 200 {object} SuccessResponse{data=[]services.BackupFile}
|
||||
// @Router /panel/website/backupList [get]
|
||||
func (r *WebsiteController) BackupList(ctx http.Context) http.Response {
|
||||
var paginateRequest commonrequests.Paginate
|
||||
sanitize := Sanitize(ctx, &paginateRequest)
|
||||
if sanitize != nil {
|
||||
return sanitize
|
||||
}
|
||||
|
||||
backupList, err := r.backup.WebsiteList()
|
||||
if err != nil {
|
||||
facades.Log().Request(ctx.Request()).Tags("面板", "网站管理").With(map[string]any{
|
||||
@@ -338,7 +345,26 @@ func (r *WebsiteController) BackupList(ctx http.Context) http.Response {
|
||||
return ErrorSystem(ctx)
|
||||
}
|
||||
|
||||
return Success(ctx, backupList)
|
||||
startIndex := (paginateRequest.Page - 1) * paginateRequest.Limit
|
||||
endIndex := paginateRequest.Page * paginateRequest.Limit
|
||||
if startIndex > len(backupList) {
|
||||
return Success(ctx, http.Json{
|
||||
"total": 0,
|
||||
"items": []services.BackupFile{},
|
||||
})
|
||||
}
|
||||
if endIndex > len(backupList) {
|
||||
endIndex = len(backupList)
|
||||
}
|
||||
pagedBackupList := backupList[startIndex:endIndex]
|
||||
if pagedBackupList == nil {
|
||||
pagedBackupList = []services.BackupFile{}
|
||||
}
|
||||
|
||||
return Success(ctx, http.Json{
|
||||
"total": len(backupList),
|
||||
"items": pagedBackupList,
|
||||
})
|
||||
}
|
||||
|
||||
// CreateBackup
|
||||
@@ -389,7 +415,7 @@ func (r *WebsiteController) CreateBackup(ctx http.Context) http.Response {
|
||||
// @Security BearerToken
|
||||
// @Param file formData file true "备份文件"
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/website/uploadBackup [post]
|
||||
// @Router /panel/website/uploadBackup [put]
|
||||
func (r *WebsiteController) UploadBackup(ctx http.Context) http.Response {
|
||||
file, err := ctx.Request().File("file")
|
||||
if err != nil {
|
||||
|
||||
@@ -114,7 +114,7 @@ func (s *BackupImpl) WebsiteRestore(website models.Website, backupFile string) e
|
||||
return errors.New("备份文件不存在")
|
||||
}
|
||||
|
||||
if _, err := tools.Exec(`rm -rf '` + website.Path + `/*'`); err != nil {
|
||||
if err := tools.Remove(website.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tools.UnArchive(backupFile, website.Path); err != nil {
|
||||
|
||||
@@ -16,6 +16,8 @@ func init() {
|
||||
"fiber": map[string]any{
|
||||
// prefork mode, see https://docs.gofiber.io/api/fiber/#config
|
||||
"prefork": false,
|
||||
// Optional, default is 4MB
|
||||
"body_limit": 4000,
|
||||
"route": func() (route.Route, error) {
|
||||
return fiberfacades.Route("fiber"), nil
|
||||
},
|
||||
|
||||
19
docs/docs.go
19
docs/docs.go
@@ -1032,6 +1032,17 @@ const docTemplate = `{
|
||||
"网站管理"
|
||||
],
|
||||
"summary": "获取备份列表",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/commonrequests.Paginate"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@@ -1177,7 +1188,7 @@ const docTemplate = `{
|
||||
}
|
||||
},
|
||||
"/panel/website/uploadBackup": {
|
||||
"post": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"BearerToken": []
|
||||
@@ -1930,7 +1941,7 @@ const docTemplate = `{
|
||||
"ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2089,7 +2100,7 @@ const docTemplate = `{
|
||||
"ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"raw": {
|
||||
@@ -2334,7 +2345,7 @@ const docTemplate = `{
|
||||
"ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"remark": {
|
||||
|
||||
@@ -1025,6 +1025,17 @@
|
||||
"网站管理"
|
||||
],
|
||||
"summary": "获取备份列表",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/commonrequests.Paginate"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@@ -1170,7 +1181,7 @@
|
||||
}
|
||||
},
|
||||
"/panel/website/uploadBackup": {
|
||||
"post": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"BearerToken": []
|
||||
@@ -1923,7 +1934,7 @@
|
||||
"ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2082,7 +2093,7 @@
|
||||
"ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"raw": {
|
||||
@@ -2327,7 +2338,7 @@
|
||||
"ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"remark": {
|
||||
|
||||
@@ -175,7 +175,7 @@ definitions:
|
||||
type: integer
|
||||
ports:
|
||||
items:
|
||||
type: string
|
||||
type: integer
|
||||
type: array
|
||||
type: object
|
||||
requests.CertStore:
|
||||
@@ -278,7 +278,7 @@ definitions:
|
||||
type: integer
|
||||
ports:
|
||||
items:
|
||||
type: string
|
||||
type: integer
|
||||
type: array
|
||||
raw:
|
||||
type: string
|
||||
@@ -438,7 +438,7 @@ definitions:
|
||||
type: integer
|
||||
ports:
|
||||
items:
|
||||
type: string
|
||||
type: integer
|
||||
type: array
|
||||
remark:
|
||||
type: string
|
||||
@@ -1056,6 +1056,13 @@ paths:
|
||||
/panel/website/backupList:
|
||||
get:
|
||||
description: 获取网站的备份列表
|
||||
parameters:
|
||||
- description: request
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/commonrequests.Paginate'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@@ -1147,7 +1154,7 @@ paths:
|
||||
tags:
|
||||
- 网站管理
|
||||
/panel/website/uploadBackup:
|
||||
post:
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 上传网站的备份
|
||||
|
||||
2
go.mod
2
go.mod
@@ -8,7 +8,7 @@ require (
|
||||
github.com/go-acme/lego/v4 v4.14.2
|
||||
github.com/gookit/color v1.5.4
|
||||
github.com/gookit/validate v1.5.1
|
||||
github.com/goravel/fiber v1.1.11-0.20231117182543-0e63ed108e45
|
||||
github.com/goravel/fiber v1.1.11-0.20231120162926-818d5d2c1b6d
|
||||
github.com/goravel/framework v1.13.1-0.20231117140817-50ecec9871ec
|
||||
github.com/iancoleman/strcase v0.3.0
|
||||
github.com/imroc/req/v3 v3.42.1
|
||||
|
||||
4
go.sum
4
go.sum
@@ -379,8 +379,8 @@ github.com/gookit/goutil v0.6.14 h1:96elyOG4BvVoDaiT7vx1vHPrVyEtFfYlPPBODR0/FGQ=
|
||||
github.com/gookit/goutil v0.6.14/go.mod h1:YyDBddefmjS+mU2PDPgCcjVzTDM5WgExiDv5ZA/b8I8=
|
||||
github.com/gookit/validate v1.5.1 h1:rPp64QZQJM+fysGFAhKpvekQAav4Ok6sjfTs9ZtxcpA=
|
||||
github.com/gookit/validate v1.5.1/go.mod h1:SskOHUQokzMNt6T3r7N+N/4me/6fxDx+tmoXf/3ZQog=
|
||||
github.com/goravel/fiber v1.1.11-0.20231117182543-0e63ed108e45 h1:BLIO7rbTvd1pOw1YfaCoyoL9YmBURK98DnDEOIjosRg=
|
||||
github.com/goravel/fiber v1.1.11-0.20231117182543-0e63ed108e45/go.mod h1:XPw0Fc2s0VEKbPYp+ka8UIrPdbkV9iNQ4eYov8YcuC8=
|
||||
github.com/goravel/fiber v1.1.11-0.20231120162926-818d5d2c1b6d h1:qBZUa4X629DgFQmwQkSO4MrmwXi0/A394xSVI2+rW14=
|
||||
github.com/goravel/fiber v1.1.11-0.20231120162926-818d5d2c1b6d/go.mod h1:sgL5mMyIm9GSDRuepAAf22wte+dVo7F1Y8fWsWj14rs=
|
||||
github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c h1:obhFK91JAhcf7s6h5sggZishm1VyGW/gBCreo+7/SwQ=
|
||||
github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c/go.mod h1:YSWsLXlG16u5CWFaXNZHhEQD10+NwF3xfgDV816OwLE=
|
||||
github.com/goravel/file-rotatelogs/v2 v2.4.1 h1:ogkeIFcTHSBRUBpZYiyJbpul8hkVXxHPuDbOaP78O1M=
|
||||
|
||||
@@ -40,8 +40,8 @@ func Api() {
|
||||
r.Get("defaultConfig", websiteController.GetDefaultConfig)
|
||||
r.Post("defaultConfig", websiteController.SaveDefaultConfig)
|
||||
r.Get("backupList", websiteController.BackupList)
|
||||
r.Post("uploadBackup", websiteController.UploadBackup)
|
||||
r.Post("deleteBackup", websiteController.DeleteBackup)
|
||||
r.Put("uploadBackup", websiteController.UploadBackup)
|
||||
r.Delete("deleteBackup", websiteController.DeleteBackup)
|
||||
})
|
||||
r.Prefix("websites").Middleware(middleware.Jwt(), middleware.MustInstall()).Group(func(r route.Router) {
|
||||
websiteController := controllers.NewWebsiteController()
|
||||
|
||||
Reference in New Issue
Block a user