8ce5471c25
- lib/passcode.ts:module 58156/28116 移植——primaryPasscodePath("/2026")、buildPasscodeUnlockHref("/unlock/2026?return=%2F")、slotCount:4、品牌名按原站 charCode-1 混淆解码(TikTok)、锁定占位符与字符/散段样式类
- PasscodeAccess.tsx:module 4278 移植——access store(useSyncExternalStore + passcode-access-changed 事件驱动刷新)、usePasscodeAllowed/usePasscodeAccessLookup、submit/logout(POST /api/passcode)
- PasscodeUnlockScreen:4 格圆环输入(inset ring label-1/label-3 + caret-blink 光标)、满 4 位自动提交、错误 shake(WAAPI 等价原 framer x 关键帧抖动)、成功 'Access granted' 600ms 后 replace 回来源、已解锁进入立即跳回
- layout 挂 PasscodeAccessProvider(服务端 cookies 读初始 access);新增 /api/passcode GET/POST(httpOnly cookie 持久化,解锁码经 PASSCODE_CODE 配置,默认 2026)与 /unlock/[scope] 页
- ScrambleReveal 支持 slot part({length,scramble,className,settled}):打散期显示占位字符、收尾替换为交互节点,1:1 原版语义
- 首页 about 段换 c9/c2 移植:锁定点击跳解锁页、解锁显示 TikTok、长按 500ms/右键 confirm 重锁;WorkSection 按 access 过滤,解锁后 TikTok 卡(tt01/tt02 素材)出现在首位
- CDP 全流程验证:锁定→解锁→持久化→重锁 循环 + 错码抖动清空 + 卡片数 10↔11
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import type { NextRequest } from "next/server";
|
|
import {
|
|
PASSCODE_COOKIE_NAME,
|
|
PASSCODE_PROTECTED_PATHS,
|
|
emptyPasscodeAccessState,
|
|
isPasscodeProtectedPath,
|
|
normalizePath,
|
|
} from "@/lib/passcode";
|
|
|
|
/**
|
|
* /api/passcode — the original site's access endpoint (module 4278 calls it):
|
|
* GET → current access state, e.g. {"/2026": false}
|
|
* POST {scope, code} → validate the code, set the access cookie
|
|
* POST {action: "logout"} → clear the access cookie
|
|
*
|
|
* The unlock code itself is a server secret (the original keeps it off the
|
|
* client bundle). Configure it with PASSCODE_CODE (4 characters, matching
|
|
* PASSCODE.slotCount); the default mirrors the theme year.
|
|
*/
|
|
const PASSCODE_CODE = process.env.PASSCODE_CODE ?? "2026";
|
|
|
|
const ONE_YEAR = 60 * 60 * 24 * 365;
|
|
|
|
function readAccess(request: NextRequest): Record<string, boolean> {
|
|
const raw = request.cookies.get(PASSCODE_COOKIE_NAME)?.value;
|
|
if (!raw) return emptyPasscodeAccessState();
|
|
try {
|
|
const parsed = JSON.parse(decodeURIComponent(raw)) as Record<string, unknown>;
|
|
const state = emptyPasscodeAccessState();
|
|
for (const key of Object.keys(state)) {
|
|
state[key] = parsed[key] === true;
|
|
}
|
|
return state;
|
|
} catch {
|
|
return emptyPasscodeAccessState();
|
|
}
|
|
}
|
|
|
|
export async function GET(request: NextRequest) {
|
|
return NextResponse.json(readAccess(request));
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
let body: { scope?: string; code?: string; action?: string };
|
|
try {
|
|
body = (await request.json()) as typeof body;
|
|
} catch {
|
|
return NextResponse.json({ ok: false }, { status: 400 });
|
|
}
|
|
|
|
const response = NextResponse.json({ ok: true });
|
|
|
|
if (body.action === "logout") {
|
|
response.cookies.delete(PASSCODE_COOKIE_NAME);
|
|
return response;
|
|
}
|
|
|
|
const scope = body.scope ? normalizePath(body.scope) : "";
|
|
if (!scope || !isPasscodeProtectedPath(scope)) {
|
|
return NextResponse.json({ ok: false }, { status: 400 });
|
|
}
|
|
if (typeof body.code !== "string" || body.code !== PASSCODE_CODE) {
|
|
return NextResponse.json({ ok: false }, { status: 401 });
|
|
}
|
|
|
|
const access = readAccess(request);
|
|
access[scope] = true;
|
|
for (const key of PASSCODE_PROTECTED_PATHS) {
|
|
if (!(key in access)) access[key] = false;
|
|
}
|
|
response.cookies.set({
|
|
name: PASSCODE_COOKIE_NAME,
|
|
value: encodeURIComponent(JSON.stringify(access)),
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
path: "/",
|
|
maxAge: ONE_YEAR,
|
|
});
|
|
return response;
|
|
}
|