feat: use new db site, cache requests to avoid repeated unneeded fetch calls

This commit is contained in:
2026-06-18 23:20:12 -03:00
parent 9f5b8cd1fa
commit 6a064d295e
8 changed files with 64 additions and 35 deletions
+28
View File
@@ -0,0 +1,28 @@
export const DB_BASE_URL = 'https://dbd-db.neru.rip';
const _cache = new Map<string, Promise<any>>();
export function fetchDB<T = any>(path: string): Promise<T> {
if (!_cache.has(path)) {
_cache.set(
path,
fetch(`${DB_BASE_URL}${path}`)
.then(r => {
if (!r.ok) throw new Error(`[db] ${r.status} ${path}`);
return r.json();
})
.catch(err => {
_cache.delete(path);
console.error(err);
return [];
})
);
}
return _cache.get(path)!;
}
export const fetchCharacters = () => fetchDB('/data/characters.json');
export const fetchCustomizations = () => fetchDB('/data/customization_items.json');
export const fetchItems = () => fetchDB('/data/items.json');
export const fetchOfferings = () => fetchDB('/data/offerings.json');
export const fetchDLCs = () => fetchDB('/data/dlcs.json');