From ff7b7b446fa68b8a92a40bb15fb188efbb2a64bb Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Thu, 28 May 2026 16:00:51 +0200 Subject: [PATCH] Fix IGDB result selection: use DOM data attributes + pass igdb_id to backend Two issues fixed: 1. Frontend closure bug: IGDB result buttons used Svelte {#each} closure with onclick={() => doUpload(result.name)}. When clicking the 3rd result, the 1st result's handler sometimes fired. Fixed by reading data-name from e.currentTarget.dataset instead of JS closure. 2. Backend scrape mismatch: when user selected 'Blood' from IGDB results, backend's autoScrape searched for 'Blood' and could match 'Captain Blood' first (alphabetical), overwriting metadata. Now passes igdb_id along with title so backend uses the EXACT IGDB entry the user selected via applyIgdbId() instead of auto-searching. --- frontend/src/lib/api.js | 3 ++- frontend/src/pages/Library.svelte | 10 ++++++---- src/main/java/com/dostalgia/UploadResource.java | 11 ++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/frontend/src/lib/api.js b/frontend/src/lib/api.js index 1f54b3a..6ba1495 100644 --- a/frontend/src/lib/api.js +++ b/frontend/src/lib/api.js @@ -43,10 +43,11 @@ export async function deleteGame(id) { } /** Upload a game ZIP */ -export async function uploadGame(file, title) { +export async function uploadGame(file, title, igdbId) { const form = new FormData(); form.append("file", file); if (title) form.append("title", title); + if (igdbId) form.append("igdb_id", String(igdbId)); const res = await fetch(`${BASE}/api/upload`, { method: "POST", diff --git a/frontend/src/pages/Library.svelte b/frontend/src/pages/Library.svelte index 0ea0155..da90bc0 100644 --- a/frontend/src/pages/Library.svelte +++ b/frontend/src/pages/Library.svelte @@ -82,12 +82,12 @@ manualSearched = false; } - async function doUpload(title) { + async function doUpload(title, igdbId) { if (!pendingFile) return; uploading = true; uploadError = ""; try { - await uploadGame(pendingFile, title || undefined); + await uploadGame(pendingFile, title || undefined, igdbId); cancelUpload(); await loadGames(); } catch (err) { @@ -139,10 +139,12 @@ {:else if igdbResults !== null && igdbResults.length > 0}

Select a match or enter a custom title:

- {#each igdbResults as result (result.igdb_id)} + {#each igdbResults as result}