MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / importRouter

Function importRouter

apps/api/src/routes/import.router.ts:7–41  ·  view source on GitHub ↗
(fastify)

Source from the content-addressed store, hash-verified

5import { Prisma } from '@openpanel/db';
6
7const importRouter: FastifyPluginCallback = async (fastify) => {
8 fastify.addHook('preHandler', async (req: FastifyRequest, reply) => {
9 try {
10 const client = await validateImportRequest(req.headers);
11 req.client = client;
12 } catch (e) {
13 if (e instanceof Prisma.PrismaClientKnownRequestError) {
14 return reply.status(401).send({
15 error: 'Unauthorized',
16 message: 'Client ID seems to be malformed',
17 });
18 }
19
20 if (e instanceof Error) {
21 return reply
22 .status(401)
23 .send({ error: 'Unauthorized', message: e.message });
24 }
25
26 return reply
27 .status(401)
28 .send({ error: 'Unauthorized', message: 'Unexpected error' });
29 }
30 });
31
32 fastify.route({
33 method: 'POST',
34 url: '/events',
35 schema: {
36 tags: ['Import'],
37 description: 'Bulk import historical events.',
38 },
39 handler: controller.importEvents,
40 });
41};
42
43export default importRouter;

Callers

nothing calls this directly

Calls 2

validateImportRequestFunction · 0.90
sendMethod · 0.45

Tested by

no test coverage detected