diff --git a/core/artwork/artwork.go b/core/artwork/artwork.go index 6cf466c64..218c4d665 100644 --- a/core/artwork/artwork.go +++ b/core/artwork/artwork.go @@ -51,9 +51,9 @@ func NewArtwork(ds model.DataStore, cache cache.FileCache, store *ImageStore, ff return &service{ds: ds, cache: cache, store: store, ffmpeg: ffm} } -// EntityExists reports whether the entity an artwork id points at is still there: state rows +// entityExists reports whether the entity an artwork id points at is still there: state rows // outlive a deleted entity until the next prune, so a servable row is not evidence of its owner. -func EntityExists(ctx context.Context, ds model.DataStore, artID model.ArtworkID) bool { +func entityExists(ctx context.Context, ds model.DataStore, artID model.ArtworkID) bool { var found bool var err error switch artID.Kind { @@ -172,7 +172,7 @@ func (s *service) serveSource(ctx context.Context, key, hash string, lastUpdate // cancelled request is not: it must not enqueue a re-resolution. func (s *service) serveHash(ctx context.Context, artID model.ArtworkID, ia *model.ItemArtwork, size int, square bool) (*Image, error) { // Only this path can hand back a deleted entity's bytes; the others load their entity anyway. - if !EntityExists(ctx, s.ds, artID) { + if !entityExists(ctx, s.ds, artID) { return nil, ErrUnavailable } art, err := s.ds.Artwork(ctx).GetImage(ia.Hash) @@ -366,13 +366,6 @@ func placeholderImage(kind model.Kind) *Image { return &Image{ReadCloser: r, Placeholder: true} } -// PlaceholderFor returns the kind-appropriate placeholder for an artwork id, for callers that -// must not consult persisted state (e.g. an access-control denial). -func PlaceholderFor(id string) *Image { - artID, _ := model.ParseArtworkID(id) - return placeholderImage(artID.Kind) -} - type coverArtIDGetter interface { CoverArtID() model.ArtworkID } diff --git a/core/artwork/artwork_test.go b/core/artwork/artwork_test.go index 59429d8b4..c58a0fe4e 100644 --- a/core/artwork/artwork_test.go +++ b/core/artwork/artwork_test.go @@ -507,7 +507,7 @@ var _ = Describe("EntityExists", func() { DescribeTable("reports whether the owning entity is still there", func(id string, expected bool) { - Expect(EntityExists(ctx, ds, model.MustParseArtworkID(id))).To(Equal(expected)) + Expect(entityExists(ctx, ds, model.MustParseArtworkID(id))).To(Equal(expected)) }, Entry("existing album", "al-al1", true), Entry("deleted album", "al-gone", false), diff --git a/core/artwork/blurhash/blurhash.go b/core/artwork/blurhash/blurhash.go index 5dfd8754f..405d7e714 100644 --- a/core/artwork/blurhash/blurhash.go +++ b/core/artwork/blurhash/blurhash.go @@ -81,7 +81,7 @@ func Encode(img image.Image) (string, error) { } var sb strings.Builder - sb.WriteString(Encode83((xComp-1)+(yComp-1)*9, 1)) + sb.WriteString(encode83((xComp-1)+(yComp-1)*9, 1)) // Derived counts are at least 1x9, so there is always at least one AC factor. ac := factors[1:] @@ -91,12 +91,12 @@ func Encode(img image.Image) (string, error) { } quantMax := int(max(0, min(82, math.Floor(actualMax*166-0.5)))) maxVal := float64(quantMax+1) / 166 - sb.WriteString(Encode83(quantMax, 1)) + sb.WriteString(encode83(quantMax, 1)) dc := factors[0] - sb.WriteString(Encode83(linearToSRGB(dc[0])<<16|linearToSRGB(dc[1])<<8|linearToSRGB(dc[2]), 4)) + sb.WriteString(encode83(linearToSRGB(dc[0])<<16|linearToSRGB(dc[1])<<8|linearToSRGB(dc[2]), 4)) for _, f := range ac { - sb.WriteString(Encode83(quantAC(f[0], maxVal)*19*19+quantAC(f[1], maxVal)*19+quantAC(f[2], maxVal), 2)) + sb.WriteString(encode83(quantAC(f[0], maxVal)*19*19+quantAC(f[1], maxVal)*19+quantAC(f[2], maxVal), 2)) } return sb.String(), nil } @@ -156,8 +156,8 @@ func linearToSRGB(v float64) int { return int((1.055*math.Pow(v, 1/2.4)-0.055)*255 + 0.5) } -// Encode83 encodes value as a fixed-width, big-endian base83 string of the given length. -func Encode83(value, length int) string { +// encode83 encodes value as a fixed-width, big-endian base83 string of the given length. +func encode83(value, length int) string { b := make([]byte, length) for i := length - 1; i >= 0; i-- { b[i] = alphabet[value%83]