chore(api): added randomizing fetching static data from API

This commit is contained in:
2026-05-04 15:06:57 +02:00
parent d8d8a00fd9
commit 328a5d4174
2 changed files with 15 additions and 1 deletions
+11 -1
View File
@@ -3,6 +3,7 @@ import { API } from '../typings/api';
import { Status } from '../typings/common'; import { Status } from '../typings/common';
import { StationJSONData } from './typings'; import { StationJSONData } from './typings';
import { HttpClient } from '../http'; import { HttpClient } from '../http';
import { getRandomDurationFromRange } from './utils';
let baseURL = 'https://stacjownik.spythere.eu'; let baseURL = 'https://stacjownik.spythere.eu';
@@ -61,7 +62,16 @@ export const useApiStore = defineStore('apiStore', {
this.fetchDonatorsData() 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 // Active data fefresh
+4
View File
@@ -48,3 +48,7 @@ export function parseSpawns(spawnString: string | null): ScenerySpawn[] {
export function getTimestamp(date: string | null): number { export function getTimestamp(date: string | null): number {
return date ? new Date(date).getTime() : 0; return date ? new Date(date).getTime() : 0;
} }
export function getRandomDurationFromRange(minDuration = 0, maxDuration: number) {
return Math.round(Math.random() * (maxDuration - minDuration) + minDuration);
}