mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-02 05:57:36 +01:00
Merge branch 'dev' into analytics
This commit is contained in:
commit
f68cd970f6
@ -54,7 +54,11 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
||||
|
||||
const { type, payload } = getJsonBody<CollectRequestBody>(req);
|
||||
|
||||
validateBody(res, { type, payload });
|
||||
const error = validateBody({ type, payload });
|
||||
|
||||
if (error) {
|
||||
return badRequest(res, error);
|
||||
}
|
||||
|
||||
if (await hasBlockedIp(req)) {
|
||||
return forbidden(res);
|
||||
@ -114,17 +118,19 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
||||
return send(res, token);
|
||||
};
|
||||
|
||||
function validateBody(res: NextApiResponse, { type, payload }: CollectRequestBody) {
|
||||
const { data } = payload || {};
|
||||
|
||||
// Validate type
|
||||
if (type !== COLLECTION_TYPE.event && type !== COLLECTION_TYPE.identify) {
|
||||
return badRequest(res, 'Wrong payload type.');
|
||||
function validateBody({ type, payload }: CollectRequestBody) {
|
||||
if (!type || !payload) {
|
||||
return 'Invalid payload.';
|
||||
}
|
||||
|
||||
// Validate eventData is JSON
|
||||
if (type !== COLLECTION_TYPE.event && type !== COLLECTION_TYPE.identify) {
|
||||
return 'Wrong payload type.';
|
||||
}
|
||||
|
||||
const { data } = payload;
|
||||
|
||||
if (data && !(typeof data === 'object' && !Array.isArray(data))) {
|
||||
return badRequest(res, 'Invalid event data.');
|
||||
return 'Invalid event data.';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user