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

Commit c8293ca

Browse files
committed
fix(download): enhance game download handling with range support and improved response headers
1 parent 2e31240 commit c8293ca

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

src/controllers/GameController.ts

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

410-
// Return the download link directly
411-
res.status(200).send({
412-
downloadLink: link,
413-
});
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+
}
419+
420+
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+
}
414442
} catch (error) {
415-
handleError(res, error, 'Error fetching download link');
443+
handleError(res, error, 'Error downloading game');
416444
}
417445
}
418446
}

0 commit comments

Comments
 (0)