mirror of
https://github.com/FluxaMedia/fluxa-core.git
synced 2026-08-18 04:55:55 +00:00
Sort merged external continue-watching items by savedAt
replace_external_continue_watching_json deduped items via a HashMap and returned them via into_values() with no final sort, so the order was whatever HashMap's randomized per-process iteration produced instead of most-recently-watched-first. Sort descending by saved_at_ms before returning, matching the pattern already used by trakt_playback_items_dedup_json.
This commit is contained in:
parent
93f2651556
commit
ef82039197
1 changed files with 15 additions and 1 deletions
|
|
@ -1240,7 +1240,8 @@ pub(crate) fn replace_external_continue_watching_json(
|
|||
}
|
||||
}
|
||||
|
||||
let result: Vec<Value> = by_id.into_values().collect();
|
||||
let mut result: Vec<Value> = by_id.into_values().collect();
|
||||
result.sort_by(|a, b| saved_at_ms(b).cmp(&saved_at_ms(a)));
|
||||
serde_json::to_string(&result).unwrap_or_else(|_| "[]".to_string())
|
||||
}
|
||||
|
||||
|
|
@ -1946,6 +1947,19 @@ mod tests {
|
|||
use super::*;
|
||||
use serde_json::Value;
|
||||
|
||||
#[test]
|
||||
fn replace_external_continue_watching_sorts_by_saved_at_descending() {
|
||||
let items = json!([
|
||||
{"id": "tt1", "reason": "Nuvio", "timeOffset": 100, "duration": 1000, "savedAt": "2026-07-16T16:18:15Z"},
|
||||
{"id": "tt2", "reason": "Nuvio", "timeOffset": 100, "duration": 1000, "savedAt": "2026-07-18T22:15:23Z"},
|
||||
{"id": "tt3", "reason": "Nuvio", "timeOffset": 100, "duration": 1000, "savedAt": "2026-07-17T19:11:51Z"},
|
||||
]);
|
||||
let result = replace_external_continue_watching_json("[]", Some("Nuvio"), &items.to_string(), None, None);
|
||||
let parsed: Vec<Value> = serde_json::from_str(&result).unwrap();
|
||||
let ids: Vec<&str> = parsed.iter().map(|v| v["id"].as_str().unwrap()).collect();
|
||||
assert_eq!(ids, vec!["tt2", "tt3", "tt1"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extracts_anilist_id_from_link_url() {
|
||||
let meta = json!({"links": [{"name": "AniList", "category": "other", "url": "https://anilist.co/anime/1535"}]});
|
||||
|
|
|
|||
Loading…
Reference in a new issue