mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
21 lines
556 B
JavaScript
21 lines
556 B
JavaScript
export async function readJsonFromUpstash(key, timeoutMs = 3_000) {
|
|
const url = process.env.UPSTASH_REDIS_REST_URL;
|
|
const token = process.env.UPSTASH_REDIS_REST_TOKEN;
|
|
if (!url || !token) return null;
|
|
|
|
const resp = await fetch(`${url}/get/${encodeURIComponent(key)}`, {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
signal: AbortSignal.timeout(timeoutMs),
|
|
});
|
|
if (!resp.ok) return null;
|
|
|
|
const data = await resp.json();
|
|
if (!data.result) return null;
|
|
|
|
try {
|
|
return JSON.parse(data.result);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|