mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
refactor(artwork): unexport what nothing outside the package calls
PlaceholderFor had no callers at all. Its comment offered it to callers that must not consult persisted state, but no such caller was ever written, so it is removed rather than unexported. entityExists and encode83 are only reached from inside their own packages; their tests are package-internal (artwork) or never touch them (blurhash_test). ImageStore stays exported: server/subsonic/e2e constructs one to wire up the worker, and that suite cannot move into package artwork. Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
d25b11dd53
commit
3ce92cc055
@ -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
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user