From 8fe83f41e34e40ece56155a10e936b1a6e77a975 Mon Sep 17 00:00:00 2001 From: Syco21 Date: Fri, 15 May 2026 22:05:59 +0200 Subject: [PATCH] Fix duplicate image_id crash: deduplicate within batch, restore ON DUPLICATE KEY UPDATE --- src/controllers/importController.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/importController.js b/src/controllers/importController.js index 4c05cb7..427085b 100644 --- a/src/controllers/importController.js +++ b/src/controllers/importController.js @@ -92,6 +92,7 @@ async function importCardsInternal() { const cardValues = [], cardParams = []; const imageValues = [], imageParams = []; const csrValues = [], csrParams = []; + const batchImageIds = new Set(); for (const card of batch) { const fp = cardFingerprint(card); @@ -107,7 +108,8 @@ async function importCardsInternal() { if (Array.isArray(card.card_images)) { for (const img of card.card_images) { - if (!existingImageIds.has(img.id)) { + if (!existingImageIds.has(img.id) && !batchImageIds.has(img.id)) { + batchImageIds.add(img.id); imageValues.push('(?, ?, ?)'); imageParams.push(img.id, card.id, img.image_url); addedImages++; @@ -151,6 +153,7 @@ async function importCardsInternal() { if (imageValues.length) { await conn.execute(` INSERT INTO card_images (image_id, card_id, image_url) VALUES ${imageValues.join(', ')} + ON DUPLICATE KEY UPDATE image_url = VALUES(image_url) `, imageParams); }