mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
atob() decodes base64 to a JS string, which r.return() then re-encodes as UTF-8. For filenames with non-ASCII characters (e.g. Pokémon), bytes above 0x7F get double-encoded — serving different content than what the backend computed the CRC32 over, causing mod_zip to report CRC failure on the .m3u file. Buffer.from(value, 'base64') decodes directly to a byte array and r.return() sends it verbatim, matching the CRC exactly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
22 lines
701 B
JavaScript
22 lines
701 B
JavaScript
// Decode a Base64 encoded string received as a query parameter named 'value',
|
|
// and return the decoded value in the response body.
|
|
function decodeBase64(r) {
|
|
var encodedValue = r.args.value;
|
|
|
|
if (!encodedValue) {
|
|
r.return(400, "Missing 'value' query parameter");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Use Buffer to return raw bytes — atob() returns a JS string which r.return()
|
|
// would re-encode as UTF-8, corrupting any non-ASCII bytes (e.g. in filenames
|
|
// like "Pokémon") and causing CRC mismatches in the mod_zip manifest.
|
|
r.return(200, Buffer.from(encodedValue, 'base64'));
|
|
} catch (e) {
|
|
r.return(400, "Invalid Base64 encoding");
|
|
}
|
|
}
|
|
|
|
export default { decodeBase64 };
|