Skip to content

Commit d4b6041

Browse files
committed
[ADD] Lametric without cache
1 parent 9c304de commit d4b6041

17 files changed

+379
-5
lines changed

src/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { MinecraftModule } from './minecraft/minecraft.module';
55
import { SourceModule } from './source/source.module';
66
import { FivemModule } from './fivem/fivem.module';
77
import { LoggerMiddleware } from 'src/middleware/logger.middleware';
8+
import { LametricModule } from './lametric/lametric.module';
89

910
@Module({
10-
imports: [MinecraftModule, SourceModule, FivemModule],
11+
imports: [MinecraftModule, SourceModule, FivemModule, LametricModule],
1112
controllers: [AppController],
1213
providers: [AppService],
1314
})

src/fivem/fivem.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CacheModule } from '@nestjs/cache-manager';
66
@Module({
77
imports: [CacheModule.register()],
88
controllers: [FivemController],
9-
providers: [FivemService]
9+
providers: [FivemService],
10+
exports: [FivemService]
1011
})
1112
export class FivemModule {}

src/lametric/dto/lametricFrameDto.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ApiProperty, getSchemaPath } from "@nestjs/swagger";
2+
import FrameGoalDto from "./lametricFrameGoalDto";
3+
import FrameSparklineDto from "./lametricFrameSparklineDto";
4+
import FrameTextDto from "./lametricFrameTextDto";
5+
6+
export default class LametricFrameDto {
7+
@ApiProperty({
8+
description: "Frames to display on the LaMetric device",
9+
type: 'array',
10+
items: { oneOf: [
11+
{ $ref: getSchemaPath(FrameTextDto) },
12+
{ $ref: getSchemaPath(FrameGoalDto) },
13+
{ $ref: getSchemaPath(FrameSparklineDto) }
14+
]}
15+
})
16+
frames: (FrameTextDto | FrameGoalDto | FrameSparklineDto)[];
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
import GoalData from "./lametricGoalData";
3+
4+
export default class LametricFrameGoalDto {
5+
constructor(goalData: GoalData, icon: string) {
6+
this.goalData = goalData;
7+
this.icon = icon;
8+
}
9+
10+
@ApiProperty({
11+
description: "Goal data",
12+
type: GoalData
13+
})
14+
goalData: GoalData;
15+
16+
@ApiProperty({
17+
description: "Icon to display",
18+
example: "7285"
19+
})
20+
icon: string;
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
3+
export default class LametricFrameSparklineDto {
4+
constructor(index: number, chartData: number[]) {
5+
this.index = index;
6+
this.chartData = chartData;
7+
}
8+
9+
@ApiProperty({
10+
description: "Chart index",
11+
example: 0
12+
})
13+
index: number;
14+
15+
@ApiProperty({
16+
description: "Chart data",
17+
example: [1, 2, 3, 4, 5]
18+
})
19+
chartData: number[];
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
3+
export default class LametricFrameTextDto {
4+
constructor(text: string, icon: string) {
5+
this.text = text;
6+
this.icon = icon;
7+
}
8+
9+
@ApiProperty({
10+
description: "Text to display",
11+
example: "Hypixel"
12+
})
13+
text: string;
14+
15+
@ApiProperty({
16+
description: "Icon to display",
17+
example: "7285"
18+
})
19+
icon: string;
20+
}

src/lametric/dto/lametricGoalData.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
3+
export default class LametricGoalData {
4+
constructor(current: number, start: number, end: number, unit: string, duration: number, progress: number, direction: string) {
5+
this.current = current;
6+
this.start = start;
7+
this.end = end;
8+
this.unit = unit;
9+
}
10+
11+
@ApiProperty({
12+
description: "Current value",
13+
example: 100
14+
})
15+
current: number;
16+
17+
@ApiProperty({
18+
description: "Start value",
19+
example: 0
20+
})
21+
start: number;
22+
23+
@ApiProperty({
24+
description: "End value",
25+
example: 100
26+
})
27+
end: number;
28+
29+
@ApiProperty({
30+
description: "Unit",
31+
example: "players"
32+
})
33+
unit: string;
34+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
3+
import { LametricServerTypeParams } from 'src/utils/enums';
4+
5+
export default class LametricServerCheckedDto {
6+
@ApiProperty({
7+
description: 'Name of game server',
8+
example: 'Hypixel',
9+
})
10+
@IsNotEmpty()
11+
@IsString()
12+
name: string;
13+
14+
@ApiProperty({
15+
description: 'Type of game server',
16+
example: LametricServerTypeParams.Minecraft,
17+
enum: [
18+
LametricServerTypeParams.Minecraft,
19+
LametricServerTypeParams.MinecraftBedrock,
20+
LametricServerTypeParams.Source,
21+
LametricServerTypeParams.FiveM,
22+
LametricServerTypeParams.FiveMByCfxCode,
23+
],
24+
})
25+
@IsNotEmpty()
26+
@IsString()
27+
@IsEnum(LametricServerTypeParams)
28+
type: LametricServerTypeParams;
29+
30+
@ApiProperty({
31+
description: "Server's address",
32+
example: 'mc.hypixel.net',
33+
})
34+
@IsNotEmpty()
35+
@IsString()
36+
address: string;
37+
38+
@ApiProperty({
39+
description: 'Enable sparkline',
40+
enum: ['true', 'false'],
41+
})
42+
@IsOptional()
43+
@IsString()
44+
sparkline: string = 'false';
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ArgumentsHost, BadRequestException, Catch, Logger } from "@nestjs/common";
2+
import LametricFrameTextDto from "../dto/lametricFrameTextDto";
3+
4+
@Catch(BadRequestException)
5+
export default class LametricRequestIncompleteFilter {
6+
catch(exception: BadRequestException, host: ArgumentsHost) {
7+
Logger.warn("The request is incomplete, default response is sent.", exception.getResponse(), "RequestIncompleteFilter");
8+
const response = host.switchToHttp().getResponse();
9+
response.status(200)
10+
.json({
11+
"frames": [
12+
new LametricFrameTextDto("Please fill all fields in Lametric app.", "555")
13+
]
14+
});
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { LametricController } from './lametric.controller';
3+
4+
describe('LametricController', () => {
5+
let controller: LametricController;
6+
7+
beforeEach(async () => {
8+
const module: TestingModule = await Test.createTestingModule({
9+
controllers: [LametricController],
10+
}).compile();
11+
12+
controller = module.get<LametricController>(LametricController);
13+
});
14+
15+
it('should be defined', () => {
16+
expect(controller).toBeDefined();
17+
});
18+
});

0 commit comments

Comments
 (0)