Self reference detection

This commit is contained in:
2024-08-11 01:08:08 +08:00
parent 3e000b6f9e
commit d34e6f068b
4 changed files with 35 additions and 25 deletions

View File

@ -25,6 +25,7 @@ type Attachment struct {
Metadata datatypes.JSONMap `json:"metadata"`
IsMature bool `json:"is_mature"`
IsAnalyzed bool `json:"is_analyzed"`
IsSelfRef bool `json:"is_self_ref"`
Ref *Attachment `json:"ref"`
RefID *uint `json:"ref_id"`

View File

@ -187,7 +187,7 @@ func AnalyzeAttachment(file models.Attachment) error {
start = time.Now()
// Move temporary to permanet
// Move temporary to permanent
if !linked {
if err := ReUploadFileToPermanent(file); err != nil {
return fmt.Errorf("unable to move file to permanet storage: %v", err)

View File

@ -109,6 +109,10 @@ func TryLinkAttachment(tx *gorm.DB, og models.Attachment, hash string) (bool, er
og.Uuid = prev.Uuid
og.Destination = prev.Destination
if og.AccountID == prev.AccountID {
og.IsSelfRef = true
}
if err := tx.Save(&og).Error; err != nil {
tx.Rollback()
return true, err