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

Commit 90e02c1

Browse files
committed
feat(games): add HEAD endpoint for game metadata retrieval
1 parent 94dc5cc commit 90e02c1

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/controllers/GameController.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Request, Response } from 'express';
22
import rateLimit from 'express-rate-limit';
33
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';
55
import fetch from 'node-fetch';
66
import { v4 } from 'uuid';
77
import { AuthenticatedRequest, LoggedCheck } from '../middlewares/LoggedCheck';
@@ -443,6 +443,34 @@ export class Games {
443443
handleError(res, error, 'Error downloading game');
444444
}
445445
}
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+
}
446474
}
447475

448476

0 commit comments

Comments
 (0)