@@ -2,7 +2,6 @@ import { Request, Response } from 'express';
22import rateLimit from 'express-rate-limit' ;
33import { inject } from 'inversify' ;
44import { controller , httpGet , httpPost , httpPut } from 'inversify-express-utils' ;
5- import fetch from 'node-fetch' ;
65import { pipeline } from 'stream' ;
76import { promisify } from 'util' ;
87import { 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