fix: fetch data when date changes

This commit is contained in:
Starcea 2024-06-28 15:29:33 +09:00
commit 27874fad37
No known key found for this signature in database
GPG key ID: B7A77E32374911E1

View file

@ -15,7 +15,7 @@ interface Data {
export default class DataManager { export default class DataManager {
private _data: Data | null = null private _data: Data | null = null
private _lastFetch = 0 private _lastFetchDate = 0
constructor(private readonly rest: AxiosInstance) {} constructor(private readonly rest: AxiosInstance) {}
@ -43,7 +43,7 @@ export default class DataManager {
const subject = RegExes.SubjectCode.exec(data) const subject = RegExes.SubjectCode.exec(data)
if (!subject) throw new Error('Failed to fetch subject code') if (!subject) throw new Error('Failed to fetch subject code')
this._lastFetch = Date.now() this._lastFetchDate = new Date().getDate()
this._data = { this._data = {
mainRoute: main[0], mainRoute: main[0],
searchRoute: search[0], searchRoute: search[0],
@ -56,7 +56,7 @@ export default class DataManager {
} }
async getData() { async getData() {
if (this._data && Date.now() - this._lastFetch < 1000 * 60 * 60) if (this._data && this._lastFetchDate === new Date().getDate())
return this._data return this._data
return this.fetchData() return this.fetchData()