fix(library): allow local artwork paths

This commit is contained in:
vicrodh committed 2026-01-12 13:05:04 -06:00
1 parent 3f13212978
commit be28ab1396
3 files changed
+22 -4

No files matched your search

+19
View File
@@ -21,6 +21,12 @@ fn get_artwork_cache_dir() -> Result<PathBuf, String> {
/// Download artwork to cache and return the path
fn cache_artwork(url: &str) -> Result<PathBuf, String> {
if let Some(local_path) = resolve_local_artwork(url) {
if local_path.exists() {
return Ok(local_path);
}
}
// Create a hash of the URL for the filename
let mut hasher = Md5::new();
hasher.update(url.as_bytes());
@@ -56,6 +62,19 @@ fn cache_artwork(url: &str) -> Result<PathBuf, String> {
Ok(cache_path)
}
fn resolve_local_artwork(url: &str) -> Option<PathBuf> {
if let Some(path) = url.strip_prefix("file://") {
return Some(PathBuf::from(path));
}
if let Some(path) = url.strip_prefix("asset://localhost/") {
let decoded = urlencoding::decode(path).ok()?;
return Some(PathBuf::from(decoded.into_owned()));
}
None
}
/// Format quality info for notification
fn format_quality(bit_depth: Option<u32>, sample_rate: Option<u32>) -> String {
match (bit_depth, sample_rate) {
+1 -1
View File
@@ -26,7 +26,7 @@
"csp": null,
"assetProtocol": {
"enable": true,
"scope": ["**", "$HOME/**"]
"scope": ["$CACHE/qbz/**", "$CONFIG/qbz/**", "$HOME/.cache/qbz/**", "$HOME/.config/qbz/**"]
}
}
},
@@ -1,5 +1,5 @@
<script lang="ts">
import { invoke } from '@tauri-apps/api/core';
import { invoke, convertFileSrc } from '@tauri-apps/api/core';
import { open } from '@tauri-apps/plugin-dialog';
import { onMount } from 'svelte';
import {
@@ -428,8 +428,7 @@
function getArtworkUrl(path?: string): string {
if (!path) return '';
// Use asset:// protocol for Tauri 2.0 to load local files in WebView
return `asset://localhost/${encodeURIComponent(path)}`;
return convertFileSrc(path);
}
</script>