🔒 Fix Attachment will contains GPS information

This commit is contained in:
2024-10-15 22:29:55 +08:00
parent fdadebbeab
commit 6d57ce84e6
6 changed files with 46 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/barasher/go-exiftool"
"image"
"io"
"os"
@ -147,6 +148,22 @@ func AnalyzeAttachment(file models.Attachment) error {
"height": height,
"ratio": ratio,
}
// Removing location EXIF data
et, err := exiftool.NewExiftool()
if err != nil {
return fmt.Errorf("error when intializing exiftool: %v", err)
}
defer et.Close()
exif := et.ExtractMetadata(dst)
for _, data := range exif {
for k, _ := range data.Fields {
if strings.HasPrefix(k, "GPS") {
data.Clear(k)
}
}
}
et.WriteMetadata(exif)
case "video":
// Dealing with video
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
@ -170,6 +187,22 @@ func AnalyzeAttachment(file models.Attachment) error {
"color_range": stream.ColorRange,
"color_space": stream.ColorSpace,
}
// Removing location EXIF data
et, err := exiftool.NewExiftool()
if err != nil {
return fmt.Errorf("error when intializing exiftool: %v", err)
}
defer et.Close()
exif := et.ExtractMetadata(dst)
for _, data := range exif {
for k, _ := range data.Fields {
if strings.HasPrefix(k, "GPS") {
data.Clear(k)
}
}
}
et.WriteMetadata(exif)
}
}