From edbe412f970c76310de46fd6dc14f86cb85eb57c Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 28 Dec 2024 20:08:32 +0800 Subject: [PATCH] :sparkles: Casedase deleting attachment --- pkg/internal/services/attachments.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/internal/services/attachments.go b/pkg/internal/services/attachments.go index 3921967..dd35352 100644 --- a/pkg/internal/services/attachments.go +++ b/pkg/internal/services/attachments.go @@ -197,10 +197,15 @@ func UpdateAttachment(item models.Attachment) (models.Attachment, error) { return item, nil } -func DeleteAttachment(item models.Attachment) error { +func DeleteAttachment(item models.Attachment, txs ...*gorm.DB) error { dat := item - tx := database.C.Begin() + var tx *gorm.DB + if len(txs) == 0 { + tx = database.C.Begin() + } else { + tx = txs[0] + } if item.RefID != nil { var refTarget models.Attachment @@ -212,6 +217,16 @@ func DeleteAttachment(item models.Attachment) error { } } } + if item.Thumbnail != nil { + if err := DeleteAttachment(*item.Thumbnail, tx); err != nil { + return err + } + } + if item.Compressed != nil { + if err := DeleteAttachment(*item.Compressed, tx); err != nil { + return err + } + } if err := database.C.Delete(&item).Error; err != nil { tx.Rollback() return err