Skip to content

Commit 134efa1

Browse files
committed
speedlimit
1 parent 59956ab commit 134efa1

4 files changed

Lines changed: 26 additions & 21 deletions

File tree

src/modules/games/games.controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ export class GamesController {
299299
): Promise<StreamableFile> {
300300
response.setHeader(
301301
"X-Otp",
302-
this.otpService.create(request.user.username, Number(params.game_id)),
302+
this.otpService.create(
303+
request.user.username,
304+
Number(params.game_id),
305+
Number(speedlimit),
306+
),
303307
);
304308
return this.filesService.download(
305309
response,
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
export default class Otp {
22
otp: string;
33
username: string;
4-
gameId?: number;
54
createdAt: Date = new Date();
65
expiresAt: Date = new Date(Date.now() + 5 * 60 * 1000); // 5 Minutes
6+
gameId?: number;
7+
xDownloadSpeedLimit?: number;
78

8-
constructor(otp: string, username: string, gameId?: number) {
9+
constructor(
10+
otp: string,
11+
username: string,
12+
gameId?: number,
13+
xDownloadSpeedLimit?: number,
14+
) {
915
this.otp = otp;
16+
this.username = username;
1017
this.gameId = gameId;
18+
this.xDownloadSpeedLimit = xDownloadSpeedLimit;
1119
}
1220

1321
getLoggableData() {
1422
return {
1523
otp: "**REDACTED**",
1624
username: this.username,
17-
gameId: this.gameId,
1825
createdAt: this.createdAt,
1926
expiresAt: this.expiresAt,
27+
gameId: this.gameId,
28+
xDownloadSpeedLimit: this.xDownloadSpeedLimit,
2029
};
2130
}
2231
}

src/modules/otp/otp.controller.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ export class OtpController {
2222
constructor(private readonly otpService: OtpService) {}
2323

2424
@Get("game")
25-
@ApiHeader({
26-
name: "X-Download-Speed-Limit",
27-
required: false,
28-
description:
29-
"This header lets you set the maximum download speed limit in kibibytes per second (kiB/s) for your request. If the header is not present the download speed limit will be unlimited.",
30-
example: "1024",
31-
})
3225
@ApiOkResponse({ type: () => StreamableFile })
3326
@ApiOperation({
3427
summary: "returns a game download for the otp",
@@ -38,8 +31,7 @@ export class OtpController {
3831
async getOtpGame(
3932
@Query("otp") otp: string,
4033
@Res({ passthrough: true }) response: Response,
41-
@Headers("X-Download-Speed-Limit") speedlimit?: string,
4234
): Promise<StreamableFile> {
43-
return this.otpService.get(otp, response, speedlimit);
35+
return this.otpService.get(otp, response);
4436
}
4537
}

src/modules/otp/otp.service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ export class OtpService {
2727
});
2828
}
2929

30-
public create(username: string, gameId?: number): string {
30+
public create(
31+
username: string,
32+
gameId?: number,
33+
xDownloadSpeedLimit?: number,
34+
): string {
3135
const randomOtp = randomBytes(64).toString("hex");
32-
const otp = new Otp(randomOtp, username, gameId);
36+
const otp = new Otp(randomOtp, username, gameId, xDownloadSpeedLimit);
3337
this.otps.set(randomOtp, otp);
3438
this.logger.log("OTP Created.", otp.getLoggableData());
3539
return randomOtp;
3640
}
3741

38-
async get(
39-
otp: string,
40-
response: Response,
41-
speedlimit?: string,
42-
): Promise<StreamableFile> {
42+
async get(otp: string, response: Response): Promise<StreamableFile> {
4343
const existingOtp = this.otps.get(otp);
4444
if (!existingOtp) {
4545
throw new UnauthorizedException("Invalid OTP");
@@ -52,7 +52,7 @@ export class OtpService {
5252
return this.filesService.download(
5353
response,
5454
existingOtp.gameId,
55-
Number(speedlimit),
55+
existingOtp.xDownloadSpeedLimit,
5656
);
5757
}
5858
}

0 commit comments

Comments
 (0)