mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add security loop
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { anomalyCheckAll, AnomalyReport, findAnomalies } from "./AnomalyService";
|
||||
import { anomalyLoop } from "./AnomalyService";
|
||||
import { connectDatabase } from '@services/DatabaseService'
|
||||
import { requireEnv } from '@utils/requireEnv'
|
||||
|
||||
@@ -10,37 +10,18 @@ import { UserModel } from "@schema/UserSchema";
|
||||
EmailService.init(requireEnv('BREVO_API_KEY'));
|
||||
connectDatabase(requireEnv('MONGO_CONNECTION_STRING'));
|
||||
|
||||
anomalyCheckAll(async report => {
|
||||
|
||||
|
||||
anomalyLoop(async report => {
|
||||
if (report.visits.length > 0 || report.events.length > 0 || report.dns.length > 0) {
|
||||
|
||||
const project = await ProjectModel.findById(report.pid);
|
||||
if (!project) return { ok: false, error: 'Cannot find project with id ' + report.pid.toString() }
|
||||
const user = await UserModel.findById(project.owner);
|
||||
if (!user) return { ok: false, error: 'Cannot find user with id ' + project.owner.toString() }
|
||||
|
||||
if (report.visits.length > 0 || report.events.length > 0) {
|
||||
|
||||
await EmailService.sendAnomalyVisitsEventsEmail(
|
||||
user.email,
|
||||
project.name,
|
||||
{ visits: report.visits, events: report.events }
|
||||
);
|
||||
|
||||
await EmailService.sendAnomalyVisitsEventsEmail(user.email, project.name, { visits: report.visits, events: report.events });
|
||||
}
|
||||
|
||||
if (report.visits.length > 0) {
|
||||
|
||||
await EmailService.sendAnomalyDomainEmail(
|
||||
user.email,
|
||||
project.name,
|
||||
report.dns
|
||||
);
|
||||
|
||||
await EmailService.sendAnomalyDomainEmail(user.email, project.name, report.dns);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user