Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit e74bab3

Browse files
committed
fix(download): simplify file download handling and improve response headers
1 parent 8daa94e commit e74bab3

1 file changed

Lines changed: 7 additions & 30 deletions

File tree

src/controllers/GameController.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -407,38 +407,15 @@ export class Games {
407407
return res.status(404).send({ message: 'Download link not available' });
408408
}
409409

410-
const headers: any = {};
411-
if (req.headers.range) {
412-
headers.Range = req.headers.range;
413-
}
414-
415-
const fileRes = await fetch(link, { headers });
416-
if (!fileRes.ok) {
417-
return res.status(fileRes.status).send({ message: 'Error fetching file' });
418-
}
410+
// Optionally, generate a signed URL if the source supports it
411+
// const signedLink = await this.generateSignedUrl(link);
419412

413+
// Redirect the client to the source link
420414
res.setHeader('Content-Disposition', `attachment; filename="${game.name}.zip"`);
421-
res.setHeader('Content-Type', fileRes.headers.get('content-type') || 'application/octet-stream');
422-
423-
const contentLength = fileRes.headers.get('content-length');
424-
if (contentLength !== null) {
425-
res.setHeader('Content-Length', contentLength);
426-
}
427-
const acceptRanges = fileRes.headers.get('accept-ranges');
428-
if (acceptRanges !== null) {
429-
res.setHeader('Accept-Ranges', acceptRanges);
430-
}
431-
const contentRange = fileRes.headers.get('content-range');
432-
if (contentRange !== null) {
433-
res.setHeader('Content-Range', contentRange);
434-
}
435-
436-
res.status(fileRes.status);
437-
if (fileRes.body) {
438-
fileRes.body.pipe(res);
439-
} else {
440-
res.end();
441-
}
415+
res.setHeader('Content-Type', 'application/octet-stream');
416+
res.setHeader('Cache-Control', 'no-cache');
417+
res.status(302).setHeader('Location', link); // Use signedLink if generated
418+
res.end();
442419
} catch (error) {
443420
handleError(res, error, 'Error downloading game');
444421
}

0 commit comments

Comments
 (0)