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

Commit 4629b2a

Browse files
committed
fix(download): enhance game download validation and error handling
1 parent e74bab3 commit 4629b2a

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/controllers/GameController.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,30 +394,29 @@ export class Games {
394394
const { gameId } = req.params;
395395
const userId = req.user.user_id;
396396
try {
397+
// Vérifiez si le jeu existe
397398
const game = await this.gameService.getGame(gameId);
398399
if (!game) {
399400
return res.status(404).send({ message: 'Game not found' });
400401
}
402+
403+
// Vérifiez si l'utilisateur possède le jeu ou y a accès
401404
const owns = (await this.gameService.userOwnsGame(gameId, userId)) || game.owner_id === userId;
402405
if (!owns) {
403406
return res.status(403).send({ message: 'Access denied' });
404407
}
408+
409+
// Vérifiez si un lien de téléchargement est disponible
405410
const link = game.download_link;
406411
if (!link) {
407412
return res.status(404).send({ message: 'Download link not available' });
408413
}
409414

410-
// Optionally, generate a signed URL if the source supports it
411-
// const signedLink = await this.generateSignedUrl(link);
412-
413-
// Redirect the client to the source link
414-
res.setHeader('Content-Disposition', `attachment; filename="${game.name}.zip"`);
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
415+
// Effectuer une redirection pure vers le lien source
416+
res.status(302).setHeader('Location', link);
418417
res.end();
419418
} catch (error) {
420-
handleError(res, error, 'Error downloading game');
419+
handleError(res, error, 'Error processing download request');
421420
}
422421
}
423422
}

0 commit comments

Comments
 (0)