mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
42 lines
1 KiB
TypeScript
42 lines
1 KiB
TypeScript
import { WebsiteActive, NextApiRequestQueryBody } from 'lib/types';
|
|
import { canViewWebsite } from 'lib/auth';
|
|
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
|
import { NextApiResponse } from 'next';
|
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|
import { getActiveVisitors } from 'queries';
|
|
import * as yup from 'yup';
|
|
|
|
export interface WebsiteActiveRequestQuery {
|
|
id: string;
|
|
}
|
|
|
|
const schema = {
|
|
GET: yup.object().shape({
|
|
id: yup.string().uuid().required(),
|
|
}),
|
|
};
|
|
|
|
export default async (
|
|
req: NextApiRequestQueryBody<WebsiteActiveRequestQuery>,
|
|
res: NextApiResponse<WebsiteActive>,
|
|
) => {
|
|
await useCors(req, res);
|
|
await useAuth(req, res);
|
|
|
|
req.yup = schema;
|
|
await useValidate(req, res);
|
|
|
|
const { id: websiteId } = req.query;
|
|
|
|
if (req.method === 'GET') {
|
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
|
return unauthorized(res);
|
|
}
|
|
|
|
const result = await getActiveVisitors(websiteId);
|
|
|
|
return ok(res, result);
|
|
}
|
|
|
|
return methodNotAllowed(res);
|
|
};
|