Merge branch 'feature/image-lightbox' into pre-release
This commit is contained in:
18 files changed
+602
-32
No files matched your search
@@ -3457,6 +3457,34 @@ impl LibraryDatabase {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Get all custom artist images (for bulk lookup)
|
||||
pub fn get_all_custom_artist_images(
|
||||
&self,
|
||||
) -> Result<std::collections::HashMap<String, String>, LibraryError> {
|
||||
let mut stmt = self
|
||||
.conn
|
||||
.prepare(
|
||||
"SELECT artist_name, custom_image_path FROM artist_images WHERE custom_image_path IS NOT NULL",
|
||||
)
|
||||
.map_err(|e| LibraryError::Database(format!("Failed to prepare query: {}", e)))?;
|
||||
|
||||
let rows = stmt
|
||||
.query_map([], |row| {
|
||||
Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?))
|
||||
})
|
||||
.map_err(|e| {
|
||||
LibraryError::Database(format!("Failed to query custom artist images: {}", e))
|
||||
})?;
|
||||
|
||||
let mut map = std::collections::HashMap::new();
|
||||
for row in rows {
|
||||
if let Ok((artist_name, custom_image_path)) = row {
|
||||
map.insert(artist_name, custom_image_path);
|
||||
}
|
||||
}
|
||||
Ok(map)
|
||||
}
|
||||
|
||||
/// Get all canonical artist names mapping (for bulk lookup)
|
||||
pub fn get_all_canonical_names(
|
||||
&self,
|
||||
|
||||
+101
-12
@@ -4218,12 +4218,18 @@ pub async fn v2_library_cache_artist_image(
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct CustomArtistImageResult {
|
||||
pub image_path: String,
|
||||
pub thumbnail_path: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn v2_library_set_custom_artist_image(
|
||||
artist_name: String,
|
||||
custom_image_path: String,
|
||||
state: State<'_, LibraryState>,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<CustomArtistImageResult, String> {
|
||||
let artwork_dir = get_artwork_cache_dir();
|
||||
let source = std::path::Path::new(&custom_image_path);
|
||||
if !source.exists() {
|
||||
@@ -4232,20 +4238,43 @@ pub async fn v2_library_set_custom_artist_image(
|
||||
custom_image_path
|
||||
));
|
||||
}
|
||||
let extension = source.extension().and_then(|e| e.to_str()).unwrap_or("jpg");
|
||||
use md5::{Digest, Md5};
|
||||
|
||||
// Validate extension
|
||||
let extension = source
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.map(|e| e.to_lowercase())
|
||||
.unwrap_or_default();
|
||||
if !["png", "jpg", "jpeg", "webp"].contains(&extension.as_str()) {
|
||||
return Err(format!(
|
||||
"Unsupported image format: {}. Use png, jpg, jpeg, or webp.",
|
||||
extension
|
||||
));
|
||||
}
|
||||
|
||||
// Generate filename using MD5 hash of artist name
|
||||
let mut hasher = Md5::new();
|
||||
hasher.update(artist_name.as_bytes());
|
||||
let artist_hash = format!("{:x}", hasher.finalize());
|
||||
let filename = format!(
|
||||
"artist_custom_{}_{}.{}",
|
||||
artist_hash,
|
||||
chrono::Utc::now().timestamp(),
|
||||
extension
|
||||
);
|
||||
let dest_path = artwork_dir.join(filename);
|
||||
std::fs::copy(source, &dest_path).map_err(|e| format!("Failed to copy artwork: {}", e))?;
|
||||
let timestamp = chrono::Utc::now().timestamp();
|
||||
let filename = format!("artist_custom_{}_{}.jpg", artist_hash, timestamp);
|
||||
let dest_path = artwork_dir.join(&filename);
|
||||
|
||||
// Decode, resize to max 1000x1000, save as JPEG
|
||||
let img = image::ImageReader::open(source)
|
||||
.map_err(|e| format!("Failed to open image: {}", e))?
|
||||
.decode()
|
||||
.map_err(|e| format!("Failed to decode image: {}", e))?;
|
||||
let resized = img.resize(1000, 1000, image::imageops::FilterType::Lanczos3);
|
||||
resized
|
||||
.save(&dest_path)
|
||||
.map_err(|e| format!("Failed to save resized image: {}", e))?;
|
||||
|
||||
// Generate 500x500 thumbnail using qbz-library
|
||||
let thumbnail_path = thumbnails::generate_thumbnail(&dest_path)
|
||||
.map_err(|e| format!("Failed to generate thumbnail: {}", e))?;
|
||||
|
||||
// Update database
|
||||
let guard = state.db.lock().await;
|
||||
let db = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
db.cache_artist_image(
|
||||
@@ -4254,7 +4283,67 @@ pub async fn v2_library_set_custom_artist_image(
|
||||
"custom",
|
||||
Some(&dest_path.to_string_lossy()),
|
||||
)
|
||||
.map_err(|e| e.to_string())
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
Ok(CustomArtistImageResult {
|
||||
image_path: dest_path.to_string_lossy().into_owned(),
|
||||
thumbnail_path: thumbnail_path.to_string_lossy().into_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn v2_library_remove_custom_artist_image(
|
||||
artist_name: String,
|
||||
state: State<'_, LibraryState>,
|
||||
) -> Result<(), String> {
|
||||
// Get current info to find file paths to delete
|
||||
let guard = state.db.lock().await;
|
||||
let db = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
let info = db.get_artist_image(&artist_name).map_err(|e| e.to_string())?;
|
||||
|
||||
if let Some(info) = info {
|
||||
// Delete custom image file if it exists
|
||||
if let Some(ref path) = info.custom_image_path {
|
||||
let p = std::path::Path::new(path);
|
||||
if p.exists() {
|
||||
// Also remove thumbnail
|
||||
if let Ok(thumb) = thumbnails::get_thumbnail_path(p) {
|
||||
let _ = std::fs::remove_file(thumb);
|
||||
}
|
||||
let _ = std::fs::remove_file(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset to original image (clear custom_image_path, keep image_url)
|
||||
db.cache_artist_image(
|
||||
&artist_name,
|
||||
info.image_url.as_deref(),
|
||||
info.source.as_deref().unwrap_or("qobuz"),
|
||||
None,
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn v2_library_get_artist_image(
|
||||
artist_name: String,
|
||||
state: State<'_, LibraryState>,
|
||||
) -> Result<Option<crate::library::ArtistImageInfo>, String> {
|
||||
let guard = state.db.lock().await;
|
||||
let db = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
db.get_artist_image(&artist_name).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn v2_library_get_all_custom_artist_images(
|
||||
state: State<'_, LibraryState>,
|
||||
) -> Result<std::collections::HashMap<String, String>, String> {
|
||||
let guard = state.db.lock().await;
|
||||
let db = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
db.get_all_custom_artist_images().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -1107,6 +1107,9 @@ pub fn run() {
|
||||
commands_v2::v2_library_update_folder_path,
|
||||
commands_v2::v2_library_cache_artist_image,
|
||||
commands_v2::v2_library_set_custom_artist_image,
|
||||
commands_v2::v2_library_remove_custom_artist_image,
|
||||
commands_v2::v2_library_get_artist_image,
|
||||
commands_v2::v2_library_get_all_custom_artist_images,
|
||||
commands_v2::v2_show_track_notification,
|
||||
commands_v2::v2_subscribe_playlist,
|
||||
commands_v2::v2_cache_track_for_offline,
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<script lang="ts">
|
||||
import { X } from 'lucide-svelte';
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
src: string;
|
||||
alt?: string;
|
||||
}
|
||||
|
||||
let {
|
||||
isOpen,
|
||||
onClose,
|
||||
src,
|
||||
alt = ''
|
||||
}: Props = $props();
|
||||
|
||||
function handleBackdropClick(e: MouseEvent) {
|
||||
if (e.target === e.currentTarget) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape' && isOpen) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
function portal(node: HTMLElement) {
|
||||
document.body.appendChild(node);
|
||||
return {
|
||||
destroy() {
|
||||
node.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
{#if isOpen}
|
||||
<div class="lightbox-overlay" use:portal onclick={handleBackdropClick}>
|
||||
<div class="lightbox-image-wrapper">
|
||||
<img
|
||||
{src}
|
||||
{alt}
|
||||
class="lightbox-image"
|
||||
/>
|
||||
<button class="lightbox-close" onclick={onClose}>
|
||||
<X size={18} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.lightbox-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
padding-left: 140px;
|
||||
z-index: 200000;
|
||||
animation: lightbox-fade-in 150ms ease;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
@keyframes lightbox-fade-in {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.lightbox-image-wrapper {
|
||||
position: relative;
|
||||
max-width: 85vw;
|
||||
max-height: 85vh;
|
||||
}
|
||||
|
||||
.lightbox-image {
|
||||
max-width: 85vw;
|
||||
max-height: 85vh;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.lightbox-close {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
transition: background 150ms ease;
|
||||
}
|
||||
|
||||
.lightbox-close:hover {
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
</style>
|
||||
@@ -16,6 +16,7 @@
|
||||
toggleAlbumFavorite
|
||||
} from '$lib/stores/albumFavoritesStore';
|
||||
import { isBlacklisted as isArtistBlacklisted } from '$lib/stores/artistBlacklistStore';
|
||||
import ImageLightbox from '../ImageLightbox.svelte';
|
||||
|
||||
interface Track {
|
||||
id: number;
|
||||
@@ -153,6 +154,7 @@
|
||||
|
||||
let isFavorite = $state(false);
|
||||
let isFavoriteLoading = $state(false);
|
||||
let lightboxOpen = $state(false);
|
||||
let scrollContainer: HTMLDivElement | null = $state(null);
|
||||
|
||||
// Carousel state for "By the same artist" section
|
||||
@@ -327,7 +329,13 @@
|
||||
<!-- Album Header -->
|
||||
<div class="album-header">
|
||||
<!-- Album Artwork -->
|
||||
<div class="artwork">
|
||||
<div
|
||||
class="artwork"
|
||||
onclick={() => lightboxOpen = true}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') lightboxOpen = true; }}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<img src={album.artwork} alt={album.title} />
|
||||
</div>
|
||||
|
||||
@@ -572,6 +580,13 @@
|
||||
</div>
|
||||
</ViewTransition>
|
||||
|
||||
<ImageLightbox
|
||||
isOpen={lightboxOpen}
|
||||
onClose={() => lightboxOpen = false}
|
||||
src={album.artwork}
|
||||
alt={album.title}
|
||||
/>
|
||||
|
||||
<style>
|
||||
.album-detail {
|
||||
width: 100%;
|
||||
@@ -631,6 +646,7 @@
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.artwork img {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<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 { setCustomImage, removeCustomImage as removeCustomImageFromStore } from '$lib/stores/customArtistImageStore';
|
||||
import { t } from 'svelte-i18n';
|
||||
import { ArrowLeft, User, ChevronDown, ChevronUp, Play, Music, Heart, Search, X, ChevronLeft, ChevronRight, Radio, MoreHorizontal, Info, Disc, Settings } from 'lucide-svelte';
|
||||
import {
|
||||
isBlacklisted,
|
||||
@@ -25,6 +28,7 @@
|
||||
toggleTrackFavorite
|
||||
} from '$lib/stores/favoritesStore';
|
||||
import { tick, onMount, onDestroy } from 'svelte';
|
||||
import ImageLightbox from '../ImageLightbox.svelte';
|
||||
|
||||
interface Track {
|
||||
id: number;
|
||||
@@ -135,6 +139,12 @@
|
||||
|
||||
let bioExpanded = $state(false);
|
||||
let imageError = $state(false);
|
||||
let lightboxOpen = $state(false);
|
||||
let showImageMenu = $state(false);
|
||||
let imageMenuPos = $state({ x: 0, y: 0 });
|
||||
let hasCustomImage = $state(false);
|
||||
let imageOverride = $state<string | null>(null);
|
||||
let customFullImage = $state<string | null>(null);
|
||||
let topTracks = $state<Track[]>([]);
|
||||
let tracksLoading = $state(false);
|
||||
let isFavorite = $state(false);
|
||||
@@ -184,6 +194,9 @@
|
||||
trackFavoritesVersion++;
|
||||
});
|
||||
|
||||
// Load custom image status
|
||||
loadCustomImageStatus();
|
||||
|
||||
// Restore scroll position
|
||||
requestAnimationFrame(() => {
|
||||
const saved = getSavedScrollPosition('artist');
|
||||
@@ -1004,6 +1017,58 @@
|
||||
imageError = true;
|
||||
}
|
||||
|
||||
// Check if artist has a custom image on mount
|
||||
async function loadCustomImageStatus() {
|
||||
try {
|
||||
const info = await invoke<{ custom_image_path?: string | null } | null>('v2_library_get_artist_image', { artistName: artist.name });
|
||||
if (info?.custom_image_path) {
|
||||
hasCustomImage = true;
|
||||
customFullImage = convertFileSrc(info.custom_image_path);
|
||||
imageOverride = customFullImage;
|
||||
}
|
||||
} catch {
|
||||
// No custom image, use default
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAddCustomImage() {
|
||||
showImageMenu = false;
|
||||
const selected = await open({
|
||||
filters: [{ name: 'Images', extensions: ['png', 'jpg', 'jpeg', 'webp'] }],
|
||||
multiple: false
|
||||
});
|
||||
if (!selected) return;
|
||||
|
||||
try {
|
||||
const result = await invoke<{ image_path: string; thumbnail_path: string }>('v2_library_set_custom_artist_image', {
|
||||
artistName: artist.name,
|
||||
customImagePath: selected
|
||||
});
|
||||
imageOverride = convertFileSrc(result.thumbnail_path);
|
||||
customFullImage = convertFileSrc(result.image_path);
|
||||
hasCustomImage = true;
|
||||
imageError = false;
|
||||
setCustomImage(artist.name, convertFileSrc(result.image_path));
|
||||
showToast($t('artist.customImageSet'), 'success');
|
||||
} catch (err) {
|
||||
showToast(`${$t('artist.customImageError')}: ${err}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRemoveCustomImage() {
|
||||
showImageMenu = false;
|
||||
try {
|
||||
await invoke('v2_library_remove_custom_artist_image', { artistName: artist.name });
|
||||
imageOverride = null;
|
||||
customFullImage = null;
|
||||
hasCustomImage = false;
|
||||
removeCustomImageFromStore(artist.name);
|
||||
showToast($t('artist.customImageRemoved'), 'success');
|
||||
} catch (err) {
|
||||
showToast(`${$t('artist.customImageError')}: ${err}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Get biography text (prefer content for full text, fall back to summary)
|
||||
let bioText = $derived(
|
||||
artist.biography?.content || artist.biography?.summary || null
|
||||
@@ -1298,14 +1363,21 @@
|
||||
<div class="artist-header section-anchor" bind:this={aboutSection}>
|
||||
<!-- Artist Image -->
|
||||
<div class="artist-image-column">
|
||||
<div class="artist-image-container">
|
||||
{#if imageError || !artist.image}
|
||||
<div
|
||||
class="artist-image-container"
|
||||
onclick={() => { if (!imageError && (imageOverride || artist.image)) lightboxOpen = true; }}
|
||||
onkeydown={(e) => { if (e.key === 'Enter' && !imageError && (imageOverride || artist.image)) lightboxOpen = true; }}
|
||||
oncontextmenu={(e) => { e.preventDefault(); imageMenuPos = { x: e.clientX, y: e.clientY }; showImageMenu = true; }}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
{#if imageError || (!imageOverride && !artist.image)}
|
||||
<div class="artist-image-placeholder">
|
||||
<User size={60} />
|
||||
</div>
|
||||
{:else}
|
||||
<img
|
||||
src={artist.image}
|
||||
src={imageOverride ?? artist.image}
|
||||
alt={artist.name}
|
||||
class="artist-image"
|
||||
loading="lazy"
|
||||
@@ -2437,6 +2509,40 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<ImageLightbox
|
||||
isOpen={lightboxOpen}
|
||||
onClose={() => lightboxOpen = false}
|
||||
src={customFullImage ?? imageOverride ?? artist.image ?? ''}
|
||||
alt={artist.name}
|
||||
/>
|
||||
|
||||
{#if showImageMenu}
|
||||
<div
|
||||
class="image-context-backdrop"
|
||||
onclick={() => showImageMenu = false}
|
||||
onkeydown={(e) => { if (e.key === 'Escape') showImageMenu = false; }}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
></div>
|
||||
<div
|
||||
class="image-context-menu"
|
||||
style="left: {imageMenuPos.x}px; top: {imageMenuPos.y}px;"
|
||||
>
|
||||
{#if hasCustomImage}
|
||||
<button class="image-context-item" onclick={handleAddCustomImage}>
|
||||
{$t('artist.changeImage')}
|
||||
</button>
|
||||
<button class="image-context-item danger" onclick={handleRemoveCustomImage}>
|
||||
{$t('artist.removeImage')}
|
||||
</button>
|
||||
{:else}
|
||||
<button class="image-context-item" onclick={handleAddCustomImage}>
|
||||
{$t('artist.addImage')}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.artist-detail {
|
||||
width: 100%;
|
||||
@@ -2675,6 +2781,7 @@
|
||||
|
||||
.artist-image-container {
|
||||
flex-shrink: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.artist-image {
|
||||
@@ -3952,4 +4059,53 @@
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.image-context-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2999;
|
||||
}
|
||||
|
||||
.image-context-menu {
|
||||
position: fixed;
|
||||
z-index: 3000;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
padding: 4px;
|
||||
min-width: 180px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
|
||||
animation: lightbox-fade-in 100ms ease;
|
||||
}
|
||||
|
||||
@keyframes lightbox-fade-in {
|
||||
from { opacity: 0; transform: scale(0.95); }
|
||||
to { opacity: 1; transform: scale(1); }
|
||||
}
|
||||
|
||||
.image-context-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
transition: background 100ms ease;
|
||||
}
|
||||
|
||||
.image-context-item:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.image-context-item.danger {
|
||||
color: var(--color-error, #ef4444);
|
||||
}
|
||||
|
||||
.image-context-item.danger:hover {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { resolveArtistImage } from '$lib/stores/customArtistImageStore';
|
||||
import { onMount, tick } from 'svelte';
|
||||
import { get } from 'svelte/store';
|
||||
import { t } from '$lib/i18n';
|
||||
@@ -897,6 +898,17 @@
|
||||
}));
|
||||
}
|
||||
|
||||
function withCustomImages(artists: FavoriteArtist[]): FavoriteArtist[] {
|
||||
return artists.map(artist => {
|
||||
const defaultUrl = artist.image?.large || artist.image?.thumbnail || artist.image?.small || '';
|
||||
const resolved = resolveArtistImage(artist.name, defaultUrl);
|
||||
if (resolved !== defaultUrl) {
|
||||
return { ...artist, image: { large: resolved, thumbnail: resolved, small: resolved } };
|
||||
}
|
||||
return artist;
|
||||
});
|
||||
}
|
||||
|
||||
function groupArtists(items: FavoriteArtist[]) {
|
||||
const prefix = 'artist-alpha';
|
||||
const sorted = [...items].sort((a, b) => a.name.localeCompare(b.name));
|
||||
@@ -1452,7 +1464,7 @@
|
||||
|
||||
<!-- Alpha Index inline for artists in Browse (sidepanel) view -->
|
||||
{#if activeTab === 'artists' && artistViewMode === 'sidepanel' && filteredArtists.length > 0}
|
||||
{@const groupedArtistsForIndex = groupArtists(filteredArtists)}
|
||||
{@const groupedArtistsForIndex = groupArtists(withCustomImages(filteredArtists))}
|
||||
{@const artistAlphaGroupsForIndex = new Set(groupedArtistsForIndex.map(group => group.key))}
|
||||
<div class="alpha-index-inline">
|
||||
{#each alphaIndexLetters as letter}
|
||||
@@ -1657,7 +1669,7 @@
|
||||
</div>
|
||||
{:else if artistViewMode === 'sidepanel'}
|
||||
<!-- Two-column sidepanel view -->
|
||||
{@const groupedArtistsSidepanel = groupArtists(filteredArtists)}
|
||||
{@const groupedArtistsSidepanel = groupArtists(withCustomImages(filteredArtists))}
|
||||
<div class="artist-two-column-layout">
|
||||
<!-- Left column: Artists list grouped A-Z (virtualized) -->
|
||||
<div class="artist-column">
|
||||
@@ -1871,7 +1883,7 @@
|
||||
{:else}
|
||||
<!-- Virtualized artist grid (grouped or ungrouped) -->
|
||||
{@const artistGridGroups = artistGroupingEnabled
|
||||
? groupArtists(filteredArtists)
|
||||
? groupArtists(withCustomImages(filteredArtists))
|
||||
: [{ key: '', id: 'all', artists: filteredArtists }]}
|
||||
{@const artistAlphaGroups = artistGroupingEnabled
|
||||
? new Set(artistGridGroups.map(grp => grp.key))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from 'svelte';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { resolveArtistImage } from '$lib/stores/customArtistImageStore';
|
||||
import { Music, User, Loader2, ArrowRight } from 'lucide-svelte';
|
||||
import { type OfflineCacheStatus } from '$lib/stores/offlineCacheState';
|
||||
import {
|
||||
@@ -585,7 +586,7 @@
|
||||
return {
|
||||
id: artist.id,
|
||||
name: artist.name,
|
||||
image: getQobuzImage(artist.image),
|
||||
image: resolveArtistImage(artist.name, getQobuzImage(artist.image)),
|
||||
playCount
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { resolveArtistImage } from '$lib/stores/customArtistImageStore';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { ArrowLeft, Disc3, Play, Music, MoreHorizontal, Heart, User, ChevronDown, ChevronUp } from 'lucide-svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
@@ -525,7 +526,11 @@
|
||||
}
|
||||
|
||||
function getArtistImageUrl(artist: Record<string, unknown>): string | null {
|
||||
// 0. Check fetched image cache
|
||||
// 0a. Check custom artist image overrides
|
||||
const artistName = getArtistName(artist);
|
||||
const customUrl = resolveArtistImage(artistName, '');
|
||||
if (customUrl) return customUrl;
|
||||
// 0b. Check fetched image cache
|
||||
const cached = artistImageMap.get(artist.id as number);
|
||||
if (cached) return cached;
|
||||
// 1. image object (most common in search results)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { invoke, convertFileSrc } from '@tauri-apps/api/core';
|
||||
import { setCustomImage } from '$lib/stores/customArtistImageStore';
|
||||
import { getThumbnailUrl, getCachedThumbnailUrl } from '$lib/services/thumbnailService';
|
||||
import { open, ask } from '@tauri-apps/plugin-dialog';
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
@@ -2976,16 +2977,17 @@
|
||||
|
||||
const imagePath = Array.isArray(selected) ? selected[0] : selected;
|
||||
|
||||
// Save to database
|
||||
await invoke('v2_library_set_custom_artist_image', {
|
||||
// Save to database (returns resized paths)
|
||||
const result = await invoke<{ image_path: string; thumbnail_path: string }>('v2_library_set_custom_artist_image', {
|
||||
artistName,
|
||||
customImagePath: imagePath
|
||||
});
|
||||
|
||||
// Update local state
|
||||
const imageUrl = convertFileSrc(imagePath);
|
||||
// Update local state with resized thumbnail
|
||||
const imageUrl = convertFileSrc(result.thumbnail_path);
|
||||
artistImages.set(artistName, imageUrl);
|
||||
artistImages = new Map(artistImages);
|
||||
setCustomImage(artistName, convertFileSrc(result.image_path));
|
||||
} catch (err) {
|
||||
console.error('Failed to upload custom artist image:', err);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { resolveArtistImage } from '$lib/stores/customArtistImageStore';
|
||||
import { Search, Disc3, Music, Mic2, User, X, ChevronLeft, ChevronRight, Crown, Heart, Play, MoreHorizontal, ListPlus } from 'lucide-svelte';
|
||||
import AlbumCard from '../AlbumCard.svelte';
|
||||
import SearchPlaylistCard from '../SearchPlaylistCard.svelte';
|
||||
@@ -742,7 +743,8 @@
|
||||
}
|
||||
|
||||
function getArtistImage(artist: Artist): string {
|
||||
return artist.image?.large || artist.image?.thumbnail || artist.image?.small || '';
|
||||
const defaultUrl = artist.image?.large || artist.image?.thumbnail || artist.image?.small || '';
|
||||
return resolveArtistImage(artist.name, defaultUrl);
|
||||
}
|
||||
|
||||
// Title case query for better API results (Qobuz returns most_popular more consistently with proper capitalization)
|
||||
|
||||
@@ -241,7 +241,13 @@
|
||||
"noBiography": "Keine Biografie verfügbar",
|
||||
"tributes": "Tributes & Coverversionen",
|
||||
"others": "Andere",
|
||||
"playlists": "Playlists"
|
||||
"playlists": "Playlists",
|
||||
"addImage": "Eigenes Künstlerbild hinzufügen",
|
||||
"changeImage": "Eigenes Künstlerbild ändern",
|
||||
"removeImage": "Eigenes Künstlerbild entfernen",
|
||||
"customImageSet": "Künstlerbild aktualisiert",
|
||||
"customImageRemoved": "Eigenes Künstlerbild entfernt",
|
||||
"customImageError": "Fehler beim Aktualisieren des Künstlerbilds"
|
||||
},
|
||||
"sort": {
|
||||
"nameAZ": "Name (A-Z)",
|
||||
|
||||
@@ -253,7 +253,13 @@
|
||||
"noBiography": "No biography available",
|
||||
"tributes": "Tributes & Covers",
|
||||
"others": "Others",
|
||||
"playlists": "Playlists"
|
||||
"playlists": "Playlists",
|
||||
"addImage": "Add custom artist image",
|
||||
"changeImage": "Change custom artist image",
|
||||
"removeImage": "Remove custom artist image",
|
||||
"customImageSet": "Artist image updated",
|
||||
"customImageRemoved": "Custom artist image removed",
|
||||
"customImageError": "Failed to update artist image"
|
||||
},
|
||||
"sort": {
|
||||
"nameAZ": "Name (A-Z)",
|
||||
|
||||
@@ -253,7 +253,13 @@
|
||||
"noBiography": "No hay biografía disponible",
|
||||
"tributes": "Tributos y Covers",
|
||||
"others": "Otros",
|
||||
"playlists": "Playlists"
|
||||
"playlists": "Playlists",
|
||||
"addImage": "Agregar imagen personalizada",
|
||||
"changeImage": "Cambiar imagen personalizada",
|
||||
"removeImage": "Eliminar imagen personalizada",
|
||||
"customImageSet": "Imagen del artista actualizada",
|
||||
"customImageRemoved": "Imagen personalizada eliminada",
|
||||
"customImageError": "Error al actualizar imagen del artista"
|
||||
},
|
||||
"sort": {
|
||||
"nameAZ": "Nombre (A-Z)",
|
||||
|
||||
@@ -241,7 +241,13 @@
|
||||
"noBiography": "Aucune biographie disponible",
|
||||
"tributes": "Hommages et reprises",
|
||||
"others": "Autres",
|
||||
"playlists": "Playlists"
|
||||
"playlists": "Playlists",
|
||||
"addImage": "Ajouter une image personnalisée",
|
||||
"changeImage": "Changer l'image personnalisée",
|
||||
"removeImage": "Supprimer l'image personnalisée",
|
||||
"customImageSet": "Image de l'artiste mise à jour",
|
||||
"customImageRemoved": "Image personnalisée supprimée",
|
||||
"customImageError": "Erreur lors de la mise à jour de l'image"
|
||||
},
|
||||
"sort": {
|
||||
"nameAZ": "Nom (A-Z)",
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Custom Artist Image Store
|
||||
*
|
||||
* Manages global resolution of user-uploaded custom artist images.
|
||||
* Loaded on login, exposes resolveArtistImage() for all views.
|
||||
*/
|
||||
|
||||
import { invoke, convertFileSrc } from '@tauri-apps/api/core';
|
||||
|
||||
// ============ State ============
|
||||
|
||||
/** Map of normalized artist name -> asset URL (convertFileSrc'd) */
|
||||
let imageMap: Map<string, string> = new Map();
|
||||
|
||||
/** Map of normalized name -> original name (for reverse lookup) */
|
||||
let nameMap: Map<string, string> = new Map();
|
||||
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function notifyListeners(): void {
|
||||
for (const listener of listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Normalization ============
|
||||
|
||||
/**
|
||||
* Normalize artist name for matching.
|
||||
* Lowercase, strip diacritics, strip non-alphanumeric.
|
||||
* Handles "Björk" vs "Bjork", "Héctor Lavoe" vs "Hector Lavoe", etc.
|
||||
*/
|
||||
function normalize(name: string): string {
|
||||
return name
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/g, '');
|
||||
}
|
||||
|
||||
// ============ Public API ============
|
||||
|
||||
/**
|
||||
* Load all custom artist images from backend
|
||||
*/
|
||||
export async function initCustomArtistImageStore(): Promise<void> {
|
||||
const mapping = await invoke<Record<string, string>>(
|
||||
'v2_library_get_all_custom_artist_images'
|
||||
);
|
||||
|
||||
imageMap = new Map();
|
||||
nameMap = new Map();
|
||||
|
||||
for (const [artistName, filePath] of Object.entries(mapping)) {
|
||||
const key = normalize(artistName);
|
||||
imageMap.set(key, convertFileSrc(filePath));
|
||||
nameMap.set(key, artistName);
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve artist image: returns custom URL if set, otherwise the default.
|
||||
*/
|
||||
export function resolveArtistImage(
|
||||
artistName: string,
|
||||
defaultUrl: string
|
||||
): string {
|
||||
const key = normalize(artistName);
|
||||
return imageMap.get(key) ?? defaultUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an artist has a custom image override.
|
||||
*/
|
||||
export function hasCustomImage(artistName: string): boolean {
|
||||
return imageMap.has(normalize(artistName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update store after user sets a custom image (no backend call).
|
||||
*/
|
||||
export function setCustomImage(artistName: string, assetUrl: string): void {
|
||||
const key = normalize(artistName);
|
||||
imageMap.set(key, assetUrl);
|
||||
nameMap.set(key, artistName);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update store after user removes a custom image (no backend call).
|
||||
*/
|
||||
export function removeCustomImage(artistName: string): void {
|
||||
const key = normalize(artistName);
|
||||
imageMap.delete(key);
|
||||
nameMap.delete(key);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all custom artist images (on logout).
|
||||
*/
|
||||
export function clearCustomArtistImages(): void {
|
||||
imageMap = new Map();
|
||||
nameMap = new Map();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to store changes.
|
||||
*/
|
||||
export function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export const ZOOM_OPTIONS = ['80%', '90%', '100%', '110%', '125%', '150%', '175%'] as const;
|
||||
export const ZOOM_OPTIONS = ['80%', '85%', '90%', '95%', '100%', '110%', '125%', '150%', '175%'] as const;
|
||||
|
||||
export const ZOOM_LEVELS = ZOOM_OPTIONS.map((option) => {
|
||||
const parsed = Number.parseFloat(option);
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
isAutoplayEnabled
|
||||
} from '$lib/stores/playbackPreferencesStore';
|
||||
import { initBlacklistStore, isBlacklisted as isArtistBlacklisted } from '$lib/stores/artistBlacklistStore';
|
||||
import { initCustomArtistImageStore, clearCustomArtistImages } from '$lib/stores/customArtistImageStore';
|
||||
|
||||
// UI state management
|
||||
import {
|
||||
@@ -2583,6 +2584,7 @@
|
||||
console.log('[Session] Persist session enabled:', sessionPersistEnabled);
|
||||
}).catch(err => console.debug('[PlaybackPrefs] Init deferred:', err));
|
||||
initBlacklistStore().catch(err => console.debug('[Blacklist] Init deferred:', err));
|
||||
initCustomArtistImageStore().catch(err => console.debug('[CustomArtistImages] Init deferred:', err));
|
||||
refreshUpdatePreferences().catch(err => console.debug('[Updates] Prefs refresh deferred:', err));
|
||||
|
||||
// Load audio settings (normalization state) now that session is active
|
||||
@@ -2701,6 +2703,7 @@
|
||||
setStorageUserId(null);
|
||||
// Clear session state
|
||||
await clearSession();
|
||||
clearCustomArtistImages();
|
||||
setLoggedOut();
|
||||
sessionReady = false;
|
||||
updatesLaunchTriggered = false;
|
||||
|
||||
Reference in new issue
Block a user