From 03fdfaed3b1a05e3da3de3769b58d2e4006842d4 Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Mon, 14 Sep 2026 22:14:27 +0200 Subject: [PATCH] feat(ui): display detailed source provenance and match confidence in hero --- public/search.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/public/search.js b/public/search.js index b3ca42f..8737076 100644 --- a/public/search.js +++ b/public/search.js @@ -134,12 +134,32 @@ function getYoutubeUrl(track) { return `https://www.youtube.com/results?search_query=${encodeURIComponent(term)}`; } +function formatSourceInfo(source, isCorrected) { + if (isCorrected) return { match: '100%', label: 'PostgreSQL (Fix)' }; + switch (source) { + case 'spotify': + case 'seed': + return { match: '100%', label: 'Spotify (Verifiziert)' }; + case 'songbpm': + return { match: '98%', label: 'SongBPM (Spotify API)' }; + case 'audio_analysis': + return { match: '85%', label: 'Audio-Analyse (ffmpeg)' }; + case 'getsongbpm': + return { match: '90%', label: 'GetSongBPM' }; + case 'postgresql': + return { match: '100%', label: 'PostgreSQL (Lokal)' }; + default: + return { match: 'Online', label: 'Deezer / Online' }; + } +} + async function selectTrack(track) { // Update Hero UI + const initialSource = formatSourceInfo(track.source || (track.is_local ? 'postgresql' : null), track.is_corrected); document.getElementById('track-title').textContent = track.title; document.getElementById('track-artist').textContent = track.artist; - document.getElementById('stat-match').textContent = track.is_corrected ? '100%' : 'Online'; - document.getElementById('stat-source-sub').textContent = track.is_local ? (track.is_corrected ? 'PostgreSQL (Fix)' : 'PostgreSQL') : 'Deezer / Online'; + document.getElementById('stat-match').textContent = initialSource.match; + document.getElementById('stat-source-sub').textContent = initialSource.label; // Stop any ongoing preview playback if (window.stopAllPreviews) window.stopAllPreviews(); @@ -202,8 +222,9 @@ async function selectTrack(track) { const deezEl = document.getElementById('action-deezer'); if (deezEl) deezEl.href = getDeezerUrl(track); } - document.getElementById('stat-match').textContent = d.is_corrected ? '100%' : (d.source === 'postgresql' ? '100%' : 'Online'); - document.getElementById('stat-source-sub').textContent = d.source === 'postgresql' ? (d.is_corrected ? 'PostgreSQL (Fix)' : 'PostgreSQL') : 'PostgreSQL (Neu)'; + const metaSource = formatSourceInfo(d.source, d.is_corrected); + document.getElementById('stat-match').textContent = metaSource.match; + document.getElementById('stat-source-sub').textContent = metaSource.label; } } catch (e) { console.warn('[Search] Metadata fetch failed, using fallback', e);