aboutsummaryrefslogtreecommitdiff
path: root/internal/gallery/id.go
blob: edb5be2b956d60a71e72f912d101587eb1c454bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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[:])
}