diff --git a/package-lock.json b/package-lock.json index 3225cc0..4289cbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "pino": "^9.9.1", "pino-http": "^10.5.0", "pino-pretty": "^13.1.1", + "undici": "^7.16.0", "xml-js": "^1.6.11", "xmlbuilder": "^15.1.1" }, @@ -9488,6 +9489,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.16.0.tgz", + "integrity": "sha512-QEg3HPMll0o3t2ourKwOeUAZ159Kn9mx5pnzHRQO8+Wixmh88YdZRiIwat0iNzNNXn0yoEtXJqFpyW7eM8BV7g==", + "license": "MIT", + "engines": { + "node": ">=20.18.1" + } + }, "node_modules/undici-types": { "version": "6.20.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", @@ -16276,6 +16286,11 @@ "which-boxed-primitive": "^1.1.1" } }, + "undici": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.16.0.tgz", + "integrity": "sha512-QEg3HPMll0o3t2ourKwOeUAZ159Kn9mx5pnzHRQO8+Wixmh88YdZRiIwat0iNzNNXn0yoEtXJqFpyW7eM8BV7g==" + }, "undici-types": { "version": "6.20.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", diff --git a/package.json b/package.json index 33344d2..f95f07a 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "pino": "^9.9.1", "pino-http": "^10.5.0", "pino-pretty": "^13.1.1", + "undici": "^7.16.0", "xml-js": "^1.6.11", "xmlbuilder": "^15.1.1" }, diff --git a/src/cli/files.cmd.ts b/src/cli/files.cmd.ts index 4c3131e..0dd73b7 100644 --- a/src/cli/files.cmd.ts +++ b/src/cli/files.cmd.ts @@ -1,6 +1,7 @@ import fs from 'node:fs/promises'; import { pipeline } from 'node:stream/promises'; import { Readable } from 'node:stream'; +import { request } from 'undici'; import { Command } from 'commander'; import { decryptWiiU } from '@pretendonetwork/boss-crypto'; import { getCliContext } from './utils'; @@ -76,18 +77,22 @@ const downloadCmd = new Command('download') } const npdi = ctx.getNpdiUrl(); - const fetchResult = await fetch(`${npdi.url}/p01/data/1/${file.bossAppId}/${file.dataId}/${file.hash}`, { + const { body, statusCode } = await request(`${npdi.url}/p01/data/1/${file.bossAppId}/${file.dataId}/${file.hash}`, { headers: { Host: npdi.host } }); - if (fetchResult.status > 299) { - console.error(`Failed to download: invalid status code (${fetchResult.status})`); + if (statusCode > 299) { + console.error(`Failed to download: invalid status code (${statusCode})`); process.exit(1); } - const arrayBuffer = await fetchResult.arrayBuffer(); - let buffer = Buffer.from(arrayBuffer); + const chunks: Buffer[] = []; + for await (const chunk of body) { + chunks.push(Buffer.from(chunk)); + } + + let buffer: Buffer = Buffer.concat(chunks); if (ops.decrypt) { const keys = ctx.getWiiUKeys();