1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-13 09:26:23 -07:00

Fix bug with videos getting tripped by the image fingerprint matcher

This commit is contained in:
Eggbertx 2024-11-23 11:19:47 -08:00
parent 6f591bade7
commit 7c417e6b7c
2 changed files with 17 additions and 13 deletions

View file

@ -1,6 +1,7 @@
package initsql
import (
"errors"
"net/http"
"path"
"strconv"
@ -150,6 +151,10 @@ func init() {
fingerprint, err := uploads.GetFileFingerprint(path.Join(
config.GetSystemCriticalConfig().DocumentRoot,
dir, "src", u.Filename))
if errors.Is(err, uploads.ErrVideoThumbFingerprint) {
// admin hasn't enabled video thumbnail fingerprinting in the config, let it through
return false, nil
}
return fingerprint == fc.Search, err
})
}

View file

@ -40,23 +40,22 @@ func GetPostImageFingerprint(postID int) (string, error) {
if err != nil {
return "", err
}
subDir := "src"
if !IsImage(filename) && !IsVideo(filename) {
return "", ErrUnsupportedFileExt
} else if IsVideo(filename) {
if !config.GetSiteConfig().FingerprintVideoThumbnails {
return "", ErrVideoThumbFingerprint
}
filename, _ = GetThumbnailFilenames(filename)
subDir = "thumb"
}
filePath := path.Join(config.GetSystemCriticalConfig().DocumentRoot,
board, subDir, filename)
filePath := path.Join(config.GetSystemCriticalConfig().DocumentRoot, board, "src", filename)
return GetFileFingerprint(filePath)
}
func GetFileFingerprint(filePath string) (string, error) {
if !IsImage(filePath) && !IsVideo(filePath) {
return "", ErrUnsupportedFileExt
} else if IsVideo(filePath) {
if !config.GetSiteConfig().FingerprintVideoThumbnails {
return "", ErrVideoThumbFingerprint
}
filePath, _ = GetThumbnailFilenames(filePath)
filename := path.Base(filePath)
fileBoardPath := path.Dir(path.Dir(filePath))
filePath = path.Join(fileBoardPath, "thumb", filename)
}
img, err := imaging.Open(filePath)
if err != nil {
return "", err