From 265de6d7fa3f89c8091ae31dd61f849535efc011 Mon Sep 17 00:00:00 2001 From: thomas-bassett Date: Sun, 30 Nov 2025 11:47:55 +0000 Subject: [PATCH] Improve card lookup by handling leading zeros in IDs Updated the 'cards' endpoint to attempt fetching cards by both the original and normalized IDs with leading zeros removed. This enhances compatibility with different ID formats across sets and ensures existing user links remain functional. --- server/src/V2/endpoints/jsonEndpoints.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/server/src/V2/endpoints/jsonEndpoints.ts b/server/src/V2/endpoints/jsonEndpoints.ts index 31f9062608..c0c188efed 100644 --- a/server/src/V2/endpoints/jsonEndpoints.ts +++ b/server/src/V2/endpoints/jsonEndpoints.ts @@ -225,14 +225,32 @@ server let result: unknown switch (endpoint) { - case 'cards': - // console.time('card') - result = await getCardById(lang, id) + case 'cards': { + // Try original and normalized IDs with leading zeros removed + // This is to accommodate for different ID formatting in various sets + // but also to allow current users not having to change their links + // e.g., "base1-001" will return "base1-1" + const tried = new Set(); + let found = false; + const parts = id.split('-'); + for (let zeros = 0; zeros <= 3 && !found; zeros++) { + const newParts = [...parts]; + if (parts.length > 1) { + newParts[newParts.length - 1] = newParts[newParts.length - 1].replace(new RegExp(`^0{0,${zeros}}`), ''); + } + const testId = newParts.join('-'); + if (!tried.has(testId)) { + result = await getCardById(lang, testId); + tried.add(testId); + if (result) found = true; + } + } if (!result) { result = await findOneCard(lang, { name: id }) } // console.timeEnd('card') break + } case 'sets': result = await findOneSet(lang, { id })