|
7 | 7 | rmSync, |
8 | 8 | } from "fs"; |
9 | 9 | import { mkdir } from "fs/promises"; |
10 | | -import { arch, homedir, tmpdir } from "os"; |
| 10 | +import { homedir, tmpdir } from "os"; |
11 | 11 | import { basename, dirname, join } from "path"; |
12 | 12 | import { join as joinPosix } from "path/posix"; |
13 | 13 | import Logger, { LoggerSource } from "../logger.mjs"; |
@@ -235,12 +235,24 @@ export async function downloadAndInstallArchive( |
235 | 235 | let isSuccess = false; |
236 | 236 |
|
237 | 237 | if (process.platform !== "linux" || process.arch !== "arm64") { |
238 | | - isSuccess = await downloadFileUndici( |
| 238 | + const undiciRet = await downloadFileUndici( |
239 | 239 | client, |
240 | 240 | downloadUrl, |
241 | 241 | archiveFilePath, |
242 | 242 | logName |
243 | 243 | ); |
| 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; |
244 | 256 | } else { |
245 | 257 | isSuccess = await downloadFileGot( |
246 | 258 | downloadUrl, |
@@ -292,8 +304,8 @@ async function downloadFileUndici( |
292 | 304 | downloadUrl: URL, |
293 | 305 | archiveFilePath: string, |
294 | 306 | logName: string |
295 | | -): Promise<boolean> { |
296 | | - return new Promise<boolean>((resolve, reject) => { |
| 307 | +): Promise<boolean | string> { |
| 308 | + return new Promise<boolean | string>((resolve, reject) => { |
297 | 309 | const requestOptions: Dispatcher.RequestOptions = { |
298 | 310 | path: downloadUrl.pathname + downloadUrl.search, |
299 | 311 | method: "GET", |
@@ -329,7 +341,9 @@ async function downloadFileUndici( |
329 | 341 | LoggerSource.downloader, |
330 | 342 | `Redirecting to ${headers.location.toString()}` |
331 | 343 | ); |
332 | | - resolve(false); // Handle redirects in the calling function |
| 344 | + resolve( |
| 345 | + headers.location.toString() |
| 346 | + ); // Handle redirects in the calling function |
333 | 347 | } |
334 | 348 |
|
335 | 349 | return writeStream; // Return the Writable stream where data is piped |
|
0 commit comments