mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-04 13:58:12 +00:00
chore(api): added randomizing fetching static data from API
This commit is contained in:
+11
-1
@@ -3,6 +3,7 @@ import { API } from '../typings/api';
|
||||
import { Status } from '../typings/common';
|
||||
import { StationJSONData } from './typings';
|
||||
import { HttpClient } from '../http';
|
||||
import { getRandomDurationFromRange } from './utils';
|
||||
|
||||
let baseURL = 'https://stacjownik.spythere.eu';
|
||||
|
||||
@@ -61,7 +62,16 @@ export const useApiStore = defineStore('apiStore', {
|
||||
this.fetchDonatorsData()
|
||||
]);
|
||||
|
||||
this.nextDataCheckTime = t + 3600000;
|
||||
if (this.nextDataCheckTime == 0) {
|
||||
this.nextDataCheckTime = getRandomDurationFromRange(5000, 7500);
|
||||
} else {
|
||||
this.nextDataCheckTime = getRandomDurationFromRange(600000, 720000);
|
||||
}
|
||||
|
||||
console.log(
|
||||
'Next data check at:',
|
||||
new Date(Date.now() + this.nextDataCheckTime).toLocaleTimeString()
|
||||
);
|
||||
}
|
||||
|
||||
// Active data fefresh
|
||||
|
||||
@@ -48,3 +48,7 @@ export function parseSpawns(spawnString: string | null): ScenerySpawn[] {
|
||||
export function getTimestamp(date: string | null): number {
|
||||
return date ? new Date(date).getTime() : 0;
|
||||
}
|
||||
|
||||
export function getRandomDurationFromRange(minDuration = 0, maxDuration: number) {
|
||||
return Math.round(Math.random() * (maxDuration - minDuration) + minDuration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user