perf: use undici instead of axios

This commit is contained in:
Starcea 2024-11-02 14:00:41 +09:00
commit 5a15d50cfc
No known key found for this signature in database
GPG key ID: B7A77E32374911E1
5 changed files with 59 additions and 97 deletions

View file

@ -1,6 +1,6 @@
import type { AxiosInstance } from 'axios'
import { decode } from 'iconv-lite'
import { RegExes } from './constants'
import type HTTP from './http'
interface Data {
mainRoute: string
@ -18,13 +18,11 @@ export default class DataManager {
private _lastFetchDate = 0
constructor(private readonly rest: AxiosInstance) {}
constructor(private readonly http: HTTP) {}
private async fetchData(): Promise<Data> {
const res = await this.rest.get('/st', {
responseType: 'arraybuffer',
})
const data = decode(Buffer.from(res.data), 'euc-kr')
const res = await this.http.get('/st').then((res) => res.body.arrayBuffer())
const data = decode(Buffer.from(res), 'euc-kr')
const main = RegExes.MainRoute.exec(data)
if (!main) throw new Error('Failed to fetch main route')