@@ -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+ }
0 commit comments