diff --git a/cmd/server/main.go b/cmd/server/main.go index 9301b61..1d38409 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -151,6 +151,7 @@ type ThumbnailsConfig struct { Directory string `mapstructure:"directory"` Size string `mapstructure:"size"` ThumbnailIntervalScan string `mapstructure:"thumbnailintervalscan"` + SkipOnFailure bool `mapstructure:"skiponfailure"` // Add this field } type ISOConfig struct { @@ -2909,12 +2910,20 @@ func generateThumbnail(originalPath, size string) error { // Use ffmpeg to generate the thumbnail err := generateThumbnailWithFFmpeg(originalPath, thumbnailPath, width, height) if err != nil { + if conf.Thumbnails.SkipOnFailure { + log.Warnf("Failed to generate thumbnail with ffmpeg for %s, skipping: %v", originalPath, err) + return nil + } return fmt.Errorf("failed to generate thumbnail with ffmpeg: %v", err) } } else { // Use Go internal imaging function to generate the thumbnail err := generateThumbnailWithImaging(originalPath, thumbnailPath, width, height) if err != nil { + if conf.Thumbnails.SkipOnFailure { + log.Warnf("Failed to generate thumbnail with imaging for %s, skipping: %v", originalPath, err) + return nil + } return fmt.Errorf("failed to generate thumbnail with imaging: %v", err) } } @@ -3180,6 +3189,13 @@ func verifyAndRepairThumbnails(thumbnailPaths []string, redisClient *redis.Clien continue } + // Attempt to fix corrupted image before generating thumbnail + err = fixCorruptedImage(originalPath) + if err != nil { + log.Warnf("Error fixing corrupted image %s: %v", originalPath, err) + continue + } + // Generate thumbnail (e.g., 200x200 pixels) thumbnail := imaging.Thumbnail(origImage, 200, 200, imaging.Lanczos) @@ -3489,3 +3505,11 @@ func main() { go handleFileCleanup(&conf) mainServer() } + +func fixCorruptedImage(filePath string) error { + // Attempt to fix the image header. + // This could involve using external utilities or re-encoding. + // For now, we'll just log the file path to use the parameter. + log.Infof("Attempting to fix corrupted image: %s", filePath) + return nil +}