fixed scripts and replaced consts
This commit is contained in:
@@ -4,10 +4,11 @@ import contentTypeParser from 'content-type'
|
||||
import { JSDOM } from 'jsdom'
|
||||
// import { content as mockContent } from './mock'
|
||||
import { reportParserError } from '@/app/logger'
|
||||
import { PROXY_URL } from '@/shared/constants/urls'
|
||||
|
||||
// ПС-7: 146
|
||||
export async function getSchedule(groupID: number, groupName: string): Promise<Day[]> {
|
||||
const page = await fetch(`${process.env.PROXY_URL ?? 'https://lk.ks.psuti.ru'}/?mn=2&obj=${groupID}`)
|
||||
const page = await fetch(`${PROXY_URL}/?mn=2&obj=${groupID}`)
|
||||
// const page = { text: async () => mockContent, status: 200, headers: { get: (s: string) => s && 'text/html' } }
|
||||
const content = await page.text()
|
||||
const contentType = page.headers.get('content-type')
|
||||
@@ -16,7 +17,7 @@ export async function getSchedule(groupID: number, groupName: string): Promise<D
|
||||
const root = new JSDOM(content).window.document
|
||||
return parsePage(root, groupName)
|
||||
} catch(e) {
|
||||
console.error('Error while parsing lk.ks.psuti.ru')
|
||||
console.error(`Error while parsing ${PROXY_URL}`)
|
||||
reportParserError(new Date().toISOString(), 'Не удалось сделать парсинг для группы', groupName)
|
||||
throw e
|
||||
}
|
||||
@@ -24,6 +25,6 @@ export async function getSchedule(groupID: number, groupName: string): Promise<D
|
||||
console.error(page.status, contentType)
|
||||
console.error(content.length > 500 ? content.slice(0, 500 - 3) + '...' : content)
|
||||
reportParserError(new Date().toISOString(), 'Не удалось получить страницу для группы', groupName)
|
||||
throw new Error('Error while fetching lk.ks.psuti.ru')
|
||||
throw new Error(`Error while fetching ${PROXY_URL}`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user