revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s

revert style: clean up code with prettier and eslint
This commit is contained in:
remco committed 2026-07-12 21:02:03 +02:00
1 parent 27de078f54
commit e85e4d74ea
378 files changed
+20710 -22428

No files matched your search

+40 -40
View File
@@ -1,16 +1,16 @@
import { env } from "@/env";
import { prisma } from "../prisma";
import { env } from '@/env'
import { prisma } from '../prisma'
export type { WebhookAction } from "@/types/admin";
export type { WebhookAction } from '@/types/admin'
import type { WebhookAction } from "@/types/admin";
import type { WebhookAction } from '@/types/admin'
interface WebhookPayload {
action: WebhookAction;
actor: string;
target: string;
targetId?: number;
details?: string;
action: WebhookAction
actor: string
target: string
targetId?: number
details?: string
}
const ACTION_COLORS: Record<WebhookAction, number> = {
@@ -31,82 +31,82 @@ const ACTION_COLORS: Record<WebhookAction, number> = {
event_cancel: 0xf87272,
poll_create: 0x36d399,
poll_close: 0xa78bfa,
};
}
async function getSetting(cmsKey: string, envValue?: string): Promise<string | null> {
if (envValue) return envValue;
if (envValue) return envValue
try {
const setting = await prisma.websiteSetting.findUnique({ where: { key: cmsKey } });
return setting?.value || null;
const setting = await prisma.websiteSetting.findUnique({ where: { key: cmsKey } })
return setting?.value || null
} catch {
return null;
return null
}
}
async function sendDiscord(payload: WebhookPayload): Promise<void> {
const url = await getSetting("webhook_discord_url", env.DISCORD_WEBHOOK_URL);
if (!url) return;
const url = await getSetting('webhook_discord_url', env.DISCORD_WEBHOOK_URL)
if (!url) return
const embed = {
title: `[${payload.action.toUpperCase().replace("_", " ")}]`,
title: `[${payload.action.toUpperCase().replace('_', ' ')}]`,
color: ACTION_COLORS[payload.action] ?? 0x666666,
fields: [
{ name: "Staff", value: payload.actor, inline: true },
{ name: "Target", value: payload.target, inline: true },
{ name: 'Staff', value: payload.actor, inline: true },
{ name: 'Target', value: payload.target, inline: true },
],
timestamp: new Date().toISOString(),
};
}
if (payload.details) {
embed.fields.push({ name: "Details", value: payload.details, inline: false });
embed.fields.push({ name: 'Details', value: payload.details, inline: false })
}
try {
await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ embeds: [embed] }),
signal: AbortSignal.timeout(5000),
});
})
} catch (err) {
console.error("[Webhook] Discord send failed:", {
console.error('[Webhook] Discord send failed:', {
action: payload.action,
error: (err as Error).message,
});
})
}
}
async function sendTelegram(payload: WebhookPayload): Promise<void> {
const token = await getSetting("webhook_telegram_bot_token", env.TELEGRAM_BOT_TOKEN);
const chatId = await getSetting("webhook_telegram_chat_id", env.TELEGRAM_CHAT_ID);
if (!token || !chatId) return;
const token = await getSetting('webhook_telegram_bot_token', env.TELEGRAM_BOT_TOKEN)
const chatId = await getSetting('webhook_telegram_chat_id', env.TELEGRAM_CHAT_ID)
if (!token || !chatId) return
const text = [
`<b>[${payload.action.toUpperCase().replace("_", " ")}]</b>`,
`<b>[${payload.action.toUpperCase().replace('_', ' ')}]</b>`,
`<b>Staff:</b> ${payload.actor}`,
`<b>Target:</b> ${payload.target}`,
payload.details ? `<b>Details:</b> ${payload.details}` : "",
payload.details ? `<b>Details:</b> ${payload.details}` : '',
]
.filter(Boolean)
.join("\n");
.join('\n')
try {
await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ chat_id: chatId, text, parse_mode: "HTML" }),
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chat_id: chatId, text, parse_mode: 'HTML' }),
signal: AbortSignal.timeout(5000),
});
})
} catch (err) {
console.error("[Webhook] Telegram send failed:", {
console.error('[Webhook] Telegram send failed:', {
action: payload.action,
error: (err as Error).message,
});
})
}
}
/** Fire-and-forget notification to Discord + Telegram */
export function notify(payload: WebhookPayload): void {
sendDiscord(payload).catch(() => {});
sendTelegram(payload).catch(() => {});
sendDiscord(payload).catch(() => {})
sendTelegram(payload).catch(() => {})
}