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-----",
|
"-----END PUBLIC KEY-----",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const axiosConstants = {
|
||||||
|
userAgent: process.env.USER_AGENT,
|
||||||
|
};
|
||||||
|
|
||||||
export const jwtConstants = {
|
export const jwtConstants = {
|
||||||
secret: process.env.JWT_SECRET,
|
secret: process.env.JWT_SECRET,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
NotAcceptableException,
|
NotAcceptableException,
|
||||||
ServiceUnavailableException,
|
ServiceUnavailableException,
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
|
import { axiosConstants } from "../../../contants";
|
||||||
|
|
||||||
export class BasicXlsDownloader implements XlsDownloaderInterface {
|
export class BasicXlsDownloader implements XlsDownloaderInterface {
|
||||||
private url: string | null = null;
|
private url: string | null = null;
|
||||||
@@ -35,9 +36,16 @@ export class BasicXlsDownloader implements XlsDownloaderInterface {
|
|||||||
url: string,
|
url: string,
|
||||||
head: boolean,
|
head: boolean,
|
||||||
): Promise<FetchResult> {
|
): Promise<FetchResult> {
|
||||||
|
const requestHeaders = {
|
||||||
|
"User-Agent": axiosConstants.userAgent,
|
||||||
|
};
|
||||||
|
|
||||||
const response = await (head
|
const response = await (head
|
||||||
? axios.head(url)
|
? axios.head(url, { headers: requestHeaders })
|
||||||
: axios.get(url, { responseType: "arraybuffer" }));
|
: axios.get(url, {
|
||||||
|
responseType: "arraybuffer",
|
||||||
|
headers: requestHeaders,
|
||||||
|
}));
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
console.error(`${response.status} ${response.statusText}`);
|
console.error(`${response.status} ${response.statusText}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user