mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
Обход бана по IP за частые обращения к сайту политехникума за счёт скачивания кода страницы на стороне клиентов.
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { Inject, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import {
|
||||
Inject,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
ServiceUnavailableException,
|
||||
} from "@nestjs/common";
|
||||
import {
|
||||
ScheduleParser,
|
||||
ScheduleParseResult,
|
||||
@@ -10,6 +15,7 @@ import {
|
||||
GroupScheduleDto,
|
||||
ScheduleDto,
|
||||
ScheduleGroupsDto,
|
||||
SiteMainPageDto,
|
||||
} from "../dto/schedule.dto";
|
||||
import { Cache, CACHE_MANAGER } from "@nestjs/cache-manager";
|
||||
import { instanceToPlain } from "class-transformer";
|
||||
@@ -38,6 +44,11 @@ export class ScheduleService {
|
||||
schedule.groups,
|
||||
) as Array<GroupDto>;
|
||||
|
||||
if (schedule.updateRequired && schedule.etag.length === 0)
|
||||
throw new ServiceUnavailableException(
|
||||
"Отсутствует начальная ссылка на скачивание!",
|
||||
);
|
||||
|
||||
return schedule;
|
||||
});
|
||||
}
|
||||
@@ -66,6 +77,7 @@ export class ScheduleService {
|
||||
groups: ScheduleService.toObject(sourceSchedule.groups),
|
||||
etag: sourceSchedule.etag,
|
||||
lastChangedDays: this.lastChangedDays,
|
||||
updateRequired: sourceSchedule.updateRequired,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -84,6 +96,7 @@ export class ScheduleService {
|
||||
group: schedule.groups[group],
|
||||
etag: schedule.etag,
|
||||
lastChangedDays: this.lastChangedDays[group] ?? [],
|
||||
updateRequired: schedule.updateRequired,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -107,4 +120,12 @@ export class ScheduleService {
|
||||
|
||||
return groupNames;
|
||||
}
|
||||
|
||||
async updateSiteMainPage(siteMainPageDto: SiteMainPageDto): Promise<void> {
|
||||
await this.scheduleParser
|
||||
.getXlsDownloader()
|
||||
.setPreparedData(siteMainPageDto.mainPage);
|
||||
|
||||
await this.cacheManager.reset();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user