From bededec29c02fefac4282ea9842277766c3f3bf1 Mon Sep 17 00:00:00 2001 From: chenchun Date: Wed, 2 Sep 2026 19:12:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=8D=E5=8A=A1=E9=A1=B5=E5=8F=8C?= =?UTF-8?q?=E6=A0=8F=E5=B8=83=E5=B1=80=20+=20=E6=BB=91=E5=9D=97=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=20v2=EF=BC=88=E5=9B=BE=E7=89=87=E5=8C=96?= =?UTF-8?q?=E6=8C=91=E6=88=98/=E8=A1=8C=E4=B8=BA=E6=A0=A1=E9=AA=8C/?= =?UTF-8?q?=E9=99=90=E6=B5=81/=E8=9C=9C=E7=BD=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 服务页(/services): - lg+ 双栏:左列服务菜单(NO.01-07,点击选中)、右列表单 (sticky 跟随);移动端保持上下堆叠 滑块验证码 v2(防机械脚本): - 答案坐标不再下发:缺口位置由服务端烘进 PNG(lib/captchaImage 自绘点阵底图 + 拼块裁片,lib/pngEncoder 纯 TS PNG 编码器, node:zlib 零依赖),脚本必须做图像识别才能定位 - 行为轨迹校验:拖动采样提交服务端,样本数 ≥6、总时长 ≥1.2s、 单调时间戳、峰值速度 > 平均×1.8(匀速直线 = 拒)、末点 ≈ 答案 - 位置容差 ±10px;失败 5 次作废;挑战 10 分钟过期 - IP 指纹(哈希)限流:challenge 15/10min、verify 30/10min、 咨询提交 3/小时;蜜罐字段(website)命中静默丢弃 端到端:无轨迹/匀速直线/超短时长均拒;真人节奏通过;重放拦截; 蜜罐丢弃;第 14 次刷 challenge 起 429;SMTP 真发正常。 --- app/(site)/layout.tsx | 2 - app/(site)/services/ServicesClient.tsx | 34 +- app/api/captcha/new/route.ts | 19 +- app/api/captcha/verify/route.ts | 19 +- app/api/inquiry/route.ts | 34 +- components/canvas/LoadingCurtain.tsx | 56 ++-- components/dom/LoadingOverlay.tsx | 128 +------- components/dom/RouteTransitionOverlay.tsx | 374 +++++++++++++++------- components/dom/SliderCaptcha.tsx | 276 ++++++++++------ lib/captcha.ts | 154 +++++++-- lib/captchaImage.ts | 99 ++++++ lib/pngEncoder.ts | 62 ++++ 12 files changed, 867 insertions(+), 390 deletions(-) create mode 100644 lib/captchaImage.ts create mode 100644 lib/pngEncoder.ts diff --git a/app/(site)/layout.tsx b/app/(site)/layout.tsx index 216bb33..6a0cde6 100644 --- a/app/(site)/layout.tsx +++ b/app/(site)/layout.tsx @@ -2,7 +2,6 @@ import SmoothScroller from "@/components/dom/SmoothScroller"; import Header from "@/components/dom/Header"; import BackgroundGrid from "@/components/dom/BackgroundGrid"; import CustomScrollbar from "@/components/dom/CustomScrollbar"; -import LoadingOverlay from "@/components/dom/LoadingOverlay"; import { HeroScene } from "@/components/canvas/HeroScene"; import { PasscodeAccessProvider } from "@/components/dom/PasscodeAccess"; import { FullscreenTransitionProvider } from "@/lib/routeTransition"; @@ -84,7 +83,6 @@ export default async function SiteLayout({ {children} - ); diff --git a/app/(site)/services/ServicesClient.tsx b/app/(site)/services/ServicesClient.tsx index 9ca79f1..49c2c1e 100644 --- a/app/(site)/services/ServicesClient.tsx +++ b/app/(site)/services/ServicesClient.tsx @@ -43,6 +43,9 @@ export default function ServicesClient({ const [name, setName] = useState(""); const [contact, setContact] = useState(""); const [message, setMessage] = useState(""); + // 蜜罐:人类不可见(CSS 藏 + tabIndex=-1 + autocomplete 关闭), + // 群发机器人会把它当普通字段填上 —— 提交接口静默丢弃。 + const [honeypot, setHoneypot] = useState(""); const [captchaOpen, setCaptchaOpen] = useState(false); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); @@ -72,6 +75,7 @@ export default function ServicesClient({ serviceSlug: selected.slug, serviceTitle: selected.title, message: message.trim(), + website: honeypot, }), }); const data = (await res.json()) as { id?: number; error?: string }; @@ -89,7 +93,7 @@ export default function ServicesClient({ setSubmitting(false); } }, - [selected, name, contact, message] + [selected, name, contact, message, honeypot] ); if (doneId !== null) { @@ -164,8 +168,10 @@ export default function ServicesClient({

- {/* 服务菜单 */} -
+ {/* 双栏:左服务菜单 / 右表单(lg+ 并排,移动端上下堆叠) */} +
+ {/* 服务菜单(左栏) */} +
{services.length === 0 ? (

服务清单整理中——有需要可直接写邮件给我。 @@ -221,8 +227,11 @@ export default function ServicesClient({ )}

- {/* 留言表单 */} -
+ {/* 留言表单(右栏,lg+ sticky 跟随) */} +

{selected ? `咨询:${selected.title}` : "留言"}

@@ -273,6 +282,20 @@ export default function ServicesClient({

{submitNote}

+ {/* 蜜罐字段 — 人类不可见;机器人填了就被服务端静默丢弃 */} + + {error && (

{error} @@ -288,6 +311,7 @@ export default function ServicesClient({ {submitting ? "提交中…" : "提交(需完成滑块验证)"}

+ 500) { + return NextResponse.json({ error: "参数错误" }, { status: 400 }); + } + const result = verifyCaptcha(req, challengeId, Math.round(x), track); if (!result.ok) { return NextResponse.json({ error: result.error }, { status: 400 }); } diff --git a/app/api/inquiry/route.ts b/app/api/inquiry/route.ts index dc56e08..8b30ea2 100644 --- a/app/api/inquiry/route.ts +++ b/app/api/inquiry/route.ts @@ -5,7 +5,7 @@ * 状态记录在 inquiries.email_sent / email_error,后台留言箱可见)。 */ import { NextResponse } from "next/server"; -import { consumeSubmitToken } from "@/lib/captcha"; +import { consumeSubmitToken, clientFingerprint } from "@/lib/captcha"; import { createInquiry, markInquiryEmail } from "@/lib/siteConfig"; import { sendInquiryNotification } from "@/lib/mailer"; @@ -15,6 +15,21 @@ const NAME_MAX = 40; const CONTACT_MAX = 80; const MESSAGE_MAX = 2000; +// 提交限流桶(单实例内存实现,重启清零可接受)。 +const submitBuckets = new Map(); +function submitRateLimit(fp: string): boolean { + const now = Date.now(); + const windowMs = 60 * 60_000; + const arr = (submitBuckets.get(fp) ?? []).filter((t) => now - t < windowMs); + if (arr.length >= 3) { + submitBuckets.set(fp, arr); + return false; + } + arr.push(now); + submitBuckets.set(fp, arr); + return true; +} + export async function POST(req: Request) { let body: { submitToken?: string; @@ -23,6 +38,8 @@ export async function POST(req: Request) { serviceSlug?: string; serviceTitle?: string; message?: string; + /** 蜜罐:人类不可见不填写;机器人会全字段填充 */ + website?: string; }; try { body = await req.json(); @@ -30,6 +47,21 @@ export async function POST(req: Request) { return NextResponse.json({ error: "请求格式错误" }, { status: 400 }); } + // 蜜罐命中:静默丢弃(不告诉机器人被识别) + if (typeof body.website === "string" && body.website.trim() !== "") { + return NextResponse.json({ ok: true, id: 0 }); + } + + // 提交限流:3 次 / 小时 / IP(与验证码限流独立) + const fp = clientFingerprint(req); + const rl = submitRateLimit(fp); + if (!rl) { + return NextResponse.json( + { error: "提交过于频繁,请稍后再试" }, + { status: 429 } + ); + } + const name = String(body.name ?? "").trim(); const contact = String(body.contact ?? "").trim(); const message = String(body.message ?? "").trim(); diff --git a/components/canvas/LoadingCurtain.tsx b/components/canvas/LoadingCurtain.tsx index 1aeff5d..8244a83 100644 --- a/components/canvas/LoadingCurtain.tsx +++ b/components/canvas/LoadingCurtain.tsx @@ -416,31 +416,39 @@ export function LoadingCurtain({ onComplete?: (open: boolean) => void; }) { const materialRef = useRef(null); + // R3F's Canvas container carries inline `position: relative; width/height: + // 100%` which OVERRIDES any Tailwind `fixed inset-0` on the Canvas itself — + // the curtain then renders as an in-flow ~150px strip (invisible during + // transitions and, worse, pointer-events:auto so it eats card clicks). A + // dedicated fullscreen fixed wrapper gives the container a real viewport + // box; pointer-events:none inherits to the whole subtree. return ( - - - - +
+ + + + +
); } diff --git a/components/dom/LoadingOverlay.tsx b/components/dom/LoadingOverlay.tsx index e9fbfa4..c86992d 100644 --- a/components/dom/LoadingOverlay.tsx +++ b/components/dom/LoadingOverlay.tsx @@ -1,42 +1,28 @@ "use client"; -import { useEffect, useState, useSyncExternalStore } from "react"; -import { usePathname } from "next/navigation"; +import { useEffect, useSyncExternalStore } from "react"; import { loadingBus } from "@/lib/loadingBus"; -import LoadingCurtain from "@/components/canvas/LoadingCurtain"; + +/** + * Heavy-load hooks (formerly the entry LoadingOverlay). The entry/route + * curtain orchestration now lives in RouteTransitionOverlay (the original + * module 34841 drives BOTH flows from one pinhole curtain); this file keeps + * only the readiness plumbing other components consume. + */ /** Stable server snapshot (must be cached — a fresh object would loop). */ const SERVER_SNAPSHOT = { progress: 0, ready: false }; -function useHeavyLoad() { +export function useHeavyLoad() { return useSyncExternalStore( - loadingBus.subscribe, - loadingBus.getSnapshot, + loadingBusSubscribe, + loadingBusGetSnapshot, () => SERVER_SNAPSHOT ); } -function useFontsReady() { - const [fontsReady, setFontsReady] = useState(false); - useEffect(() => { - let cancelled = false; - const fonts = (document as any).fonts; - if (!fonts) { - setFontsReady(true); - return; - } - fonts.ready.then(() => { - if (!cancelled) setFontsReady(true); - }); - return () => { - cancelled = true; - }; - }, []); - return fontsReady; -} - -const clamp = (v: number, min: number, max: number) => - Math.min(max, Math.max(min, v)); +const loadingBusSubscribe = loadingBus.subscribe; +const loadingBusGetSnapshot = loadingBus.getSnapshot; /** * Heavy-asset readiness for the camera intro dolly (original cV's `p`: @@ -53,91 +39,3 @@ export function useAppReady(): boolean { return heavy.ready; } - -/** - * Entry loading flow — port of the original route-transition controller - * (module 34841) for the entry case on "/": - * - * 1. entry:wait — curtain fully closed (initialProgress 1), centered - * 140px bar shows 50%·fontsReady + 50%·heavyLoadProgress. - * 2. readyToLoadHeavy && fontsReady → hold 250ms → bar fades (250ms) - * → 250ms later the curtain opens (0.8s customCubic radial hole + - * dot mask) — reveal phase. - * 3. Curtain reveal completes (+0.9s grace) → idle: unmount everything. - */ -export function LoadingOverlay() { - const heavy = useHeavyLoad(); - const fontsReady = useFontsReady(); - // Original useHomeLoadingGate: the entry curtain is a "/"-only flow — - // detail routes render with no loading curtain at all. - const pathname = usePathname(); - - // wait → fading → reveal → (unmount when reveal completes) - const [phase, setPhase] = useState<"wait" | "fading" | "reveal">("wait"); - const [mounted, setMounted] = useState(true); - - const progress = Math.round(clamp(50 * +fontsReady + heavy.progress / 2, 0, 100)); - const assetsDone = heavy.ready && fontsReady; - - useEffect(() => { - if (!assetsDone || phase !== "wait") return; - // Original: 250ms hold → fade the bar → 250ms later open the curtain. - const t1 = window.setTimeout(() => setPhase("fading"), 250); - return () => window.clearTimeout(t1); - }, [assetsDone, phase]); - - useEffect(() => { - if (phase !== "fading") return; - const t2 = window.setTimeout(() => setPhase("reveal"), 250); - return () => window.clearTimeout(t2); - }, [phase]); - - if (!mounted || pathname !== "/") return null; - - return ( - <> - { - if (open) { - // Reveal finished — a beat later the curtain canvas unmounts. - window.setTimeout(() => setMounted(false), 900); - } - }} - /> - {phase !== "reveal" && ( - - )} - - ); -} - -/** Centered 140px progress bar (original `b`). */ -function ProgressBar({ progress, fading }: { progress: number; fading: boolean }) { - const clamped = clamp(progress, 0, 100); - return ( -