feat: add a Bhote Koshi flood event tool

This commit is contained in:
Sameh Khamis committed 2026-10-01 13:44:41 -07:00
1 parent a747b8a4e0
commit 0953ebb026
10 files changed
+243 -5

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
/** Event packs the app serves under `/events/<id>/`, read once per id. */
const EVENT_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
export function createEventPackSource({
fetchImpl = (...args) => globalThis.fetch(...args),
} = {}) {
const cache = new Map();
return {
async getEvent(id, { signal } = {}) {
if (!EVENT_ID.test(id)) throw new TypeError(`Invalid event id: ${id}`);
if (!cache.has(id)) {
signal?.throwIfAborted();
const response = await fetchImpl(`/events/${id}/event.json`, {
signal,
});
if (!response.ok)
throw new Error(`Event pack ${id} unavailable (${response.status})`);
cache.set(id, await response.json());
}
return cache.get(id);
},
};
}