update endpoints to support domains

This commit is contained in:
Emily
2025-01-22 17:46:59 +01:00
parent 8922507a64
commit afeaac1b0d
7 changed files with 36 additions and 25 deletions

View File

@@ -1,16 +1,15 @@
import { VisitModel } from "@schema/metrics/VisitSchema";
import { Redis } from "~/server/services/CacheService";
import { getRequestDataOld } from "~/server/utils/getRequestData";
export default defineEventHandler(async event => {
const data = await getRequestDataOld(event, { requireSchema: false });
const data = await getRequestData(event, ['GUEST', 'RANGE', 'GUEST', 'DOMAIN']);
if (!data) return;
const { pid, from, to, project_id, limit } = data;
const { pid, from, to, project_id, limit, domain } = data;
const cacheKey = `devices:${pid}:${limit}:${from}:${to}`;
const cacheKey = `devices:${pid}:${limit}:${from}:${to}:${domain}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
@@ -19,7 +18,8 @@ export default defineEventHandler(async event => {
{
$match: {
project_id,
created_at: { $gte: new Date(from), $lte: new Date(to) }
created_at: { $gte: new Date(from), $lte: new Date(to) },
website: domain
}
},
{ $group: { _id: "$device", count: { $sum: 1, } } },