diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-13 12:24:29 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-13 12:24:29 +0530 |
| commit | 1694a7b3d4db4dc5f089ca272a3f207c7c458a63 (patch) | |
| tree | 2e7ddee1431637873a507800f15881efd2bc262b | |
| parent | 0d44904c3e54bb3fe393e88c12a152a799b9773b (diff) | |
| download | galleryd-1694a7b3d4db4dc5f089ca272a3f207c7c458a63.tar.xz galleryd-1694a7b3d4db4dc5f089ca272a3f207c7c458a63.zip | |
feat(gallery): generate stable photo identifiers
| -rw-r--r-- | internal/gallery/builder.go | 23 | ||||
| -rw-r--r-- | internal/gallery/id.go | 11 |
2 files changed, 33 insertions, 1 deletions
diff --git a/internal/gallery/builder.go b/internal/gallery/builder.go index ebbe87e..1964b19 100644 --- a/internal/gallery/builder.go +++ b/internal/gallery/builder.go @@ -22,5 +22,26 @@ func (b *Builder) Build( ctx context.Context, files []scanner.File, ) ([]Photo, error) { - return nil, nil + photos := make([]Photo, 0, len(files)) + + for _, file := range files { + select { + case <-ctx.Done(): + return nil, ctx.Err() + default: + } + + md, err := b.reader.Read(ctx, file) + if err != nil { + return nil, err + } + + photos = append(photos, Photo{ + ID: generateID(file.RelativePath), + File: file, + Metadata: md, + }) + } + + return photos, nil } diff --git a/internal/gallery/id.go b/internal/gallery/id.go new file mode 100644 index 0000000..b23ebf5 --- /dev/null +++ b/internal/gallery/id.go @@ -0,0 +1,11 @@ +package gallery + +import ( + "crypto/sha256" + "encoding/hex" +) + +func generateID(relativePath string) string { + sum := sha256.Sum256([]byte(relativePath)) + return hex.EncodeToString(sum[:]) +} |