aboutsummaryrefslogtreecommitdiff
path: root/internal/thumbnail/cache.go
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-07-13 14:44:12 +0530
committerGitHub <noreply@github.com>2026-07-13 14:44:12 +0530
commitcc639337ed5ccb4634b2a338f764cf9c73b02e4f (patch)
treeeae608923098a07f1413988cf0c79fc8ce4211be /internal/thumbnail/cache.go
parented70370d9f58d39c3b31f5506e449aeb5d562a77 (diff)
parentc2e38ad8c3cff2d3c6ea627855b2b4f02dc3e9ba (diff)
downloadgalleryd-cc639337ed5ccb4634b2a338f764cf9c73b02e4f.tar.xz
galleryd-cc639337ed5ccb4634b2a338f764cf9c73b02e4f.zip
Merge pull request #5 from RanXom/feat/thumbnail
Feat/thumbnail: implement thumbnail generation and caching
Diffstat (limited to 'internal/thumbnail/cache.go')
-rw-r--r--internal/thumbnail/cache.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/thumbnail/cache.go b/internal/thumbnail/cache.go
new file mode 100644
index 0000000..740268a
--- /dev/null
+++ b/internal/thumbnail/cache.go
@@ -0,0 +1,35 @@
+package thumbnail
+
+import (
+ "fmt"
+ "path/filepath"
+
+ "github.com/RanXom/galleryd/internal/gallery"
+)
+
+const (
+ thumbnailCacheVersion = 1
+ thumbnailExtension = ".webp"
+)
+
+func cacheVersion() string {
+ return fmt.Sprintf("v%d", thumbnailCacheVersion)
+}
+
+// cachePath returns the on-disk cache location for a photo thumbnail.
+//
+// Thumbnails are sharded by the first two characters of the photo ID to
+// avoid placing large numbers of files in a single directory.
+func (g *Generator) cachePath(photo gallery.Photo) string {
+ shard := photo.ID[:2]
+
+ filename := photo.ID + thumbnailExtension
+
+ return filepath.Join(
+ g.cacheDir,
+ "thumbs",
+ cacheVersion(),
+ shard,
+ filename,
+ )
+}