summaryrefslogtreecommitdiff
path: root/player-server/internal/service
diff options
context:
space:
mode:
Diffstat (limited to 'player-server/internal/service')
-rw-r--r--player-server/internal/service/import.go8
-rw-r--r--player-server/internal/service/write.go9
2 files changed, 11 insertions, 6 deletions
diff --git a/player-server/internal/service/import.go b/player-server/internal/service/import.go
index 90fa4b1..4253439 100644
--- a/player-server/internal/service/import.go
+++ b/player-server/internal/service/import.go
@@ -69,18 +69,20 @@ func probeMedia(ctx context.Context, prober probe.Prober, path string) (*model.M
}
// generateThumbnail creates a thumbnail for video and image media.
+// Thumbnail directory + filename are derived via internal/thumb to share the
+// on-disk convention with the scanner and RegenerateThumbnail.
func generateThumbnail(ctx context.Context, thumbGen thumb.Generator, media *model.Media, duration float64) error {
ext := strings.ToLower(filepath.Ext(media.AbsPath))
if ext == ".svg" {
media.ThumbnailPath = media.AbsPath
return nil
}
- thumbDir := filepath.Join(filepath.Dir(media.AbsPath), ".thumbnails")
+ parent := filepath.Dir(media.AbsPath)
+ thumbDir := thumb.ThumbnailDir(parent)
if err := os.MkdirAll(thumbDir, 0o755); err != nil {
return fmt.Errorf("mkdir thumbnails: %w", err)
}
- thumbName := strings.TrimSuffix(filepath.Base(media.AbsPath), filepath.Ext(media.AbsPath)) + ".jpg"
- thumbnailPath := filepath.Join(thumbDir, thumbName)
+ thumbnailPath := thumb.ThumbnailPathFor(media.AbsPath, parent)
if thumbGen == nil {
media.ThumbnailPath = thumbnailPath
diff --git a/player-server/internal/service/write.go b/player-server/internal/service/write.go
index 23fd130..3fe4d47 100644
--- a/player-server/internal/service/write.go
+++ b/player-server/internal/service/write.go
@@ -112,12 +112,15 @@ func (s *writeService) RegenerateThumbnail(ctx context.Context, mediaID, userID
return fmt.Errorf("probe media: %w", err)
}
- thumbDir := filepath.Join(filepath.Dir(media.AbsPath), ".thumbnails")
+ // Thumbnail destination is derived via internal/thumb so re-generation
+ // targets the exact same path used by scanner + import; otherwise stale
+ // JPEGs would linger alongside the freshly written one.
+ parent := filepath.Dir(media.AbsPath)
+ thumbDir := thumb.ThumbnailDir(parent)
if err := os.MkdirAll(thumbDir, 0o755); err != nil {
return fmt.Errorf("mkdir thumbnails: %w", err)
}
- thumbName := strings.TrimSuffix(filepath.Base(media.AbsPath), filepath.Ext(media.AbsPath)) + ".jpg"
- thumbnailPath := filepath.Join(thumbDir, thumbName)
+ thumbnailPath := thumb.ThumbnailPathFor(media.AbsPath, parent)
if err := s.thumbGen.Generate(ctx, media.AbsPath, thumbnailPath, meta.Duration); err != nil {
return fmt.Errorf("generate thumbnail: %w", err)