mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
25 lines
577 B
TypeScript
25 lines
577 B
TypeScript
|
|
import { SessionModel } from "@schema/metrics/SessionSchema";
|
|
|
|
export default defineEventHandler(async event => {
|
|
|
|
const data = await getRequestDataOld(event, { requireSchema: false });
|
|
if (!data) return;
|
|
|
|
const { project_id } = data;
|
|
|
|
const online_users = await SessionModel.aggregate([
|
|
{
|
|
$match: {
|
|
project_id,
|
|
updated_at: { $gt: new Date(Date.now() - 1000 * 60 * 5) }
|
|
}
|
|
},
|
|
{ $count: 'count' }
|
|
]);
|
|
|
|
if (!online_users[0]) return 0;
|
|
|
|
return online_users[0].count;
|
|
|
|
}); |