mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
26 lines
722 B
TypeScript
26 lines
722 B
TypeScript
import { subMinutes } from 'date-fns';
|
|
import { RealtimeInit, NextApiRequestAuth } from 'lib/types';
|
|
import { useAuth } from 'lib/middleware';
|
|
import { NextApiResponse } from 'next';
|
|
import { methodNotAllowed, ok } from 'next-basics';
|
|
import { getRealtimeData } from 'queries';
|
|
|
|
export default async (req: NextApiRequestAuth, res: NextApiResponse<RealtimeInit>) => {
|
|
await useAuth(req, res);
|
|
|
|
if (req.method === 'GET') {
|
|
const { id, startAt } = req.query;
|
|
let startTime = subMinutes(new Date(), 30);
|
|
|
|
if (+startAt > startTime.getTime()) {
|
|
startTime = new Date(+startAt);
|
|
}
|
|
|
|
const data = await getRealtimeData(id, startTime);
|
|
|
|
return ok(res, data);
|
|
}
|
|
|
|
return methodNotAllowed(res);
|
|
};
|