fix(library): allow local artwork paths
This commit is contained in:
1 parent
3f13212978
commit
be28ab1396
3 files changed
+22
-4
No files matched your search
@@ -21,6 +21,12 @@ fn get_artwork_cache_dir() -> Result<PathBuf, String> {
|
|||||||
|
|
||||||
/// Download artwork to cache and return the path
|
/// Download artwork to cache and return the path
|
||||||
fn cache_artwork(url: &str) -> Result<PathBuf, String> {
|
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
|
// Create a hash of the URL for the filename
|
||||||
let mut hasher = Md5::new();
|
let mut hasher = Md5::new();
|
||||||
hasher.update(url.as_bytes());
|
hasher.update(url.as_bytes());
|
||||||
@@ -56,6 +62,19 @@ fn cache_artwork(url: &str) -> Result<PathBuf, String> {
|
|||||||
Ok(cache_path)
|
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
|
/// Format quality info for notification
|
||||||
fn format_quality(bit_depth: Option<u32>, sample_rate: Option<u32>) -> String {
|
fn format_quality(bit_depth: Option<u32>, sample_rate: Option<u32>) -> String {
|
||||||
match (bit_depth, sample_rate) {
|
match (bit_depth, sample_rate) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
"csp": null,
|
"csp": null,
|
||||||
"assetProtocol": {
|
"assetProtocol": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"scope": ["**", "$HOME/**"]
|
"scope": ["$CACHE/qbz/**", "$CONFIG/qbz/**", "$HOME/.cache/qbz/**", "$HOME/.config/qbz/**"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<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 { open } from '@tauri-apps/plugin-dialog';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import {
|
import {
|
||||||
@@ -428,8 +428,7 @@
|
|||||||
|
|
||||||
function getArtworkUrl(path?: string): string {
|
function getArtworkUrl(path?: string): string {
|
||||||
if (!path) return '';
|
if (!path) return '';
|
||||||
// Use asset:// protocol for Tauri 2.0 to load local files in WebView
|
return convertFileSrc(path);
|
||||||
return `asset://localhost/${encodeURIComponent(path)}`;
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user