Skip to content

Commit f725afd

Browse files
committed
Add undici redirect handling
1 parent 1917bfc commit f725afd

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/utils/download.mts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
rmSync,
88
} from "fs";
99
import { mkdir } from "fs/promises";
10-
import { arch, homedir, tmpdir } from "os";
10+
import { homedir, tmpdir } from "os";
1111
import { basename, dirname, join } from "path";
1212
import { join as joinPosix } from "path/posix";
1313
import Logger, { LoggerSource } from "../logger.mjs";
@@ -235,12 +235,24 @@ export async function downloadAndInstallArchive(
235235
let isSuccess = false;
236236

237237
if (process.platform !== "linux" || process.arch !== "arm64") {
238-
isSuccess = await downloadFileUndici(
238+
const undiciRet = await downloadFileUndici(
239239
client,
240240
downloadUrl,
241241
archiveFilePath,
242242
logName
243243
);
244+
if (typeof undiciRet === "string") {
245+
return downloadAndInstallArchive(
246+
url,
247+
targetDirectory,
248+
archiveFileName,
249+
logName,
250+
extraCallback,
251+
undiciRet,
252+
extraHeaders
253+
)
254+
}
255+
isSuccess = undiciRet;
244256
} else {
245257
isSuccess = await downloadFileGot(
246258
downloadUrl,
@@ -292,8 +304,8 @@ async function downloadFileUndici(
292304
downloadUrl: URL,
293305
archiveFilePath: string,
294306
logName: string
295-
): Promise<boolean> {
296-
return new Promise<boolean>((resolve, reject) => {
307+
): Promise<boolean | string> {
308+
return new Promise<boolean | string>((resolve, reject) => {
297309
const requestOptions: Dispatcher.RequestOptions = {
298310
path: downloadUrl.pathname + downloadUrl.search,
299311
method: "GET",
@@ -329,7 +341,9 @@ async function downloadFileUndici(
329341
LoggerSource.downloader,
330342
`Redirecting to ${headers.location.toString()}`
331343
);
332-
resolve(false); // Handle redirects in the calling function
344+
resolve(
345+
headers.location.toString()
346+
); // Handle redirects in the calling function
333347
}
334348

335349
return writeStream; // Return the Writable stream where data is piped

0 commit comments

Comments
 (0)