fix: 网站,创建备份后,点击网站名称进入二级页面,此时查看源文和默认文档等页面,都报错

pull/79/head
zhengkunwang223 2022-12-20 22:00:05 +08:00 committed by zhengkunwang223
parent 53ac95b005
commit a36bb94299
3 changed files with 27 additions and 5 deletions

View File

@ -41,7 +41,7 @@ func (u *BackupRepo) ListRecord(opts ...DBOption) ([]model.BackupRecord, error)
for _, opt := range opts {
db = opt(db)
}
err := db.Find(&users).Error
err := db.Debug().Find(&users).Error
return users, err
}
@ -57,7 +57,7 @@ func (u *BackupRepo) PageRecord(page, size int, opts ...DBOption) (int64, []mode
return count, users, err
}
func (c *BackupRepo) WithByDetailName(detailName string) DBOption {
func (u *BackupRepo) WithByDetailName(detailName string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(detailName) == 0 {
return g
@ -66,7 +66,7 @@ func (c *BackupRepo) WithByDetailName(detailName string) DBOption {
}
}
func (c *BackupRepo) WithByFileName(fileName string) DBOption {
func (u *BackupRepo) WithByFileName(fileName string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(fileName) == 0 {
return g
@ -75,6 +75,15 @@ func (c *BackupRepo) WithByFileName(fileName string) DBOption {
}
}
func (u *BackupRepo) WithByType(backupType string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(backupType) == 0 {
return g
}
return g.Where("type = ?", backupType)
}
}
func (u *BackupRepo) List(opts ...DBOption) ([]model.BackupAccount, error) {
var ops []model.BackupAccount
db := global.DB.Model(&model.BackupAccount{})

View File

@ -268,7 +268,19 @@ func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error {
}
}
}
//TODO 删除备份
if req.DeleteBackup {
backups, _ := backupRepo.ListRecord(backupRepo.WithByType("website-"+website.Type), commonRepo.WithByName(website.PrimaryDomain))
if len(backups) > 0 {
fileOp := files.NewFileOp()
for _, b := range backups {
_ = fileOp.DeleteDir(b.FileDir)
}
}
if err := backupRepo.DeleteRecord(backupRepo.WithByType("website-"+website.Type), commonRepo.WithByName(website.PrimaryDomain)); err != nil {
return err
}
}
if err := websiteRepo.DeleteBy(ctx, commonRepo.WithByID(req.ID)); err != nil {
tx.Rollback()
return err

View File

@ -402,7 +402,8 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
return err
}
nginxConfFile := fmt.Sprintf("%s/nginx/%s/conf/conf.d/%s.conf", constant.AppInstallDir, nginxInfo.Name, website.PrimaryDomain)
if err := copyConf(nginxConfFile, fmt.Sprintf("%s/%s.conf", tmpDir, website.PrimaryDomain)); err != nil {
fileOp := files.NewFileOp()
if err := fileOp.CopyFile(nginxConfFile, tmpDir); err != nil {
return err
}