feat(photos): add square medium variant for sharp grid thumbnails
This commit is contained in:
@@ -382,6 +382,23 @@ func testPhotos(t *testing.T, ctx context.Context, r Repos) {
|
||||
t.Fatalf("cover not set: %+v", al.CoverPhotoID)
|
||||
}
|
||||
|
||||
// The album exposes the cover's medium variant so the overview can render
|
||||
// it sharply.
|
||||
coverMedium := &photos.Object{ID: newID(), StorageKey: "objects/" + newID(), MimeType: "image/webp", State: photos.ObjectReady}
|
||||
if err := r.Photos.CreateObject(ctx, coverMedium); err != nil {
|
||||
t.Fatalf("create cover medium: %v", err)
|
||||
}
|
||||
if err := r.Photos.ActivateObject(ctx, coverMedium.ID); err != nil {
|
||||
t.Fatalf("activate cover medium: %v", err)
|
||||
}
|
||||
if err := r.Photos.BindObject(ctx, p.ID, coverMedium.ID, photos.RoleMedium); err != nil {
|
||||
t.Fatalf("bind cover medium: %v", err)
|
||||
}
|
||||
al, _ = r.Albums.GetByID(ctx, a.ID)
|
||||
if al.CoverMediumKey != coverMedium.StorageKey {
|
||||
t.Fatalf("cover medium key = %q want %q", al.CoverMediumKey, coverMedium.StorageKey)
|
||||
}
|
||||
|
||||
// Clearing the cover only affects a matching photo id.
|
||||
r.Photos.ClearCoverIfMatches(ctx, a.ID, newID())
|
||||
al, _ = r.Albums.GetByID(ctx, a.ID)
|
||||
@@ -468,6 +485,19 @@ func testObjects(t *testing.T, ctx context.Context, r Repos) {
|
||||
t.Fatalf("thumb refs = %d, want 1", refs)
|
||||
}
|
||||
|
||||
// The medium role is a first-class binding, so it must be accepted by the
|
||||
// role constraint on every backend.
|
||||
medium := &photos.Object{ID: newID(), StorageKey: "objects/" + newID(), MimeType: "image/webp", State: photos.ObjectPending}
|
||||
if err := r.Photos.CreateObject(ctx, medium); err != nil {
|
||||
t.Fatalf("create medium object: %v", err)
|
||||
}
|
||||
if err := r.Photos.ActivateObject(ctx, medium.ID); err != nil {
|
||||
t.Fatalf("activate medium: %v", err)
|
||||
}
|
||||
if err := r.Photos.BindObject(ctx, p.ID, medium.ID, photos.RoleMedium); err != nil {
|
||||
t.Fatalf("bind medium: %v", err)
|
||||
}
|
||||
|
||||
// After the photo is gone, its objects have no bindings and are collectible.
|
||||
if err := r.Photos.HardDelete(ctx, p.ID); err != nil {
|
||||
t.Fatalf("hard delete: %v", err)
|
||||
@@ -480,8 +510,8 @@ func testObjects(t *testing.T, ctx context.Context, r Repos) {
|
||||
for _, o := range claimed {
|
||||
got[o.ID] = true
|
||||
}
|
||||
if !got[orig.ID] || !got[thumb.ID] {
|
||||
t.Fatalf("claimed = %+v, want original and thumb", got)
|
||||
if !got[orig.ID] || !got[thumb.ID] || !got[medium.ID] {
|
||||
t.Fatalf("claimed = %+v, want original, thumb and medium", got)
|
||||
}
|
||||
for _, o := range claimed {
|
||||
if err := r.Photos.DeleteObjectRow(ctx, o.ID); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user