Merge feature/api-keys-refactor: Remove embedded API keys and add Discogs artwork selector
This major refactor achieves Flathub compliance by removing all embedded API credentials from the binary. All API requests now go through a Cloudflare Workers proxy for secure credential management. New Features: - Discogs artwork selection UI with multi-release support - Catalog number support for audiophile libraries - Carousel navigation for artwork options - Release metadata display (title, year) Technical Changes: - Cloudflare Workers proxy for Last.fm, Spotify, Tidal, Discogs - Database migration adds catalog_number column - URI scheme registration (qbz://) for OAuth flows - Rate limiting and User-Agent validation server-side See CHANGELOG-api-keys-refactor.md for complete details. See POST-MERGE-CLEANUP.md for removing legacy API Keys UI.
This commit is contained in:
commit
9516a1c1fa
18 files changed
+2264
-325
No files matched your search
@@ -5,7 +5,7 @@
|
||||
import {
|
||||
HardDrive, Music, Disc3, Mic2, FolderPlus, Trash2, RefreshCw,
|
||||
Settings, ArrowLeft, X, Play, AlertCircle, ImageDown, Upload, Search, LayoutGrid, List, Edit3,
|
||||
Network, Power, PowerOff
|
||||
Network, Power, PowerOff, ChevronLeft, ChevronRight
|
||||
} from 'lucide-svelte';
|
||||
import FolderSettingsModal from '../FolderSettingsModal.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
@@ -58,6 +58,7 @@
|
||||
title: string;
|
||||
artist: string;
|
||||
year?: number;
|
||||
catalog_number?: string;
|
||||
artwork_path?: string;
|
||||
track_count: number;
|
||||
total_duration_secs: number;
|
||||
@@ -113,6 +114,15 @@
|
||||
lastScan: number | null;
|
||||
}
|
||||
|
||||
interface DiscogsImageOption {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
image_type: string;
|
||||
release_title?: string;
|
||||
release_year?: number;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
onAlbumClick?: (album: LocalAlbum) => void;
|
||||
onQobuzArtistClick?: (artistId: number) => void;
|
||||
@@ -181,6 +191,11 @@
|
||||
let showAlbumEditModal = $state(false);
|
||||
let editingAlbumTitle = $state('');
|
||||
let editingAlbumHidden = $state(false);
|
||||
let discogsImageOptions = $state<DiscogsImageOption[]>([]);
|
||||
let selectedDiscogsImage = $state<string | null>(null);
|
||||
let fetchingDiscogsImages = $state(false);
|
||||
let discogsImagePage = $state(0);
|
||||
const IMAGES_PER_PAGE = 4;
|
||||
|
||||
// Folder selection state (by folder ID)
|
||||
let selectedFolders = $state<Set<number>>(new Set());
|
||||
@@ -809,20 +824,99 @@
|
||||
if (!selectedAlbum) return;
|
||||
editingAlbumTitle = selectedAlbum.title;
|
||||
editingAlbumHidden = false;
|
||||
discogsImageOptions = [];
|
||||
selectedDiscogsImage = null;
|
||||
showAlbumEditModal = true;
|
||||
}
|
||||
|
||||
async function fetchDiscogsArtwork() {
|
||||
if (!selectedAlbum || fetchingDiscogsImages) return;
|
||||
|
||||
try {
|
||||
fetchingDiscogsImages = true;
|
||||
discogsImageOptions = [];
|
||||
selectedDiscogsImage = null;
|
||||
discogsImagePage = 0;
|
||||
|
||||
const options = await invoke<DiscogsImageOption[]>('discogs_search_artwork', {
|
||||
artist: selectedAlbum.artist,
|
||||
album: selectedAlbum.title,
|
||||
catalogNumber: selectedAlbum.catalog_number || null
|
||||
});
|
||||
|
||||
discogsImageOptions = options;
|
||||
console.log(`Found ${options.length} Discogs artwork options`);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch Discogs artwork:', err);
|
||||
alert(`Failed to fetch Discogs artwork: ${err}`);
|
||||
} finally {
|
||||
fetchingDiscogsImages = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Computed values for Discogs image pagination
|
||||
const paginatedDiscogsImages = $derived(
|
||||
discogsImageOptions.slice(
|
||||
discogsImagePage * IMAGES_PER_PAGE,
|
||||
(discogsImagePage + 1) * IMAGES_PER_PAGE
|
||||
)
|
||||
);
|
||||
|
||||
const hasMoreDiscogsPages = $derived(
|
||||
discogsImageOptions.length > (discogsImagePage + 1) * IMAGES_PER_PAGE
|
||||
);
|
||||
|
||||
const hasPrevDiscogsPages = $derived(discogsImagePage > 0);
|
||||
|
||||
function nextDiscogsPage() {
|
||||
if (hasMoreDiscogsPages) {
|
||||
discogsImagePage++;
|
||||
}
|
||||
}
|
||||
|
||||
function prevDiscogsPage() {
|
||||
if (hasPrevDiscogsPages) {
|
||||
discogsImagePage--;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveAlbumEdit() {
|
||||
if (!selectedAlbum) return;
|
||||
|
||||
try {
|
||||
// If a Discogs image was selected, download and set it
|
||||
if (selectedDiscogsImage) {
|
||||
console.log('Downloading Discogs artwork from:', selectedDiscogsImage);
|
||||
|
||||
const localPath = await invoke<string>('discogs_download_artwork', {
|
||||
imageUrl: selectedDiscogsImage,
|
||||
artist: selectedAlbum.artist,
|
||||
album: selectedAlbum.title
|
||||
});
|
||||
|
||||
console.log('Downloaded to:', localPath);
|
||||
|
||||
await invoke('library_set_album_artwork', {
|
||||
albumGroupKey: selectedAlbum.id,
|
||||
artworkPath: localPath
|
||||
});
|
||||
|
||||
console.log('Set album artwork successfully');
|
||||
applyAlbumArtworkUpdate(selectedAlbum.id, localPath);
|
||||
}
|
||||
|
||||
await invoke('library_set_album_hidden', {
|
||||
albumGroupKey: selectedAlbum.id,
|
||||
hidden: editingAlbumHidden
|
||||
});
|
||||
|
||||
// Reset Discogs state
|
||||
discogsImageOptions = [];
|
||||
selectedDiscogsImage = null;
|
||||
discogsImagePage = 0;
|
||||
|
||||
showAlbumEditModal = false;
|
||||
|
||||
|
||||
if (editingAlbumHidden) {
|
||||
clearLocalAlbum();
|
||||
navGoBack();
|
||||
@@ -1368,6 +1462,7 @@
|
||||
<p class="artist">{selectedAlbum.artist}</p>
|
||||
{/if}
|
||||
<p class="meta">
|
||||
{#if selectedAlbum.catalog_number}Cat# {selectedAlbum.catalog_number} • {/if}
|
||||
{#if selectedAlbum.year}{selectedAlbum.year} • {/if}
|
||||
{selectedAlbum.track_count} tracks •
|
||||
{formatTotalDuration(selectedAlbum.total_duration_secs)}
|
||||
@@ -2148,17 +2243,77 @@
|
||||
<Disc3 size={24} />
|
||||
</div>
|
||||
{/if}
|
||||
<button
|
||||
class="secondary-btn"
|
||||
onclick={handleSetAlbumArtwork}
|
||||
disabled={updatingArtwork}
|
||||
>
|
||||
<Upload size={14} />
|
||||
<span>{updatingArtwork ? 'Updating...' : 'Change Cover'}</span>
|
||||
</button>
|
||||
<div class="artwork-actions">
|
||||
<button
|
||||
class="discogs-btn"
|
||||
onclick={handleSetAlbumArtwork}
|
||||
disabled={updatingArtwork}
|
||||
>
|
||||
<Upload size={14} />
|
||||
<span>{updatingArtwork ? 'Updating...' : 'Change Cover'}</span>
|
||||
</button>
|
||||
<button
|
||||
class="discogs-btn"
|
||||
onclick={fetchDiscogsArtwork}
|
||||
disabled={fetchingDiscogsImages}
|
||||
>
|
||||
<img src="/discogs_icon.svg" alt="Discogs" class="discogs-icon" />
|
||||
<span>{fetchingDiscogsImages ? 'Fetching...' : 'Fetch from Discogs'}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if discogsImageOptions.length > 0}
|
||||
<div class="form-group">
|
||||
<div class="discogs-header">
|
||||
<label>Select Artwork from Discogs</label>
|
||||
{#if discogsImageOptions.length > IMAGES_PER_PAGE}
|
||||
<div class="carousel-controls">
|
||||
<button
|
||||
class="carousel-btn"
|
||||
onclick={prevDiscogsPage}
|
||||
disabled={!hasPrevDiscogsPages}
|
||||
title="Previous"
|
||||
>
|
||||
<ChevronLeft size={16} />
|
||||
</button>
|
||||
<span class="page-indicator">
|
||||
{discogsImagePage + 1} / {Math.ceil(discogsImageOptions.length / IMAGES_PER_PAGE)}
|
||||
</span>
|
||||
<button
|
||||
class="carousel-btn"
|
||||
onclick={nextDiscogsPage}
|
||||
disabled={!hasMoreDiscogsPages}
|
||||
title="Next"
|
||||
>
|
||||
<ChevronRight size={16} />
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="discogs-options">
|
||||
{#each paginatedDiscogsImages as option, i}
|
||||
<button
|
||||
class="discogs-option"
|
||||
class:selected={selectedDiscogsImage === option.url}
|
||||
onclick={() => selectedDiscogsImage = option.url}
|
||||
title={option.release_title ? `${option.release_title}${option.release_year ? ` (${option.release_year})` : ''}` : ''}
|
||||
>
|
||||
<img src={option.url} alt={`Option ${discogsImagePage * IMAGES_PER_PAGE + i + 1}`} />
|
||||
<div class="option-info">
|
||||
{#if option.release_title}
|
||||
<div class="release-title">{option.release_title}{#if option.release_year} ({option.release_year}){/if}</div>
|
||||
{/if}
|
||||
<div class="image-dims">{option.width}x{option.height}</div>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<p class="form-hint">Click an image to select it, then click Save</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="form-group">
|
||||
<label class="toggle-label">
|
||||
<input
|
||||
@@ -3494,6 +3649,151 @@
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.artwork-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.discogs-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--bg-quaternary);
|
||||
border-radius: 8px;
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.discogs-btn:hover:not(:disabled) {
|
||||
background: var(--bg-quaternary);
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.discogs-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.discogs-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
filter: invert(1) brightness(0.8);
|
||||
}
|
||||
|
||||
.discogs-options {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.discogs-option {
|
||||
position: relative;
|
||||
aspect-ratio: 1;
|
||||
padding: 0;
|
||||
background: var(--bg-tertiary);
|
||||
border: 2px solid transparent;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.discogs-option:hover {
|
||||
border-color: var(--text-muted);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.discogs-option.selected {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px var(--accent);
|
||||
}
|
||||
|
||||
.discogs-option img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.discogs-option .option-info {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 4px 6px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
font-size: 10px;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.discogs-option .release-title {
|
||||
font-weight: 500;
|
||||
line-height: 1.2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.discogs-option .image-dims {
|
||||
opacity: 0.8;
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
.discogs-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.carousel-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.carousel-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--bg-quaternary);
|
||||
border-radius: 6px;
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.carousel-btn:hover:not(:disabled) {
|
||||
background: var(--bg-quaternary);
|
||||
border-color: var(--text-muted);
|
||||
}
|
||||
|
||||
.carousel-btn:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.page-indicator {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
min-width: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
Reference in new issue
Block a user