mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 15:17:23 +01:00
Add api validations.
This commit is contained in:
parent
7d5a24044a
commit
7a7233ead4
41 changed files with 690 additions and 180 deletions
|
|
@ -1,22 +1,34 @@
|
|||
import { subMinutes } from 'date-fns';
|
||||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { useAuth, useValidate } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody, RealtimeInit } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getRealtimeData } from 'queries';
|
||||
|
||||
import * as yup from 'yup';
|
||||
export interface RealtimeRequestQuery {
|
||||
id: string;
|
||||
startAt: number;
|
||||
}
|
||||
|
||||
const currentDate = new Date().getTime();
|
||||
|
||||
const schema = {
|
||||
GET: yup.object().shape({
|
||||
id: yup.string().uuid().required(),
|
||||
startAt: yup.number().integer().max(currentDate).required(),
|
||||
}),
|
||||
};
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<RealtimeRequestQuery>,
|
||||
res: NextApiResponse<RealtimeInit>,
|
||||
) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
req.yup = schema;
|
||||
await useValidate(req, res);
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const { id: websiteId, startAt } = req.query;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue