mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
35 lines
946 B
TypeScript
35 lines
946 B
TypeScript
import { WebsiteActive } from 'interface/api/models';
|
|
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
|
import { allowQuery } from 'lib/auth';
|
|
import { UmamiApi } from 'lib/constants';
|
|
import { useAuth, useCors } from 'lib/middleware';
|
|
import { NextApiResponse } from 'next';
|
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|
import { getActiveVisitors } from 'queries';
|
|
|
|
export interface WebsiteActiveRequestQuery {
|
|
id: string;
|
|
}
|
|
|
|
export default async (
|
|
req: NextApiRequestQueryBody<WebsiteActiveRequestQuery>,
|
|
res: NextApiResponse<WebsiteActive>,
|
|
) => {
|
|
await useCors(req, res);
|
|
await useAuth(req, res);
|
|
|
|
if (req.method === 'GET') {
|
|
if (!(await allowQuery(req, UmamiApi.AuthType.Website))) {
|
|
return unauthorized(res);
|
|
}
|
|
|
|
const { id: websiteId } = req.query;
|
|
|
|
const result = await getActiveVisitors(websiteId);
|
|
|
|
return ok(res, result);
|
|
}
|
|
|
|
return methodNotAllowed(res);
|
|
};
|