refactoring dashboard

This commit is contained in:
Emily
2025-01-23 17:34:43 +01:00
parent afeaac1b0d
commit e4bdf7e4c3
112 changed files with 2345 additions and 12532 deletions

View File

@@ -2,7 +2,7 @@
import { createUserJwt, readRegisterJwt } from '~/server/AuthManager';
import { UserModel } from '@schema/UserSchema';
import { PasswordModel } from '@schema/PasswordSchema';
import EmailService from '@services/EmailService';
// import EmailService from '@services/EmailService';
export default defineEventHandler(async event => {
@@ -14,7 +14,7 @@ export default defineEventHandler(async event => {
try {
await PasswordModel.create({ email: data.email, password: data.password })
await UserModel.create({ email: data.email, given_name: '', name: 'EmailLogin', locale: '', picture: '', created_at: Date.now() });
setImmediate(() => { EmailService.sendWelcomeEmail(data.email); });
// setImmediate(() => { EmailService.sendWelcomeEmail(data.email); });
const jwt = createUserJwt({ email: data.email, name: 'EmailLogin' });
return sendRedirect(event,`https://dashboard.litlyx.com/jwt_login?jwt_login=${jwt}`);
} catch (ex) {

View File

@@ -2,7 +2,7 @@
import { OAuth2Client } from 'google-auth-library';
import { createUserJwt } from '~/server/AuthManager';
import { UserModel } from '@schema/UserSchema';
import EmailService from '@services/EmailService';
// import EmailService from '@services/EmailService';
const { GOOGLE_AUTH_CLIENT_SECRET, GOOGLE_AUTH_CLIENT_ID } = useRuntimeConfig()
@@ -58,10 +58,10 @@ export default defineEventHandler(async event => {
const savedUser = await newUser.save();
setImmediate(() => {
console.log('SENDING WELCOME EMAIL TO', payload.email);
if (payload.email) EmailService.sendWelcomeEmail(payload.email);
});
// setImmediate(() => {
// console.log('SENDING WELCOME EMAIL TO', payload.email);
// if (payload.email) EmailService.sendWelcomeEmail(payload.email);
// });
return { error: false, access_token: createUserJwt({ email: savedUser.email, name: savedUser.name }) }

View File

@@ -2,7 +2,7 @@
import { createRegisterJwt, createUserJwt } from '~/server/AuthManager';
import { UserModel } from '@schema/UserSchema';
import { RegisterModel } from '@schema/RegisterSchema';
import EmailService from '@services/EmailService';
// import EmailService from '@services/EmailService';
import crypto from 'crypto';
function canRegister(email: string, password: string) {
@@ -33,9 +33,9 @@ export default defineEventHandler(async event => {
await RegisterModel.create({ email, password: hashedPassword });
setImmediate(() => {
EmailService.sendConfirmEmail(email, `https://dashboard.litlyx.com/api/auth/confirm_email?register_code=${jwt}`);
});
// setImmediate(() => {
// EmailService.sendConfirmEmail(email, `https://dashboard.litlyx.com/api/auth/confirm_email?register_code=${jwt}`);
// });
return {
error: false,

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 = `browsers:${pid}:${limit}:${from}:${to}`;
const cacheKey = `browsers:${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: "$browser", count: { $sum: 1, } } },

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 = `oss:${pid}:${limit}:${from}:${to}`;
const cacheKey = `oss:${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: "$os", count: { $sum: 1, } } },

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 = `websites:${pid}:${limit}:${from}:${to}`;
const cacheKey = `pages:${pid}:${limit}:${from}:${to}:${domain}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
@@ -19,10 +18,11 @@ 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: "$website", count: { $sum: 1, } } },
{ $group: { _id: "$page", count: { $sum: 1, } } },
{ $sort: { count: -1 } },
{ $limit: limit }
]);

View File

@@ -1,37 +0,0 @@
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 });
if (!data) return;
const { pid, from, to, project_id, limit } = data;
const websiteName = getHeader(event, 'x-website-name');
const cacheKey = `websites_pages:${websiteName}:${pid}:${limit}:${from}:${to}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
const result = await VisitModel.aggregate([
{
$match: {
project_id,
created_at: { $gte: new Date(from), $lte: new Date(to) }
},
},
{ $match: { website: websiteName, }, },
{ $group: { _id: "$page", count: { $sum: 1, } } },
{ $sort: { count: -1 } },
{ $limit: limit }
]);
return result as { _id: string, count: number }[];
});
});

View File

@@ -1,5 +1,4 @@
import { getPlanFromId } from "@data/PREMIUM";
import { PREMIUM_PLAN } from "../../../../shared/data/PREMIUM";
import { getPlanFromId, PREMIUM_PLAN } from "@data/PREMIUM";
import { canTryAppsumoCode, checkAppsumoCode, useAppsumoCode, useTryAppsumoCode } from "~/server/services/AppsumoService";
import StripeService from '~/server/services/StripeService';

View File

@@ -4,7 +4,7 @@ import type Event from 'stripe';
import { ProjectModel } from '@schema/project/ProjectSchema';
import { PREMIUM_DATA, PREMIUM_PLAN, getPlanFromId, getPlanFromPrice, getPlanFromTag } from '@data/PREMIUM';
import { ProjectLimitModel } from '@schema/project/ProjectsLimits';
import EmailService from '@services/EmailService'
// import EmailService from '@services/EmailService'
import { UserModel } from '@schema/UserSchema';
@@ -93,9 +93,9 @@ async function onPaymentOnetimeSuccess(event: Event.PaymentIntentSucceededEvent)
const user = await UserModel.findOne({ _id: project.owner });
if (!user) return { ok: false, error: 'USER NOT EXIST FOR PROJECT' + project.id }
setTimeout(() => {
EmailService.sendPurchaseEmail(user.email, project.name);
}, 1);
// setTimeout(() => {
// EmailService.sendPurchaseEmail(user.email, project.name);
// }, 1);
return { ok: true };
}
@@ -140,10 +140,10 @@ async function onPaymentSuccess(event: Event.InvoicePaidEvent) {
const user = await UserModel.findOne({ _id: project.owner });
if (!user) return { ok: false, error: 'USER NOT EXIST FOR PROJECT' + project.id }
setTimeout(() => {
if (PLAN.ID == 0) return;
if (isNewSubscription) EmailService.sendPurchaseEmail(user.email, project.name);
}, 1);
// setTimeout(() => {
// if (PLAN.ID == 0) return;
// if (isNewSubscription) EmailService.sendPurchaseEmail(user.email, project.name);
// }, 1);
return { ok: true };

View File

@@ -1,22 +1,22 @@
import { EventModel } from "@schema/metrics/EventSchema";
import { Redis } from "~/server/services/CacheService";
import { executeTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService";
import { executeTimelineAggregation } from "~/server/services/TimelineService";
export default defineEventHandler(async event => {
const data = await getRequestDataOld(event, { requireSchema: false, requireSlice: true });
const data = await getRequestData(event, ['SLICE', 'GUEST', 'DOMAIN', 'RANGE', 'OFFSET']);
if (!data) return;
const { pid, from, to, slice, project_id, timeOffset } = data;
const { pid, from, to, slice, project_id, timeOffset, domain } = data;
const cacheKey = `timeline:events:${pid}:${slice}:${from}:${to}`;
const cacheKey = `timeline:events:${pid}:${slice}:${from}:${to}:${domain}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
const timelineData = await executeTimelineAggregation({
projectId: project_id,
model: EventModel,
from, to, slice, timeOffset
from, to, slice, timeOffset, domain, debug: true
});
return timelineData;
});

View File

@@ -1,22 +1,22 @@
import { SessionModel } from "@schema/metrics/SessionSchema";
import { Redis } from "~/server/services/CacheService";
import { executeTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService";
import { executeTimelineAggregation } from "~/server/services/TimelineService";
export default defineEventHandler(async event => {
const data = await getRequestDataOld(event, { requireSchema: false, requireSlice: true });
const data = await getRequestData(event, ['SLICE', 'GUEST', 'DOMAIN', 'RANGE', 'OFFSET']);
if (!data) return;
const { pid, from, to, slice, project_id, timeOffset } = data;
const { pid, from, to, slice, project_id, timeOffset, domain } = data;
const cacheKey = `timeline:sessions:${pid}:${slice}:${from}:${to}`;
const cacheKey = `timeline:sessions:${pid}:${slice}:${from}:${to}:${domain}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
const timelineData = await executeTimelineAggregation({
projectId: project_id,
model: SessionModel,
from, to, slice, timeOffset
from, to, slice, timeOffset, domain
});
return timelineData;
});

View File

@@ -1,22 +1,22 @@
import { VisitModel } from "@schema/metrics/VisitSchema";
import { Redis } from "~/server/services/CacheService";
import { executeTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService";
import { executeTimelineAggregation } from "~/server/services/TimelineService";
export default defineEventHandler(async event => {
const data = await getRequestDataOld(event, { requireSchema: false, requireSlice: true });
const data = await getRequestData(event, ['SLICE', 'GUEST', 'DOMAIN', 'RANGE', 'OFFSET']);
if (!data) return;
const { pid, from, to, slice, project_id, timeOffset } = data;
const { pid, from, to, slice, project_id, timeOffset, domain } = data;
const cacheKey = `timeline:visits:${pid}:${slice}:${from}:${to}`;
const cacheKey = `timeline:visits:${pid}:${slice}:${from}:${to}:${domain}`;
const cacheExp = 60;
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
const timelineData = await executeTimelineAggregation({
projectId: project_id,
model: VisitModel,
from, to, slice, timeOffset
from, to, slice, timeOffset, domain
});
return timelineData;
});

View File

@@ -1,7 +1,7 @@
import crypto from 'crypto';
import { PasswordModel } from '@schema/PasswordSchema';
import EmailService from '@services/EmailService'
// import EmailService from '@services/EmailService'
export default defineEventHandler(async event => {
@@ -19,7 +19,7 @@ export default defineEventHandler(async event => {
target.password = hashedPassword;
await target.save();
await EmailService.sendResetPasswordEmail(email, newPass);
// await EmailService.sendResetPasswordEmail(email, newPass);
return { error: false, message: 'Password changed' }