feat(source): each source interprets its own raw artwork token

Design 02 §9 stage 4 needs the art index to carry an ArtRef instead of a
String, and the producers of that index are the row mappers, which hold
no MediaRef — the windowed grid pipeline is keyed by art_key (§3.4). The
two ways to give them one were both bad: sniff the string later (that is
`artwork_qt::classify`, i.e. bug 3), or claim per visible row and let
the source look the token up again, which for Plex is one plex_cache.db
query per row on a cold grid — on the exact grid whose scroll cost is
the open perf item.

`Source::artwork_token` is the artwork analogue of `claim`: the source
says what its OWN token means, at the moment provenance is still known.
It is pure — no network, no DB, no filesystem — because the token is the
whole input.

This is what makes stage 5 free. `classify` recognises a Plex thumb only
because somebody bolted `local_plex::is_thumb_path` onto it, so a
Jellyfin token (`/Items/<id>/Images/Primary`) reads as a filesystem path
— it starts with `/` — and the pipeline opens it from disk: blank cover,
no error, nowhere to look. Dispatching by owner removes the guess.

Three impls, each carrying the arm of `classify` that was really about
it: Local (file:// and absolute paths, plus the CDN url an offline row
can keep), Plex (the two declared thumb prefixes, Unavailable rather
than None when there are no credentials), Qobuz (CDN url, cache_key on
the RAW url so downscaling does not re-download per size class).

An unregistered source returns None, not Unavailable: a row whose source
word this build does not know has no art to wait for, and Unavailable
would park it in the retry-when-connected bucket forever.

59/59.

cc
This commit is contained in:
vicrodh committed 2026-08-20 01:35:47 -06:00
1 parent 22033672a1
commit ffb35085c9
5 files changed
+173

No files matched your search

+59
View File
@@ -647,6 +647,38 @@ impl Source for LocalSource {
}
}
fn artwork_token(&self, token: &str, _size: ArtSize) -> ArtRef {
// The `LocalFile` half of `artwork_qt::classify` (artwork_qt.rs:155-183),
// minus the guessing: this only ever sees a token a LOCAL row carried,
// so an absolute path is a file rather than "a shape that might be a
// Plex thumb". No `stat` — this must stay pure; the CHEAP-phase
// thumbnail lookup happens in the pipeline, exactly where it does
// today.
let token = token.trim();
if token.is_empty() {
return ArtRef::None;
}
// A `file://` url is ALREADY on disk — reqwest cannot even build a
// request for it ("builder error for url"), so it must never be
// fetched.
if let Some(path) = token.strip_prefix("file://") {
return ArtRef::File(PathBuf::from(path));
}
// An offline-download row can keep the CDN url its cover came from.
if token.starts_with("http://") || token.starts_with("https://") {
return ArtRef::Fetch {
url: token.to_string(),
cache_key: token.to_string(),
};
}
if token.starts_with('/') {
return ArtRef::File(PathBuf::from(token));
}
// A bare relative string is not something this source can resolve.
// `classify` returned `Empty` here too.
ArtRef::None
}
fn thumbnail(&self, art: &ArtRef, _size: ArtSize) -> ArtRef {
// EXPENSIVE phase: this is where the decode+downscale happens, on the
// caller's worker pool (`local_artwork::stream_cold`,
@@ -872,4 +904,31 @@ mod tests {
let err = claimed(&raw).unwrap_err();
assert!(matches!(err, SourceError::BadIdShape { by: SourceId::LOCAL, .. }));
}
// ── artwork_token: the LocalFile arm of the dead `classify` ─────────────
/// The four shapes a local row's token really takes. `file://` must come
/// back as a PATH — reqwest cannot even build a request for that scheme,
/// so treating it as fetchable is a guaranteed miss.
#[test]
fn a_local_token_is_a_path_a_cdn_url_or_nothing() {
let l = LocalSource::new();
assert_eq!(
l.artwork_token("file:///home/u/.cache/qbz/thumb.jpg", ArtSize::Card),
ArtRef::File(PathBuf::from("/home/u/.cache/qbz/thumb.jpg"))
);
assert_eq!(
l.artwork_token("/home/u/Music/Album/cover.jpg", ArtSize::Card),
ArtRef::File(PathBuf::from("/home/u/Music/Album/cover.jpg"))
);
// An offline-download row can keep the CDN url its cover came from.
assert!(matches!(
l.artwork_token("https://static.qobuz.com/a.jpg", ArtSize::Card),
ArtRef::Fetch { .. }
));
assert_eq!(l.artwork_token("", ArtSize::Card), ArtRef::None);
assert_eq!(l.artwork_token(" ", ArtSize::Card), ArtRef::None);
// A bare relative string is not resolvable — `classify` said Empty too.
assert_eq!(l.artwork_token("covers/a.jpg", ArtSize::Card), ArtRef::None);
}
}