diff --git a/src/store/apiStore.ts b/src/store/apiStore.ts index 9b0d483..59bac2e 100644 --- a/src/store/apiStore.ts +++ b/src/store/apiStore.ts @@ -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 diff --git a/src/store/utils.ts b/src/store/utils.ts index 8744e10..2ebf1b6 100644 --- a/src/store/utils.ts +++ b/src/store/utils.ts @@ -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); +}