🐛 Fix analyzer panic

This commit is contained in:
LittleSheep 2025-01-21 19:11:40 +08:00
parent ac347540b8
commit ed9b1474fb

View File

@ -99,8 +99,8 @@ func ScanUnanalyzedFileFromDatabase() {
}() }()
} }
func calculateAspectRatio(width, height int, orientation int) float64 { func calculateAspectRatio(width, height int, orientation string) float64 {
if orientation == 6 || orientation == 8 { if orientation == "6" || orientation == "8" {
width, height = height, width width, height = height, width
} }
return float64(width) / float64(height) return float64(width) / float64(height)
@ -173,7 +173,7 @@ func AnalyzeAttachment(file models.Attachment) error {
for _, data := range exif { for _, data := range exif {
for k := range data.Fields { for k := range data.Fields {
if k == "Orientation" { if k == "Orientation" {
file.Metadata["ratio"] = calculateAspectRatio(width, height, data.Fields[k].(int)) file.Metadata["ratio"] = calculateAspectRatio(width, height, data.Fields[k].(string))
} }
if strings.HasPrefix(k, "GPS") { if strings.HasPrefix(k, "GPS") {
data.Clear(k) data.Clear(k)
@ -217,7 +217,7 @@ func AnalyzeAttachment(file models.Attachment) error {
for _, data := range exif { for _, data := range exif {
for k := range data.Fields { for k := range data.Fields {
if k == "Orientation" { if k == "Orientation" {
file.Metadata["ratio"] = calculateAspectRatio(stream.Width, stream.Height, data.Fields[k].(int)) file.Metadata["ratio"] = calculateAspectRatio(stream.Width, stream.Height, data.Fields[k].(string))
} }
if strings.HasPrefix(k, "GPS") { if strings.HasPrefix(k, "GPS") {
data.Clear(k) data.Clear(k)