mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
1.1.1
Фикс невозможности парсинга субботы. class-validator.interceptor.ts - Добавлена возможность возвращать клиенту любой DTO из списка. Добавлен разный ответ клиенту в зависимости от его версии.
This commit is contained in:
@@ -107,11 +107,16 @@ export class ScheduleParser {
|
||||
++row;
|
||||
}
|
||||
|
||||
const dayMonthIdx = /[А-Яа-я]+\s(\d+)\.\d+\.\d+/.exec(
|
||||
trimAll(dayName),
|
||||
);
|
||||
if (
|
||||
days.length == 0 ||
|
||||
!days[days.length - 1].name.startsWith("Суббота")
|
||||
) {
|
||||
const dayMonthIdx = /[А-Яа-я]+\s(\d+)\.\d+\.\d+/.exec(
|
||||
trimAll(dayName),
|
||||
);
|
||||
|
||||
if (dayMonthIdx === null) continue;
|
||||
if (dayMonthIdx === null) continue;
|
||||
}
|
||||
|
||||
days.push({
|
||||
row: row,
|
||||
|
||||
@@ -11,6 +11,8 @@ import { AuthGuard } from "../auth/auth.guard";
|
||||
import { ScheduleService } from "./schedule.service";
|
||||
import {
|
||||
CacheStatusDto,
|
||||
CacheStatusV0Dto,
|
||||
CacheStatusV1Dto,
|
||||
GroupScheduleDto,
|
||||
GroupScheduleRequestDto,
|
||||
ScheduleDto,
|
||||
@@ -26,6 +28,7 @@ import {
|
||||
ApiOperation,
|
||||
refs,
|
||||
} from "@nestjs/swagger";
|
||||
import { ClientVersion } from "../version/client-version.decorator";
|
||||
|
||||
@Controller("api/v1/schedule")
|
||||
@UseGuards(AuthGuard)
|
||||
@@ -82,34 +85,59 @@ export class ScheduleController {
|
||||
}
|
||||
|
||||
@ApiExtraModels(SiteMainPageDto)
|
||||
@ApiExtraModels(CacheStatusDto)
|
||||
@ApiExtraModels(CacheStatusV0Dto)
|
||||
@ApiExtraModels(CacheStatusV1Dto)
|
||||
@ApiOperation({
|
||||
summary: "Обновление данных основной страницы политехникума",
|
||||
tags: ["schedule"],
|
||||
})
|
||||
@ApiOkResponse({ description: "Данные обновлены успешно" })
|
||||
@ApiOkResponse({
|
||||
description: "Данные обновлены успешно",
|
||||
schema: refs(CacheStatusV0Dto)[0],
|
||||
})
|
||||
@ApiOkResponse({
|
||||
description: "Данные обновлены успешно",
|
||||
schema: refs(CacheStatusV0Dto)[1],
|
||||
})
|
||||
@ApiNotAcceptableResponse({
|
||||
description: "Передан некорректный код страницы",
|
||||
})
|
||||
@ResultDto(CacheStatusDto)
|
||||
@ResultDto([CacheStatusV0Dto, CacheStatusV1Dto])
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post("update-site-main-page")
|
||||
async updateSiteMainPage(
|
||||
@Body() siteMainPageDto: SiteMainPageDto,
|
||||
): Promise<CacheStatusDto> {
|
||||
return await this.scheduleService.updateSiteMainPage(siteMainPageDto);
|
||||
@ClientVersion() version: number,
|
||||
): Promise<CacheStatusV0Dto> {
|
||||
return CacheStatusDto.stripVersion(
|
||||
await this.scheduleService.updateSiteMainPage(siteMainPageDto),
|
||||
version,
|
||||
);
|
||||
}
|
||||
|
||||
@ApiExtraModels(CacheStatusDto)
|
||||
@ApiExtraModels(CacheStatusV0Dto)
|
||||
@ApiExtraModels(CacheStatusV1Dto)
|
||||
@ApiOperation({
|
||||
summary: "Получение информации о кеше",
|
||||
tags: ["schedule", "cache"],
|
||||
})
|
||||
@ApiOkResponse({ description: "Получение данных прошло успешно" })
|
||||
@ResultDto(CacheStatusDto)
|
||||
@ApiOkResponse({
|
||||
description: "Получение данных прошло успешно",
|
||||
schema: refs(CacheStatusV0Dto)[0],
|
||||
})
|
||||
@ApiOkResponse({
|
||||
description: "Получение данных прошло успешно",
|
||||
schema: refs(CacheStatusV1Dto)[0],
|
||||
})
|
||||
@ResultDto([CacheStatusV0Dto, CacheStatusV1Dto])
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Get("cache-status")
|
||||
getCacheStatus(): CacheStatusDto {
|
||||
return this.scheduleService.getCacheStatus();
|
||||
getCacheStatus(
|
||||
@ClientVersion() version: number,
|
||||
): CacheStatusV0Dto | CacheStatusV1Dto {
|
||||
return CacheStatusDto.stripVersion(
|
||||
this.scheduleService.getCacheStatus(),
|
||||
version,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ export class ScheduleService {
|
||||
private cacheHash: string = "0000000000000000000000000000000000000000";
|
||||
|
||||
private lastChangedDays: Array<Array<number>> = [];
|
||||
private scheduleUpdatedAt: Date = new Date(0);
|
||||
|
||||
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {}
|
||||
|
||||
@@ -39,6 +40,8 @@ export class ScheduleService {
|
||||
cacheHash: this.cacheHash,
|
||||
cacheUpdateRequired:
|
||||
(Date.now() - this.cacheUpdatedAt.valueOf()) / 1000 / 60 >= 5,
|
||||
lastCacheUpdate: this.cacheUpdatedAt.valueOf(),
|
||||
lastScheduleUpdate: this.scheduleUpdatedAt.valueOf(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,11 +53,21 @@ export class ScheduleService {
|
||||
) as Array<GroupDto>;
|
||||
|
||||
this.cacheUpdatedAt = new Date();
|
||||
|
||||
const oldHash = this.cacheHash;
|
||||
this.cacheHash = crypto
|
||||
.createHash("sha1")
|
||||
.update(schedule.etag)
|
||||
.update(
|
||||
JSON.stringify(schedule.groups, null, 0) + schedule.etag,
|
||||
)
|
||||
.digest("hex");
|
||||
|
||||
if (
|
||||
this.scheduleUpdatedAt.valueOf() === 0 ||
|
||||
this.cacheHash !== oldHash
|
||||
)
|
||||
this.scheduleUpdatedAt = new Date();
|
||||
|
||||
return schedule;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user