42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
/**
|
|
* Returns current storm status — polled by the frontend every 60 seconds.
|
|
* Storm is considered "active" if an event was received within the last 24 hours.
|
|
*
|
|
* Requires Vercel KV to be connected for auto-trigger to work.
|
|
* Without KV: always returns stormActive: false (manual Storm Mode still works).
|
|
*
|
|
* Response: { stormActive: boolean, event: StormEvent | null, checkedAt: number }
|
|
*/
|
|
|
|
const STORM_ACTIVE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
|
|
export default async function handler(req, res) {
|
|
res.setHeader('Cache-Control', 'no-store');
|
|
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
try {
|
|
const { kv } = await import('@vercel/kv');
|
|
const event = await kv.get('lastStormEvent');
|
|
|
|
const stormActive = !!event &&
|
|
typeof event.receivedAt === 'number' &&
|
|
(Date.now() - event.receivedAt) < STORM_ACTIVE_WINDOW_MS;
|
|
|
|
return res.status(200).json({
|
|
stormActive,
|
|
event: stormActive ? event : null,
|
|
checkedAt: Date.now(),
|
|
});
|
|
} catch {
|
|
// KV not configured — storm auto-trigger unavailable, manual toggle still works
|
|
return res.status(200).json({
|
|
stormActive: false,
|
|
event: null,
|
|
checkedAt: Date.now(),
|
|
});
|
|
}
|
|
}
|