mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
Обход бана со стороны сайта политехникума путём подмены User-Agent.
This commit is contained in:
@@ -23,6 +23,10 @@ export const vkIdConstants = {
|
||||
"-----END PUBLIC KEY-----",
|
||||
};
|
||||
|
||||
export const axiosConstants = {
|
||||
userAgent: process.env.USER_AGENT,
|
||||
};
|
||||
|
||||
export const jwtConstants = {
|
||||
secret: process.env.JWT_SECRET,
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
NotAcceptableException,
|
||||
ServiceUnavailableException,
|
||||
} from "@nestjs/common";
|
||||
import { axiosConstants } from "../../../contants";
|
||||
|
||||
export class BasicXlsDownloader implements XlsDownloaderInterface {
|
||||
private url: string | null = null;
|
||||
@@ -35,9 +36,16 @@ export class BasicXlsDownloader implements XlsDownloaderInterface {
|
||||
url: string,
|
||||
head: boolean,
|
||||
): Promise<FetchResult> {
|
||||
const requestHeaders = {
|
||||
"User-Agent": axiosConstants.userAgent,
|
||||
};
|
||||
|
||||
const response = await (head
|
||||
? axios.head(url)
|
||||
: axios.get(url, { responseType: "arraybuffer" }));
|
||||
? axios.head(url, { headers: requestHeaders })
|
||||
: axios.get(url, {
|
||||
responseType: "arraybuffer",
|
||||
headers: requestHeaders,
|
||||
}));
|
||||
|
||||
if (response.status !== 200) {
|
||||
console.error(`${response.status} ${response.statusText}`);
|
||||
|
||||
Reference in New Issue
Block a user