Many improvemtns and fixes related to decoupling of svelte and rust on android.
This commit is contained in:
@@ -36,6 +36,29 @@ impl OnlineRepository {
|
||||
HttpClient::build_auth_header(Some(&self.access_token), "jellytau-device")
|
||||
}
|
||||
|
||||
/// Download raw bytes from a URL using the shared authenticated HTTP client.
|
||||
/// Used by thumbnail cache to download images with proper auth and connection reuse.
|
||||
pub async fn download_bytes(&self, url: &str) -> Result<Vec<u8>, String> {
|
||||
let request = self.http_client.client.get(url)
|
||||
.header("X-Emby-Authorization", self.auth_header())
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to build request: {}", e))?;
|
||||
|
||||
let response = self.http_client.request_with_retry(request).await
|
||||
.map_err(|e| format!("Download failed: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
let body_preview = if body.len() > 200 { &body[..200] } else { &body };
|
||||
return Err(format!("HTTP {} ({})", status, body_preview.trim()));
|
||||
}
|
||||
|
||||
response.bytes().await
|
||||
.map(|b| b.to_vec())
|
||||
.map_err(|e| format!("Failed to read bytes: {}", e))
|
||||
}
|
||||
|
||||
/// Make authenticated GET request
|
||||
async fn get_json<T: for<'de> Deserialize<'de>>(&self, endpoint: &str) -> Result<T, RepoError> {
|
||||
let url = format!("{}{}", self.server_url, endpoint);
|
||||
@@ -1005,8 +1028,12 @@ impl MediaRepository for OnlineRepository {
|
||||
image_type.as_str()
|
||||
);
|
||||
|
||||
// Authentication is handled by X-Emby-Authorization header in download_bytes()
|
||||
// Do NOT include api_key here — some Jellyfin servers reject requests when
|
||||
// api_key is present but the token doesn't match the expected format.
|
||||
let mut params: Vec<String> = Vec::new();
|
||||
|
||||
if let Some(opts) = options {
|
||||
let mut params = Vec::new();
|
||||
if let Some(width) = opts.max_width {
|
||||
params.push(format!("maxWidth={}", width));
|
||||
}
|
||||
@@ -1019,11 +1046,11 @@ impl MediaRepository for OnlineRepository {
|
||||
if let Some(tag) = opts.tag {
|
||||
params.push(format!("tag={}", tag));
|
||||
}
|
||||
}
|
||||
|
||||
if !params.is_empty() {
|
||||
url.push('?');
|
||||
url.push_str(¶ms.join("&"));
|
||||
}
|
||||
if !params.is_empty() {
|
||||
url.push('?');
|
||||
url.push_str(¶ms.join("&"));
|
||||
}
|
||||
|
||||
url
|
||||
|
||||
Reference in New Issue
Block a user