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

Commit 706b474

Browse files
committed
fix(download): simplify download handling by redirecting to the game file URL
1 parent f143617 commit 706b474

1 file changed

Lines changed: 1 addition & 24 deletions

File tree

src/controllers/GameController.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Request, Response } from 'express';
22
import rateLimit from 'express-rate-limit';
33
import { inject } from 'inversify';
44
import { controller, httpGet, httpPost, httpPut } from 'inversify-express-utils';
5-
import fetch from 'node-fetch';
65
import { pipeline } from 'stream';
76
import { promisify } from 'util';
87
import { v4 } from 'uuid';
@@ -399,29 +398,7 @@ export class Games {
399398
const [_, owner, repo] = githubMatch;
400399
downloadUrl = `https://github.com/${owner}/${repo}/archive/refs/heads/main.zip`;
401400
}
402-
const headers: any = {};
403-
if (req.headers.range) {
404-
headers.Range = req.headers.range;
405-
}
406-
const fileRes = await fetch(downloadUrl, { headers });
407-
if (!fileRes.ok) return res.status(502).send({ message: 'Failed to fetch game file' });
408-
res.setHeader('Content-Disposition', `attachment; filename="${game.name}.zip"`);
409-
res.setHeader('Content-Type', fileRes.headers.get('content-type') || 'application/octet-stream');
410-
const contentLength = fileRes.headers.get('content-length');
411-
if (contentLength) res.setHeader('Content-Length', contentLength);
412-
const acceptRanges = fileRes.headers.get('accept-ranges');
413-
if (acceptRanges) res.setHeader('Accept-Ranges', acceptRanges);
414-
if (fileRes.headers.get('content-range')) res.setHeader('Content-Range', fileRes.headers.get('content-range')!);
415-
res.status(fileRes.status);
416-
if (fileRes.body) {
417-
try {
418-
await streamPipeline(fileRes.body, res);
419-
} catch (err) {
420-
res.status(500).send({ message: 'Error streaming the file.' });
421-
}
422-
} else {
423-
res.status(500).send({ message: 'Response body is empty.' });
424-
}
401+
res.redirect(downloadUrl);
425402
} catch (error) {
426403
handleError(res, error, 'Error downloading game');
427404
}

0 commit comments

Comments
 (0)