Compare commits
2 Commits
411b2f3313
...
66ee6c37f2
Author | SHA1 | Date | |
---|---|---|---|
66ee6c37f2 | |||
ae6815b2a4 |
@ -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 {
|
||||
@ -111,12 +94,7 @@ func DeleteFile(meta models.Attachment) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var destMap map[string]any
|
||||
if meta.Destination == models.AttachmentDstTemporary {
|
||||
destMap = viper.GetStringMap("destinations.0")
|
||||
} else {
|
||||
destMap = viper.GetStringMap("destinations.permanent")
|
||||
}
|
||||
destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", meta.Destination))
|
||||
|
||||
var dest models.BaseDestination
|
||||
rawDest, _ := jsoniter.Marshal(destMap)
|
||||
|
Loading…
Reference in New Issue
Block a user