From ce8f6a13560ddb4030ec7f088a865886452f5899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Mon, 10 Nov 2025 12:52:39 +0000 Subject: [PATCH] feat(npdl): Support edge cases for country and language-specific files --- src/services/npdl.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/services/npdl.ts b/src/services/npdl.ts index c9a5d5d..7585196 100644 --- a/src/services/npdl.ts +++ b/src/services/npdl.ts @@ -3,7 +3,7 @@ import { getCTRTaskFile } from '@/database'; import { config } from '@/config-manager'; import { restrictHostnames } from '@/middleware/host-limit'; import { getCDNFileAsStream, streamFileToResponse } from '@/cdn'; -import { handleEtag, sendEtagCacheResponse } from '@/util'; +import { handleEtag, isValidCountryCode, sendEtagCacheResponse } from '@/util'; const npdl = express.Router(); @@ -23,7 +23,26 @@ npdl.get([ }>, response) => { const { appID, taskID, countryCode, languageCode, fileName } = request.params; - const file = await getCTRTaskFile(appID, taskID, fileName, countryCode, languageCode); + // * There are some special cases that we need to account for some specific 3DS task files: + // * + // * 1. The country and language being represented in a single parameter with an underscore :languageCode_:countryCode + // * 2. Only the country parameter being set instead of the language + // * + // * This isn't the standard behavior as it doesn't work for all tasks, only some of them do need it + // * (this is so unstandard that you can't officially find tasks which use an underscore with the file list endpoint). + // * I'm sure whoever designed this behavior must be the most evil person I've ever met + let country: string | undefined; + let language: string | undefined; + if (countryCode == undefined && languageCode !== undefined && languageCode.includes('_')) { + [language, country] = languageCode.split('_'); + } else if (countryCode == undefined && languageCode !== undefined && isValidCountryCode(languageCode)) { + country = languageCode; + } else { + country = countryCode; + language = languageCode; + } + + const file = await getCTRTaskFile(appID, taskID, fileName, country, language); if (!file) { response.sendStatus(404);