Referenced external attachment

This commit is contained in:
2025-04-05 11:51:35 +08:00
parent 048535d1c0
commit 1de0a86074
18 changed files with 90 additions and 15 deletions

View File

@@ -158,6 +158,25 @@ func NewAttachmentMetadata(tx *gorm.DB, user *sec.UserInfo, file *multipart.File
return attachment, nil
}
func NewRefURLAttachment(tx *gorm.DB, user *sec.UserInfo, attachment models.Attachment) (models.Attachment, error) {
if attachment.RefURL == nil {
return attachment, fmt.Errorf("attachment doesn't have a ref url")
}
attachment.Uuid = uuid.NewString()
attachment.Rid = RandString(16)
attachment.Size = 0
attachment.Destination = models.AttachmentDstExternal
attachment.Type = models.AttachmentTypeNormal
attachment.AccountID = user.ID
if err := tx.Save(&attachment).Error; err != nil {
return attachment, fmt.Errorf("failed to save attachment record: %v", err)
}
return attachment, nil
}
func TryLinkAttachment(tx *gorm.DB, og models.Attachment, hash string) (bool, error) {
prev, err := GetAttachmentByHash(hash)
if err != nil {