committed by
GitHub
parent
f0b7526847
commit
df05e2dab3
@@ -5,6 +5,7 @@ import icoToPng from 'ico-to-png';
|
||||
import sharp from 'sharp';
|
||||
|
||||
import { createHash } from '@openpanel/common';
|
||||
import { ch, TABLE_NAMES } from '@openpanel/db';
|
||||
import { getRedisCache } from '@openpanel/redis';
|
||||
|
||||
interface GetFaviconParams {
|
||||
@@ -110,3 +111,37 @@ export async function clearFavicons(
|
||||
}
|
||||
return reply.status(404).send('OK');
|
||||
}
|
||||
|
||||
export async function ping(
|
||||
request: FastifyRequest<{
|
||||
Body: {
|
||||
domain: string;
|
||||
count: number;
|
||||
};
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
) {
|
||||
try {
|
||||
await ch.insert({
|
||||
table: TABLE_NAMES.self_hosting,
|
||||
values: [
|
||||
{
|
||||
domain: request.body.domain,
|
||||
count: request.body.count,
|
||||
created_at: new Date(),
|
||||
},
|
||||
],
|
||||
format: 'JSONEachRow',
|
||||
});
|
||||
reply.status(200).send({
|
||||
message: `Success`,
|
||||
count: request.body.count,
|
||||
domain: request.body.domain,
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error(e, 'Failed to insert ping');
|
||||
reply.status(500).send({
|
||||
error: 'Failed to insert ping',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ export async function clerkWebhook(
|
||||
|
||||
if (payload.type === 'user.created') {
|
||||
const email = payload.data.email_addresses[0]?.email_address;
|
||||
const emails = payload.data.email_addresses.map((e) => e.email_address);
|
||||
|
||||
if (!email) {
|
||||
return Response.json(
|
||||
@@ -63,14 +64,16 @@ export async function clerkWebhook(
|
||||
|
||||
const memberships = await db.member.findMany({
|
||||
where: {
|
||||
email,
|
||||
email: {
|
||||
in: emails,
|
||||
},
|
||||
userId: null,
|
||||
},
|
||||
});
|
||||
|
||||
for (const membership of memberships) {
|
||||
const access = pathOr<string[]>([], ['meta', 'access'], membership);
|
||||
db.$transaction([
|
||||
await db.$transaction([
|
||||
// Update the member to link it to the user
|
||||
// This will remove the item from invitations
|
||||
db.member.update({
|
||||
@@ -123,7 +126,6 @@ export async function clerkWebhook(
|
||||
deletedAt: new Date(),
|
||||
firstName: null,
|
||||
lastName: null,
|
||||
email: `deleted+${payload.data.id}@openpanel.dev`,
|
||||
},
|
||||
}),
|
||||
db.projectAccess.deleteMany({
|
||||
|
||||
@@ -2,6 +2,12 @@ import * as controller from '@/controllers/misc.controller';
|
||||
import type { FastifyPluginCallback } from 'fastify';
|
||||
|
||||
const miscRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||
fastify.route({
|
||||
method: 'POST',
|
||||
url: '/ping',
|
||||
handler: controller.ping,
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: 'GET',
|
||||
url: '/favicon',
|
||||
|
||||
Reference in New Issue
Block a user