mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
new selfhosted version
This commit is contained in:
@@ -4,22 +4,22 @@ import { Redis } from "~/server/services/CacheService";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestData(event, ['RANGE', 'DOMAIN'], ['WEB']);
|
||||
if (!data) return;
|
||||
|
||||
const { pid, from, to, project_id, limit, domain } = data;
|
||||
const ctx = await getRequestContext(event, 'pid', 'domain', 'range', 'limit', 'permission:webAnalytics','flag:allowShare');
|
||||
const { pid, project_id, domain, from, to, limit } = ctx;
|
||||
|
||||
const cacheKey = `oss:${pid}:${limit}:${from}:${to}:${domain}`;
|
||||
const cacheExp = 60;
|
||||
|
||||
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
|
||||
return await Redis.useCache(cacheKey, cacheExp, async () => {
|
||||
|
||||
const websiteMatch = domain ? { website: domain } : {};
|
||||
|
||||
const result = await VisitModel.aggregate([
|
||||
{
|
||||
$match: {
|
||||
project_id,
|
||||
created_at: { $gte: new Date(from), $lte: new Date(to) },
|
||||
website: domain
|
||||
...websiteMatch
|
||||
}
|
||||
},
|
||||
{ $group: { _id: "$os", count: { $sum: 1, } } },
|
||||
|
||||
Reference in New Issue
Block a user