mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 07:37:11 +01:00
Converted admin, auth, me and realtime routes.
This commit is contained in:
parent
6c9f1ad06b
commit
5205551ca8
25 changed files with 346 additions and 7 deletions
30
src/app/api/realtime/[websiteId]/route.ts
Normal file
30
src/app/api/realtime/[websiteId]/route.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { json, unauthorized } from 'lib/response';
|
||||
import { getRealtimeData } from 'queries';
|
||||
import { canViewWebsite } from 'lib/auth';
|
||||
import { startOfMinute, subMinutes } from 'date-fns';
|
||||
import { REALTIME_RANGE } from 'lib/constants';
|
||||
import { parseRequest } from 'lib/request';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const { auth, query, error } = await parseRequest(request);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { timezone } = query;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = subMinutes(startOfMinute(new Date()), REALTIME_RANGE);
|
||||
|
||||
const data = await getRealtimeData(websiteId, { startDate, timezone });
|
||||
|
||||
return json(data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue