集成 Turnstile 人机验证 + Cloudflare R2 事件归档

This commit is contained in:
2569718930@qq.com
2026-06-16 03:40:47 +08:00
parent 9d61d9443d
commit 382bc99f0c
8 changed files with 786 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
export function getConfiguredTurnstileSiteKey() {
return String(process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY || "").trim();
}
export function isTurnstileEnabled() {
return Boolean(getConfiguredTurnstileSiteKey());
}
export function getTurnstileTokenForAction(
token: string | null | undefined,
action: string,
options?: { message?: string },
) {
if (!isTurnstileEnabled()) return undefined;
const normalized = String(token || "").trim();
if (!normalized) {
throw new Error(
options?.message ||
`Complete the security check before continuing (${action}).`,
);
}
return normalized;
}