new selfhosted version

This commit is contained in:
antonio
2025-11-28 14:11:51 +01:00
parent afda29997d
commit 951860f67e
1046 changed files with 72586 additions and 574750 deletions

View File

@@ -0,0 +1,26 @@
import { EventModel } from "~/shared/schema/metrics/EventSchema";
import { parseNumberInt } from "~/utils/parseNumber";
export default defineEventHandler(async event => {
const ctx = await getRequestContext(event, 'pid', 'domain', 'range', 'permission:webAnalytics');
const { project_id, domain, from, to } = ctx;
const { page, limit } = getQuery(event);
const pageValue = parseNumberInt(page, 1);
const limitValue = parseNumberInt(limit, 10);
const skipValue = (pageValue - 1) * limitValue;
const websiteMatch = domain ? { website: domain } : {};
const count = await EventModel.countDocuments({ project_id, ...websiteMatch, created_at: { $gte: new Date(from), $lte: new Date(to) } });
const result = await EventModel.find({
project_id, ...websiteMatch, created_at: { $gte: new Date(from), $lte: new Date(to) }
}, {}, {
skip: skipValue, limit: limitValue, sort: { created_at: -1 }
})
return { count, data: result };
});