Skip to content

Commit

Permalink
fix: add skipOnFailure option for thumbnail generation and implement …
Browse files Browse the repository at this point in the history
…image repair logic
  • Loading branch information
PlusOne committed Dec 31, 2024
1 parent b1130fb commit b2f8686
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
}

0 comments on commit b2f8686

Please sign in to comment.