|
1 | 1 | import { Request, Response } from 'express'; |
2 | 2 | import rateLimit from 'express-rate-limit'; |
3 | 3 | import { inject } from 'inversify'; |
4 | | -import { controller, httpGet, httpPost, httpPut } from 'inversify-express-utils'; |
| 4 | +import { controller, httpGet, httpPost, httpPut, httpHead } from 'inversify-express-utils'; |
5 | 5 | import fetch from 'node-fetch'; |
6 | 6 | import { v4 } from 'uuid'; |
7 | 7 | import { AuthenticatedRequest, LoggedCheck } from '../middlewares/LoggedCheck'; |
@@ -443,6 +443,34 @@ export class Games { |
443 | 443 | handleError(res, error, 'Error downloading game'); |
444 | 444 | } |
445 | 445 | } |
| 446 | + |
| 447 | + @httpHead('/:gameId') |
| 448 | + public async headGame(req: Request, res: Response) { |
| 449 | + if (!(await validateOr400(gameIdParamSchema, req.params, res))) { |
| 450 | + await this.createLog(req, 'headGame', 'games', 400); |
| 451 | + return; |
| 452 | + } |
| 453 | + try { |
| 454 | + const { gameId } = req.params; |
| 455 | + const game = await this.gameService.getGame(gameId); |
| 456 | + if (!game) { |
| 457 | + await this.createLog(req, 'headGame', 'games', 404); |
| 458 | + return res.status(404).send({ message: 'Game not found' }); |
| 459 | + } |
| 460 | + |
| 461 | + const headers = { |
| 462 | + 'Content-Type': 'application/json', |
| 463 | + 'ETag': generateETag(Buffer.from(JSON.stringify(game))), |
| 464 | + }; |
| 465 | + |
| 466 | + res.set(headers); |
| 467 | + await this.createLog(req, 'headGame', 'games', 200); |
| 468 | + res.status(200).end(); |
| 469 | + } catch (error) { |
| 470 | + await this.createLog(req, 'headGame', 'games', 500); |
| 471 | + handleError(res, error, 'Error fetching game headers'); |
| 472 | + } |
| 473 | + } |
446 | 474 | } |
447 | 475 |
|
448 | 476 |
|
0 commit comments