Correction on cache system

This commit is contained in:
2025-10-19 19:29:10 +02:00
parent 45599787ba
commit 79940e685c
13 changed files with 197 additions and 59 deletions

View File

@@ -12,7 +12,7 @@
use pmodidl::{Container, DIDLLite};
use pmosource::api::{get_source as get_source_from_registry, list_all_sources};
use pmosource::{BrowseResult, MusicSource};
use pmosource::{BrowseResult, MusicSource, MusicSourceError};
use std::sync::Arc;
/// Convertit des containers et items en XML DIDL-Lite
@@ -113,40 +113,52 @@ impl ContentHandler {
}
// Sinon, chercher dans les sources
let mut non_not_found_error: Option<String> = None;
for source in list_all_sources().await {
if let Ok(result) = source.browse(object_id).await {
// L'objet a été trouvé, retourner ses métadonnées
match result {
BrowseResult::Containers(containers) => {
if let Some(container) = containers.first() {
let didl = to_didl_lite(&[container.clone()], &[])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
}
}
BrowseResult::Items(items) => {
if let Some(item) = items.first() {
let didl = to_didl_lite(&[], &[item.clone()])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
}
}
BrowseResult::Mixed { containers, items } => {
if let Some(container) = containers.first() {
let didl = to_didl_lite(&[container.clone()], &[])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
} else if let Some(item) = items.first() {
let didl = to_didl_lite(&[], &[item.clone()])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
match source.browse(object_id).await {
Ok(result) => {
// L'objet a été trouvé, retourner ses métadonnées
match result {
BrowseResult::Containers(containers) => {
if let Some(container) = containers.first() {
let didl = to_didl_lite(&[container.clone()], &[])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
}
}
BrowseResult::Items(items) => {
if let Some(item) = items.first() {
let didl = to_didl_lite(&[], &[item.clone()])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
}
}
BrowseResult::Mixed { containers, items } => {
if let Some(container) = containers.first() {
let didl = to_didl_lite(&[container.clone()], &[])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
} else if let Some(item) = items.first() {
let didl = to_didl_lite(&[], &[item.clone()])?;
let update_id = source.update_id().await;
return Ok((didl, 1, 1, update_id));
}
}
}
}
Err(MusicSourceError::ObjectNotFound(_)) => continue,
Err(e) => {
non_not_found_error = Some(e.to_string());
break;
}
}
}
Err(format!("Object not found: {}", object_id))
if let Some(err) = non_not_found_error {
Err(format!("Browse failed: {}", err))
} else {
Err(format!("Object not found: {}", object_id))
}
}
}
@@ -170,15 +182,27 @@ impl ContentHandler {
}
// Sinon, chercher dans les sources
let mut non_not_found_error: Option<String> = None;
for source in list_all_sources().await {
if let Ok(result) = source.browse(object_id).await {
return self
.browse_result_to_didl(result, source, starting_index, requested_count)
.await;
match source.browse(object_id).await {
Ok(result) => {
return self
.browse_result_to_didl(result, source, starting_index, requested_count)
.await;
}
Err(MusicSourceError::ObjectNotFound(_)) => continue,
Err(e) => {
non_not_found_error = Some(e.to_string());
break;
}
}
}
Err(format!("Container not found: {}", object_id))
if let Some(err) = non_not_found_error {
Err(format!("Browse failed: {}", err))
} else {
Err(format!("Container not found: {}", object_id))
}
}
/// Browse la racine (liste toutes les sources)

View File

@@ -56,10 +56,34 @@ pub fn browse_handler() -> ActionHandler {
let object_id: String = get!(&data, "ObjectID", String);
let browse_flag: String = get!(&data, "BrowseFlag", String);
let starting_index: u32 = get!(&data, "StartingIndex", u32);
let requested_count: u32 = get!(&data, "RequestedCount", u32);
let _filter: String = get!(&data, "Filter", String);
let _sort_criteria: String = get!(&data, "SortCriteria", String);
let starting_index: u32 = get!(
&data,
"StartingIndex",
u32,
"ContentDirectory::Browse misconfigured: 'StartingIndex' missing or not bound"
);
let requested_count: u32 = get!(
&data,
"RequestedCount",
u32,
"ContentDirectory::Browse misconfigured: 'RequestedCount' missing or not bound"
);
let _filter: String = get!(
&data,
"Filter",
String,
"ContentDirectory::Browse misconfigured: 'Filter' missing or not bound"
);
let _sort_criteria: String = get!(
&data,
"SortCriteria",
String,
"ContentDirectory::Browse misconfigured: 'SortCriteria' missing or not bound"
);
info!(
"📂 Browse requested: object_id={} flag={} start={} count={}",