aboutsummaryrefslogtreecommitdiff
path: root/internal/gallery/id.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/gallery/id.go')
-rw-r--r--internal/gallery/id.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/gallery/id.go b/internal/gallery/id.go
new file mode 100644
index 0000000..edb5be2
--- /dev/null
+++ b/internal/gallery/id.go
@@ -0,0 +1,21 @@
+package gallery
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "path/filepath"
+
+ "github.com/RanXom/galleryd/internal/scanner"
+)
+
+// generateID returns a deterministic identifier for a photo.
+//
+// IDs are generated from the cleaned root and relative path to avoid
+// collisions when multiple roots contain the same directory layout.
+func generateID(file scanner.File) string {
+ canonical := filepath.Join(file.Root, file.RelativePath)
+
+ sum := sha256.Sum256([]byte(canonical))
+
+ return hex.EncodeToString(sum[:])
+}