mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-12 22:26:12 -05:00
Zod validated config for security and ease of getting started
This commit is contained in:
@@ -14,7 +14,6 @@ import {
|
||||
import { errorIsSqliteForeignKeyConstraintFailure } from "~/utils/sql";
|
||||
import { assertUnreachable } from "~/utils/types";
|
||||
import { _action, actualNumber, friendCode } from "~/utils/zod";
|
||||
import * as AdminNotifications from "../core/admin-notifications.server";
|
||||
import { plusTiersFromVotingAndLeaderboard } from "../core/plus-tier.server";
|
||||
|
||||
export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
@@ -170,14 +169,6 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
message = "API access granted";
|
||||
break;
|
||||
}
|
||||
case "TEST_ADMIN_NOTIFICATION": {
|
||||
requireRole("ADMIN");
|
||||
|
||||
await AdminNotifications.send("Test notification from admin panel");
|
||||
|
||||
message = "Test notification sent";
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
assertUnreachable(data);
|
||||
}
|
||||
@@ -240,7 +231,4 @@ export const adminActionSchema = z.union([
|
||||
_action: _action("API_ACCESS"),
|
||||
user: z.preprocess(actualNumber, z.number().positive()),
|
||||
}),
|
||||
z.object({
|
||||
_action: _action("TEST_ADMIN_NOTIFICATION"),
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import { logger } from "~/utils/logger";
|
||||
|
||||
const DISCORD_ADMIN_WEBHOOK_URL = process.env.DISCORD_ADMIN_WEBHOOK_URL;
|
||||
|
||||
if (!DISCORD_ADMIN_WEBHOOK_URL) {
|
||||
logger.info(
|
||||
"DISCORD_ADMIN_WEBHOOK_URL not set, admin notifications disabled",
|
||||
);
|
||||
}
|
||||
|
||||
export async function send(message: string): Promise<void> {
|
||||
if (!DISCORD_ADMIN_WEBHOOK_URL) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(DISCORD_ADMIN_WEBHOOK_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ content: message }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
logger.error(`Failed to send admin notification: ${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Failed to send admin notification", error);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,6 @@ function AdminActions() {
|
||||
return (
|
||||
<div className="stack lg">
|
||||
{DANGEROUS_CAN_ACCESS_DEV_CONTROLS ? <Seed /> : null}
|
||||
{DANGEROUS_CAN_ACCESS_DEV_CONTROLS ? <TestAdminNotification /> : null}
|
||||
{DANGEROUS_CAN_ACCESS_DEV_CONTROLS || isAdmin || isDev ? (
|
||||
<Impersonate />
|
||||
) : null}
|
||||
@@ -487,21 +486,4 @@ function Seed() {
|
||||
);
|
||||
}
|
||||
|
||||
function TestAdminNotification() {
|
||||
const fetcher = useFetcher();
|
||||
|
||||
return (
|
||||
<fetcher.Form method="post">
|
||||
<h2>Test Admin Notification</h2>
|
||||
<SubmitButton
|
||||
type="submit"
|
||||
_action="TEST_ADMIN_NOTIFICATION"
|
||||
state={fetcher.state}
|
||||
>
|
||||
Send Test
|
||||
</SubmitButton>
|
||||
</fetcher.Form>
|
||||
);
|
||||
}
|
||||
|
||||
export const ErrorBoundary = Catcher;
|
||||
|
||||
Reference in New Issue
Block a user