mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
17 lines
834 B
TypeScript
17 lines
834 B
TypeScript
import { visitController } from "~/server/controllers/VisitController";
|
|
import { Redis } from "~/server/services/CacheService";
|
|
|
|
export default defineEventHandler(async event => {
|
|
const ctx = await getRequestContext(event, 'pid', 'domain', 'range', 'slice', 'permission:webAnalytics', 'flag:allowShare');
|
|
const { pid, project_id, domain, from, to, slice } = ctx;
|
|
const cacheKey = `timeline:visits:${pid}:${slice}:${from}:${to}:${domain}`;
|
|
const cacheExp = 20;
|
|
if (getHeader(event, 'x-dev') === 'true') await Redis.del(cacheKey);
|
|
return await Redis.useCache(cacheKey, cacheExp, async () => {
|
|
const { data, time } = await visitController.executeDynamic({ project_id: project_id.toString(), from, to, slice, domain });
|
|
setHeader(event, 'x-time', time.toFixed());
|
|
return data;
|
|
});
|
|
|
|
|
|
}); |