feat(qt): the Local Library union, the settings store and the sweep
Three pieces that only mean anything together: rows in the shared cache,
a union that shows them, and settings that decide whether either
happens.
THE UNION. `get_albums_metadata_page` grows a second, INDEPENDENT
attachment. `plex_cache` stays; `remote_cache` is the shared mirror, and
they attach separately on purpose — a missing Plex cache must not cost
the user their Jellyfin rows. `attach_best_effort` is extracted because
the failure mode of a botched ATTACH is a silently local-only library,
and a failure stays non-fatal: refusing to list any albums because one
server is off turns "Jellyfin is unplugged" into "your library is
empty".
The union takes an ENABLED-SOURCES list, not just a path. The mirror
holds every remote source, so the master toggle has to be a filter
rather than a detach: turning Jellyfin off must hide Jellyfin's rows and
leave Subsonic's alone. That predicate is interpolated into SQL, so it
is VALIDATED rather than escaped — only [a-z] survives, an all-invalid
list yields `0` (show nothing, the safe direction), and a test feeds it
`x'; DROP TABLE local_tracks; --`.
The remote group key is `<source>:<album id>`, matching Plex's
`plex:<hash>`. That namespaces two servers using the same album id AND
lets a source claim an album card that arrives with no source word,
which is every card that round-trips through a QML string property —
`recognises` grew that arm and `claim` strips the prefix, because
carrying it inward is how Plex ended up with two album keys only one of
its queries understood (IC-2).
THE SETTINGS. One store for both servers, keyed by a `server` column,
mirroring the shared-cache decision. What each protocol needs differs
and `is_configured` is the one place that knows: Jellyfin needs its
issued token, Subsonic needs a password because it has no session and
re-derives `md5(password + salt)` per request.
Two identifiers are minted once and persisted, and both are
load-bearing. Jellyfin's DeviceId, because re-authenticating under the
same one revokes the previous token — a constant would make two installs
log each other out, a fresh one per launch drops the last run's token.
Subsonic's salt, because rolling it per request makes every cover URL
unique and the artwork cache keys on the URL.
THE SWEEP. In the frontend, where the runtime and the progress UI are,
writing through the cache handle the SOURCE owns so sweep and reads can
never point at different users. Jellyfin gets progress and a delta path
(45.8 s for 4924 rows); Subsonic needs neither (0.81 s for 6678).
`prune_stale` runs only after a COMPLETED full sweep — a delta never
prunes, because it deliberately does not see unchanged rows and would
read every one of them as deleted. `last_sync_at` is stamped only on
success for the same reason.
Verified against the running binary, twice:
source registry bound: local_tracks=617 plex=connected
ephemeral_store=yes remote=none configured
jellyfin: minted a device id for this install
subsonic: minted a salt for this install
...and on the second launch, zero re-mints and the same values on disk —
which is the property that keeps a Jellyfin session alive.
qbz-qt 428/428, qbz-app 224/224, qbz-library 100/100, qbz-source 88/88.
Release build clean, zero warnings.
cc
This commit is contained in:
17 files changed
+2159
-35
No files matched your search
@@ -116,6 +116,12 @@ impl Default for JellyfinSource {
|
||||
/// class of inference the seam exists to delete.
|
||||
pub(crate) fn recognises(raw: &RawRef) -> bool {
|
||||
raw.source == Some(SourceId::JELLYFIN)
|
||||
// The PREFIXED album key the Local Library grid publishes. Without
|
||||
// this arm an album card carrying no source word — which is every card
|
||||
// that round-trips through a QML string property — would be claimed by
|
||||
// nobody and the album page would open empty. Plex solves the same
|
||||
// problem the same way, with its `plex:` keys.
|
||||
|| raw.id.trim().starts_with("jellyfin:")
|
||||
|| raw
|
||||
.numeric()
|
||||
.map(|n| RemoteSource::of_id(n as i64) == Some(RemoteSource::Jellyfin))
|
||||
@@ -137,14 +143,20 @@ impl Source for JellyfinSource {
|
||||
Some(match kind {
|
||||
// An album id is the server's own, opaque and non-numeric.
|
||||
ItemKind::Album => {
|
||||
if id.is_empty() {
|
||||
// The grid publishes `jellyfin:<server album id>`; a producer
|
||||
// that holds the raw id may pass it bare. STRIP the prefix —
|
||||
// the cache and the server both speak the raw id, and carrying
|
||||
// the prefixed form inward is how Plex ended up with two album
|
||||
// keys only one of its queries understood (survey IC-2).
|
||||
let bare = id.strip_prefix("jellyfin:").unwrap_or(id).trim();
|
||||
if bare.is_empty() {
|
||||
Err(SourceError::BadIdShape {
|
||||
by: SourceId::JELLYFIN,
|
||||
id: id.to_string(),
|
||||
why: "a jellyfin album id is the server's item id, never empty",
|
||||
why: "a jellyfin album id is the server's own id, never empty",
|
||||
})
|
||||
} else {
|
||||
Ok(MediaRef::new(SourceId::JELLYFIN, ItemKind::Album, id))
|
||||
Ok(MediaRef::new(SourceId::JELLYFIN, ItemKind::Album, bare))
|
||||
}
|
||||
}
|
||||
// A TRACK arrives in one of two shapes and both must normalise to
|
||||
@@ -439,6 +451,59 @@ mod tests {
|
||||
}));
|
||||
}
|
||||
|
||||
/// The grid's album key is PREFIXED, and it must round-trip: recognised
|
||||
/// with no source word at all, and stripped back to the raw server id the
|
||||
/// cache and the server both speak.
|
||||
#[test]
|
||||
fn a_prefixed_album_key_is_recognised_and_stripped() {
|
||||
let s = connected();
|
||||
// No source word — the shape a QML string property hands back.
|
||||
let raw = RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "jellyfin:alb-1".into(),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(recognises(&raw), "an unlabelled prefixed key was not recognised");
|
||||
let m = s.claim(&raw).unwrap().unwrap();
|
||||
assert_eq!(m.id(), "alb-1", "the prefix was carried inward");
|
||||
// A bare id with the source word still works.
|
||||
let bare = s
|
||||
.claim(&RawRef {
|
||||
source: Some(SourceId::JELLYFIN),
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "alb-1".into(),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(bare.id(), "alb-1");
|
||||
// A prefix with nothing after it is a named error, not an empty lookup.
|
||||
let err = s
|
||||
.claim(&RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "jellyfin:".into(),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap_err();
|
||||
assert!(matches!(err, SourceError::BadIdShape { by: SourceId::JELLYFIN, .. }));
|
||||
}
|
||||
|
||||
/// ...and it must not answer for the NEIGHBOUR's prefix.
|
||||
#[test]
|
||||
fn it_does_not_recognise_the_other_prefix() {
|
||||
assert!(!recognises(&RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "subsonic:al-abc".into(),
|
||||
..Default::default()
|
||||
}));
|
||||
assert!(!recognises(&RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "plex:5677211365378243606".into(),
|
||||
..Default::default()
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_album_id_is_a_named_error_not_a_lookup() {
|
||||
let s = connected();
|
||||
|
||||
@@ -103,6 +103,12 @@ impl Default for SubsonicSource {
|
||||
/// `SourceId::from_word` has already folded), or the namespace bit.
|
||||
pub(crate) fn recognises(raw: &RawRef) -> bool {
|
||||
raw.source == Some(SourceId::SUBSONIC)
|
||||
// The PREFIXED album key the Local Library grid publishes. Without
|
||||
// this arm an album card carrying no source word — which is every card
|
||||
// that round-trips through a QML string property — would be claimed by
|
||||
// nobody and the album page would open empty. Plex solves the same
|
||||
// problem the same way, with its `plex:` keys.
|
||||
|| raw.id.trim().starts_with("subsonic:")
|
||||
|| raw
|
||||
.numeric()
|
||||
.map(|n| RemoteSource::of_id(n as i64) == Some(RemoteSource::Subsonic))
|
||||
@@ -123,14 +129,20 @@ impl Source for SubsonicSource {
|
||||
let kind = raw.kind.unwrap_or(ItemKind::Track);
|
||||
Some(match kind {
|
||||
ItemKind::Album => {
|
||||
if id.is_empty() {
|
||||
// The grid publishes `subsonic:<server album id>`; a producer
|
||||
// that holds the raw id may pass it bare. STRIP the prefix —
|
||||
// the cache and the server both speak the raw id, and carrying
|
||||
// the prefixed form inward is how Plex ended up with two album
|
||||
// keys only one of its queries understood (survey IC-2).
|
||||
let bare = id.strip_prefix("subsonic:").unwrap_or(id).trim();
|
||||
if bare.is_empty() {
|
||||
Err(SourceError::BadIdShape {
|
||||
by: SourceId::SUBSONIC,
|
||||
id: id.to_string(),
|
||||
why: "a subsonic album id is the server's own id, never empty",
|
||||
})
|
||||
} else {
|
||||
Ok(MediaRef::new(SourceId::SUBSONIC, ItemKind::Album, id))
|
||||
Ok(MediaRef::new(SourceId::SUBSONIC, ItemKind::Album, bare))
|
||||
}
|
||||
}
|
||||
// Same two shapes as Jellyfin, same reason for preferring the hint:
|
||||
@@ -355,6 +367,59 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The grid's album key is PREFIXED, and it must round-trip: recognised
|
||||
/// with no source word at all, and stripped back to the raw server id the
|
||||
/// cache and the server both speak.
|
||||
#[test]
|
||||
fn a_prefixed_album_key_is_recognised_and_stripped() {
|
||||
let s = connected();
|
||||
// No source word — the shape a QML string property hands back.
|
||||
let raw = RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "subsonic:al-abc".into(),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(recognises(&raw), "an unlabelled prefixed key was not recognised");
|
||||
let m = s.claim(&raw).unwrap().unwrap();
|
||||
assert_eq!(m.id(), "al-abc", "the prefix was carried inward");
|
||||
// A bare id with the source word still works.
|
||||
let bare = s
|
||||
.claim(&RawRef {
|
||||
source: Some(SourceId::SUBSONIC),
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "al-abc".into(),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(bare.id(), "al-abc");
|
||||
// A prefix with nothing after it is a named error, not an empty lookup.
|
||||
let err = s
|
||||
.claim(&RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "subsonic:".into(),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap_err();
|
||||
assert!(matches!(err, SourceError::BadIdShape { by: SourceId::SUBSONIC, .. }));
|
||||
}
|
||||
|
||||
/// ...and it must not answer for the NEIGHBOUR's prefix.
|
||||
#[test]
|
||||
fn it_does_not_recognise_the_other_prefix() {
|
||||
assert!(!recognises(&RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "jellyfin:alb-1".into(),
|
||||
..Default::default()
|
||||
}));
|
||||
assert!(!recognises(&RawRef {
|
||||
kind: Some(ItemKind::Album),
|
||||
id: "plex:5677211365378243606".into(),
|
||||
..Default::default()
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_track_normalises_to_the_server_id_from_the_hint() {
|
||||
let s = connected();
|
||||
|
||||
Reference in new issue
Block a user