🐛 Trying fix deleting attachment issue
This commit is contained in:
		| @@ -1,9 +1,10 @@ | ||||
| package models | ||||
|  | ||||
| import ( | ||||
| 	"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda" | ||||
| 	"time" | ||||
|  | ||||
| 	"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda" | ||||
|  | ||||
| 	"gorm.io/datatypes" | ||||
| ) | ||||
|  | ||||
|   | ||||
| @@ -5,8 +5,6 @@ import ( | ||||
| 	"crypto/sha256" | ||||
| 	"encoding/hex" | ||||
| 	"fmt" | ||||
| 	"github.com/barasher/go-exiftool" | ||||
| 	"github.com/samber/lo" | ||||
| 	"image" | ||||
| 	"io" | ||||
| 	"os" | ||||
| @@ -15,6 +13,9 @@ import ( | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/barasher/go-exiftool" | ||||
| 	"github.com/samber/lo" | ||||
|  | ||||
| 	"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" | ||||
| 	"git.solsynth.dev/hypernet/paperclip/pkg/internal/models" | ||||
| 	jsoniter "github.com/json-iterator/go" | ||||
| @@ -164,7 +165,7 @@ func AnalyzeAttachment(file models.Attachment) error { | ||||
| 				defer et.Close() | ||||
| 				exif := et.ExtractMetadata(dst) | ||||
| 				for _, data := range exif { | ||||
| 					for k, _ := range data.Fields { | ||||
| 					for k := range data.Fields { | ||||
| 						if strings.HasPrefix(k, "GPS") { | ||||
| 							data.Clear(k) | ||||
| 						} else if lo.Contains(exifWhitelist, k) { | ||||
| @@ -205,7 +206,7 @@ func AnalyzeAttachment(file models.Attachment) error { | ||||
| 				defer et.Close() | ||||
| 				exif := et.ExtractMetadata(dst) | ||||
| 				for _, data := range exif { | ||||
| 					for k, _ := range data.Fields { | ||||
| 					for k := range data.Fields { | ||||
| 						if strings.HasPrefix(k, "GPS") { | ||||
| 							data.Clear(k) | ||||
| 						} else if lo.Contains(exifWhitelist, k) { | ||||
| @@ -248,7 +249,7 @@ func AnalyzeAttachment(file models.Attachment) error { | ||||
|  | ||||
| 	// Recycle the temporary file | ||||
| 	file.Destination = models.AttachmentDstTemporary | ||||
| 	PublishDeleteFileTask(file) | ||||
| 	go DeleteFile(file) | ||||
|  | ||||
| 	// Finish | ||||
| 	log.Info().Dur("elapsed", time.Since(start)).Uint("id", file.ID).Bool("linked", linked).Msg("A file post-analyze upload task was finished.") | ||||
|   | ||||
| @@ -3,7 +3,6 @@ package services | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"git.solsynth.dev/hypernet/nexus/pkg/nex/sec" | ||||
| 	"math" | ||||
| 	"mime" | ||||
| 	"mime/multipart" | ||||
| @@ -11,6 +10,8 @@ import ( | ||||
| 	"path/filepath" | ||||
| 	"time" | ||||
|  | ||||
| 	"git.solsynth.dev/hypernet/nexus/pkg/nex/sec" | ||||
|  | ||||
| 	"github.com/eko/gocache/lib/v4/cache" | ||||
| 	"github.com/eko/gocache/lib/v4/marshaler" | ||||
| 	"github.com/eko/gocache/lib/v4/store" | ||||
| @@ -251,7 +252,7 @@ func DeleteAttachment(item models.Attachment) error { | ||||
| 	tx.Commit() | ||||
|  | ||||
| 	if dat.RefCount == 0 { | ||||
| 		PublishDeleteFileTask(dat) | ||||
| 		go DeleteFile(dat) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
|   | ||||
| @@ -3,12 +3,13 @@ package services | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" | ||||
| 	"github.com/samber/lo" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"time" | ||||
|  | ||||
| 	"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" | ||||
| 	"github.com/samber/lo" | ||||
|  | ||||
| 	"git.solsynth.dev/hypernet/paperclip/pkg/internal/models" | ||||
| 	jsoniter "github.com/json-iterator/go" | ||||
| 	"github.com/minio/minio-go/v7" | ||||
| @@ -17,24 +18,6 @@ import ( | ||||
| 	"github.com/spf13/viper" | ||||
| ) | ||||
|  | ||||
| var fileDeletionQueue = make(chan models.Attachment, 256) | ||||
|  | ||||
| func PublishDeleteFileTask(file models.Attachment) { | ||||
| 	fileDeletionQueue <- file | ||||
| } | ||||
|  | ||||
| func StartConsumeDeletionTask() { | ||||
| 	for { | ||||
| 		task := <-fileDeletionQueue | ||||
| 		start := time.Now() | ||||
| 		if err := DeleteFile(task); err != nil { | ||||
| 			log.Error().Err(err).Any("task", task).Msg("A file deletion task failed...") | ||||
| 		} else { | ||||
| 			log.Info().Dur("elapsed", time.Since(start)).Uint("id", task.ID).Msg("A file deletion task was completed.") | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func RunMarkLifecycleDeletionTask() { | ||||
| 	var pools []models.AttachmentPool | ||||
| 	if err := database.C.Find(&pools).Error; err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user