mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-19 07:43:38 +01:00
27 lines
621 B
JavaScript
27 lines
621 B
JavaScript
|
import { useAuth } from 'lib/middleware';
|
||
|
import { ok, methodNotAllowed, badRequest } from 'lib/response';
|
||
|
import { getRealtimeData } from 'lib/queries';
|
||
|
import { parseToken } from 'lib/crypto';
|
||
|
|
||
|
export default async (req, res) => {
|
||
|
await useAuth(req, res);
|
||
|
|
||
|
if (req.method === 'GET') {
|
||
|
const { start_at } = req.query;
|
||
|
|
||
|
const token = req.headers['x-umami-token'];
|
||
|
|
||
|
if (!token) {
|
||
|
return badRequest(res);
|
||
|
}
|
||
|
|
||
|
const { websites } = await parseToken(token);
|
||
|
|
||
|
const data = await getRealtimeData(websites, new Date(+start_at));
|
||
|
|
||
|
return ok(res, data);
|
||
|
}
|
||
|
|
||
|
return methodNotAllowed(res);
|
||
|
};
|