feat(npdl): Support edge cases for country and language-specific files
Some checks are pending
Build and Publish Docker Image / Build and Publish Docker Image (amd64) (push) Waiting to run
Build and Publish Docker Image / Build and Publish Docker Image (arm64) (push) Waiting to run

This commit is contained in:
Daniel López Guimaraes 2025-11-10 12:52:39 +00:00
parent 35f23f710c
commit ce8f6a1356
No known key found for this signature in database
GPG Key ID: 6AC74DE3DEF050E0

View File

@ -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);