rename mixan to OPENPANEL!

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-11 13:40:46 +01:00
parent 6d4f9010d4
commit e6c0bc2ec8
201 changed files with 1193 additions and 1047 deletions

View File

@@ -1,56 +1,56 @@
import { isBot } from '@/bots';
import * as controller from '@/controllers/event.controller';
import { validateSdkRequest } from '@/utils/auth';
import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
import { isBot } from "@/bots";
import * as controller from "@/controllers/event.controller";
import { validateSdkRequest } from "@/utils/auth";
import type { FastifyPluginCallback, FastifyRequest } from "fastify";
import { createBotEvent } from '@mixan/db';
import type { PostEventPayload } from '@mixan/sdk';
import { createBotEvent } from "@openpanel/db";
import type { PostEventPayload } from "@openpanel/sdk";
const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
fastify.addHook(
'preHandler',
"preHandler",
async (
req: FastifyRequest<{
Body: PostEventPayload;
}>,
reply
reply,
) => {
try {
const projectId = await validateSdkRequest(req.headers);
req.projectId = projectId;
const bot = req.headers['user-agent']
? isBot(req.headers['user-agent'])
const bot = req.headers["user-agent"]
? isBot(req.headers["user-agent"])
: null;
if (bot) {
const path = (req.body?.properties?.__path ||
req.body?.properties?.path) as string | undefined;
req.log.warn({ ...req.headers, bot }, 'Bot detected (event)');
req.log.warn({ ...req.headers, bot }, "Bot detected (event)");
await createBotEvent({
...bot,
projectId,
path: path ?? '',
path: path ?? "",
createdAt: new Date(req.body?.timestamp),
});
reply.status(202).send('OK');
reply.status(202).send("OK");
}
} catch (e) {
req.log.error(e, 'Failed to create bot event');
req.log.error(e, "Failed to create bot event");
reply.status(401).send();
return;
}
}
},
);
fastify.route({
method: 'POST',
url: '/',
method: "POST",
url: "/",
handler: controller.postEvent,
});
fastify.route({
method: 'GET',
url: '/',
method: "GET",
url: "/",
handler: controller.postEvent,
});
done();