Skip to content

Commit 4f27cef

Browse files
committed
fix: 网站上传备份逻辑调整
1 parent 1ccc561 commit 4f27cef

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

backend/app/service/backup_website.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/1Panel-dev/1Panel/backend/app/dto"
1313
"github.com/1Panel-dev/1Panel/backend/app/model"
14+
"github.com/1Panel-dev/1Panel/backend/buserr"
1415
"github.com/1Panel-dev/1Panel/backend/constant"
1516
"github.com/1Panel-dev/1Panel/backend/global"
1617
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
@@ -80,11 +81,11 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
8081

8182
temPathWithName := tmpPath + "/" + website.Alias
8283
if !fileOp.Stat(tmpPath+"/website.json") || !fileOp.Stat(temPathWithName+".conf") || !fileOp.Stat(temPathWithName+".web.tar.gz") {
83-
return errors.New("the wrong recovery package does not have .conf or .web.tar.gz files")
84+
return buserr.WithDetail(constant.ErrBackupExist, ".conf or .web.tar.gz", nil)
8485
}
8586
if website.Type == constant.Deployment {
8687
if !fileOp.Stat(temPathWithName + ".app.tar.gz") {
87-
return errors.New("the wrong recovery package does not have .app.tar.gz files")
88+
return buserr.WithDetail(constant.ErrBackupExist, ".app.tar.gz", nil)
8889
}
8990
}
9091
var oldWebsite model.Website
@@ -95,8 +96,9 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
9596
if err := json.Unmarshal(websiteJson, &oldWebsite); err != nil {
9697
return fmt.Errorf("unmarshal app.json failed, err: %v", err)
9798
}
98-
if oldWebsite.Alias != website.Alias || oldWebsite.Type != website.Type || oldWebsite.ID != website.ID {
99-
return errors.New("the current backup file does not match the application")
99+
100+
if err := checkValidOfWebsite(&oldWebsite, website); err != nil {
101+
return err
100102
}
101103

102104
isOk := false
@@ -155,6 +157,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
155157
return errors.New(string(stdout))
156158
}
157159

160+
oldWebsite.ID = website.ID
158161
if err := websiteRepo.SaveWithoutCtx(&oldWebsite); err != nil {
159162
global.LOG.Errorf("handle save website data failed, err: %v", err)
160163
return err
@@ -212,3 +215,29 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName string) err
212215

213216
return nil
214217
}
218+
219+
func checkValidOfWebsite(oldWebsite, website *model.Website) error {
220+
if oldWebsite.Alias != website.Alias || oldWebsite.Type != website.Type {
221+
return buserr.WithDetail(constant.ErrBackupMatch, fmt.Sprintf("oldName: %s, oldType: %v", oldWebsite.Alias, oldWebsite.Type), nil)
222+
}
223+
if oldWebsite.AppInstallID != 0 {
224+
app, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
225+
if err != nil {
226+
return buserr.WithDetail(constant.ErrBackupMatch, "app", nil)
227+
}
228+
if app.App.Type != "website" {
229+
return buserr.WithDetail(constant.ErrBackupMatch, fmt.Sprintf("appType: %s", app.App.Type), nil)
230+
}
231+
}
232+
if oldWebsite.RuntimeID != 0 {
233+
if _, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)); err != nil {
234+
return buserr.WithDetail(constant.ErrBackupMatch, "runtime", nil)
235+
}
236+
}
237+
if oldWebsite.WebsiteSSLID != 0 {
238+
if _, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(website.WebsiteSSLID)); err != nil {
239+
return buserr.WithDetail(constant.ErrBackupMatch, "ssl", nil)
240+
}
241+
}
242+
return nil
243+
}

backend/constant/errs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ var (
6868
ErrGroupIsUsed = "ErrGroupIsUsed"
6969
ErrUsernameIsExist = "ErrUsernameIsExist"
7070
ErrUsernameIsNotExist = "ErrUsernameIsNotExist"
71+
ErrBackupMatch = "ErrBackupMatch"
72+
ErrBackupExist = "ErrBackupExist"
7173
)
7274

7375
// ssl

backend/i18n/lang/en.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ ErrDomainIsExist: "Domain is already exist"
5959
ErrAliasIsExist: "Alias is already exist"
6060
ErrAppDelete: 'Other Website use this App'
6161
ErrGroupIsUsed: 'The group is in use and cannot be deleted'
62+
ErrBackupMatch: 'the backup file does not match the current partial data of the website: {{ .detail}}"'
63+
ErrBackupExist: 'the backup file corresponds to a portion of the original data that does not exist: {{ .detail}}"'
6264

6365
#ssl
6466
ErrSSLCannotDelete: "The certificate is being used by the website and cannot be removed"

backend/i18n/lang/zh-Hant.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ ErrDomainIsExist: "域名已存在"
5959
ErrAliasIsExist: "代號已存在"
6060
ErrAppDelete: '其他網站使用此應用,無法刪除'
6161
ErrGroupIsUsed: '分組正在使用中,無法刪除'
62+
ErrBackupMatch: '該備份文件與當前網站部分數據不匹配: {{ .detail}}"'
63+
ErrBackupExist: '該備份文件對應部分原數據不存在: {{ .detail}}"'
6264

6365
#ssl
6466
ErrSSLCannotDelete: "證書正在被網站使用,無法刪除"

backend/i18n/lang/zh.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ ErrDomainIsExist: "域名已存在"
5959
ErrAliasIsExist: "代号已存在"
6060
ErrAppDelete: '其他网站使用此应用,无法删除'
6161
ErrGroupIsUsed: '分组正在使用中,无法删除'
62+
ErrBackupMatch: '该备份文件与当前网站部分数据不匹配 {{ .detail}}"'
63+
ErrBackupExist: '该备份文件对应部分源数据不存在 {{ .detail}}"'
6264

6365
#ssl
6466
ErrSSLCannotDelete: "证书正在被网站使用,无法删除"

0 commit comments

Comments
 (0)