Skip to content

Commit

Permalink
fix: enhance thumbnail generation by adding image repair logic and de…
Browse files Browse the repository at this point in the history
…duplication path check
  • Loading branch information
PlusOne committed Dec 31, 2024
1 parent b2f8686 commit 5870f20
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2870,10 +2870,6 @@ func generateThumbnail(originalPath, size string) error {

log.Debugf("Generating thumbnail for: %s with size: %s", originalPath, size)

if !conf.Thumbnails.Enabled {
return nil
}

// Check if the file is an image
if !isImageFile(originalPath) {
log.Infof("File %s is not an image. Skipping thumbnail generation.", originalPath)
Expand Down Expand Up @@ -2905,6 +2901,12 @@ func generateThumbnail(originalPath, size string) error {
return fmt.Errorf("error checking thumbnail existence: %v", err)
}

// Check if the original image is in the dedup directory
originalDedupPath := filepath.Join(conf.Deduplication.Directory, filepath.Base(originalPath))
if _, err := os.Stat(originalDedupPath); err == nil {
originalPath = originalDedupPath
}

// Check if ffmpeg is installed
if isFFmpegInstalled() {
// Use ffmpeg to generate the thumbnail
Expand All @@ -2920,11 +2922,25 @@ func generateThumbnail(originalPath, size string) error {
// 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
// Attempt to repair the image if it appears corrupt
err = fixCorruptedImage(originalPath)
if err != nil {
log.Warnf("Failed to repair image %s: %v", originalPath, err)
if conf.Thumbnails.SkipOnFailure {
return nil
}
return fmt.Errorf("failed to repair image: %v", err)
}

// Retry generating the thumbnail after repair
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)
}
return fmt.Errorf("failed to generate thumbnail with imaging: %v", err)
}
}

Expand Down

0 comments on commit 5870f20

Please sign in to comment.