d666cedfc6
后端(node:sqlite 零原生依赖,data/site.db,WAL + busy_timeout 抗并发): - works / service_items / site_config / inquiries / admin_users / admin_sessions / captcha_challenges - API:admin 登录登出/密码、作品与服务 CRUD、图片上传、留言箱、 验证码 challenge/verify、咨询提交(一次性滑块令牌防重放) 后台 /virtheart(仅手动访问,未登录一律 307 → /virtheart/login): - 服务端布局鉴权 + DB 会话(httpOnly cookie 7 天)+ CSRF 头校验 - 概览 / 作品(上传、网格预设、发布开关)/ 服务 / 留言箱 / 配置(全站文案) - 设计与主站同语言:暗底点阵、mono、lime 选中,非传统后台模板 公开站: - 路由组 (site) 隔离站点壳层;首页/服务页文案全部 DB 驱动即时生效 - /services 服务菜单 + 留言表单 + 全屏居中滑块拼图验证码(对齐缺口) - 提交入 inquiries 并 SMTP(飞书 notify@)邮件通知 chenchun@virtheart.com - Header 新增「服务」菜单;旧作品清理,空状态自动接管 - 根布局仅承载字体/全局样式,后台无站点壳层 验证:登录/CSRF/发布隔离/滑块容错/令牌单次消费/SMTP 真发全部通过; lint 与基线一致(119 errors 均为存量)。
148 lines
4.2 KiB
TypeScript
148 lines
4.2 KiB
TypeScript
"use client";
|
||
|
||
/**
|
||
* About-paragraph passcode easter egg — ported from the original components
|
||
* `c9` + `c2` (chunk 4d3f3b68dbbde33a.js),品牌标签国内化为「小红书」:
|
||
*
|
||
* - Locked: the brand label slot scrambles as "■■" (each char wrapped,
|
||
* PASSCODE_LOCKED_CHAR_CLASS); clicking navigates through the route
|
||
* transition to /unlock/2026?return=%2F.
|
||
* - Unlocked: the slot settles to the "小红书" button span — long-press
|
||
* (500ms) or context-menu re-locks (confirm + reload).
|
||
* - The reveal sequence (ScrambleReveal) treats the label as a slot part, so
|
||
* its characters participate in the per-char scramble timing.
|
||
*/
|
||
import { useCallback, useRef } from "react";
|
||
import { useRouter } from "next/navigation";
|
||
import ScrambleReveal from "@/components/dom/ScrambleReveal";
|
||
import {
|
||
logoutPasscodeAccess,
|
||
usePasscodeAllowed,
|
||
} from "@/components/dom/PasscodeAccess";
|
||
import {
|
||
PASSCODE_LOCKED_CHAR_CLASS,
|
||
PASSCODE_LOCKED_SCRAMBLE_CLASS,
|
||
buildPasscodeUnlockHref,
|
||
passcodeLockedPlaceholderText,
|
||
primaryPasscodePath,
|
||
revealBrandLabel,
|
||
revealBrandLabelLength,
|
||
} from "@/lib/passcode";
|
||
|
||
const SCOPE = primaryPasscodePath(); // "/2026"
|
||
const BRAND = revealBrandLabel(); // "小红书"
|
||
const BRAND_LEN = revealBrandLabelLength(); // 2
|
||
|
||
function RevealLabelButton() {
|
||
const allowed = usePasscodeAllowed(SCOPE);
|
||
const router = useRouter();
|
||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||
|
||
const clearTimer = useCallback(() => {
|
||
if (timerRef.current) {
|
||
clearTimeout(timerRef.current);
|
||
timerRef.current = null;
|
||
}
|
||
}, []);
|
||
|
||
const relock = useCallback(async () => {
|
||
if (
|
||
window.confirm("要重新锁定受保护的内容吗?再次查看需要输入口令。")
|
||
) {
|
||
await logoutPasscodeAccess({ reload: true });
|
||
}
|
||
}, []);
|
||
|
||
if (!allowed) {
|
||
// TODO(route-system): go through useRouteTransitionController().startNavigation
|
||
const go = () => {
|
||
router.push(buildPasscodeUnlockHref(SCOPE, "/"));
|
||
};
|
||
return (
|
||
<span
|
||
role="button"
|
||
tabIndex={0}
|
||
aria-label="受保护内容 — 输入口令后显示"
|
||
className="inline-flex items-baseline gap-[0.12em] mx-[0.06em] align-baseline cursor-pointer select-text"
|
||
onClick={go}
|
||
onKeyDown={(e) => {
|
||
if (e.key === "Enter" || e.key === " ") {
|
||
e.preventDefault();
|
||
go();
|
||
}
|
||
}}
|
||
>
|
||
{passcodeLockedPlaceholderText()
|
||
.split("")
|
||
.map((ch, i) => (
|
||
<span key={i} aria-hidden="true" className={PASSCODE_LOCKED_CHAR_CLASS}>
|
||
{ch}
|
||
</span>
|
||
))}
|
||
</span>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<span
|
||
role="button"
|
||
tabIndex={0}
|
||
aria-label={`${BRAND} — 长按可重新锁定`}
|
||
className="inline mx-[0.06em] align-baseline cursor-default select-none"
|
||
onPointerDown={() => {
|
||
clearTimer();
|
||
timerRef.current = setTimeout(() => void relock(), 500);
|
||
}}
|
||
onPointerUp={clearTimer}
|
||
onPointerLeave={clearTimer}
|
||
onPointerCancel={clearTimer}
|
||
onContextMenu={(e) => {
|
||
e.preventDefault();
|
||
void relock();
|
||
}}
|
||
>
|
||
{BRAND}
|
||
</span>
|
||
);
|
||
}
|
||
|
||
export default function PasscodeRevealText({
|
||
className,
|
||
startDelayMs = 300,
|
||
letterDelayMs = 10,
|
||
prefix,
|
||
suffix,
|
||
brandName = "北极新一",
|
||
}: {
|
||
className?: string;
|
||
startDelayMs?: number;
|
||
letterDelayMs?: number;
|
||
/** 自我介绍前半句(site_config.intro_prefix,后台可改) */
|
||
prefix: string;
|
||
/** 自我介绍后半句(site_config.intro_suffix) */
|
||
suffix: string;
|
||
/** 介绍文字里的自称(品牌名) */
|
||
brandName?: string;
|
||
}) {
|
||
const allowed = usePasscodeAllowed(SCOPE);
|
||
const introPrefix = prefix.replace("北极新一", brandName);
|
||
const parts = [
|
||
introPrefix,
|
||
{
|
||
length: BRAND_LEN,
|
||
scramble: allowed ? BRAND : passcodeLockedPlaceholderText(),
|
||
className: allowed ? undefined : PASSCODE_LOCKED_SCRAMBLE_CLASS,
|
||
settled: <RevealLabelButton />,
|
||
},
|
||
suffix,
|
||
];
|
||
return (
|
||
<ScrambleReveal
|
||
className={className}
|
||
parts={parts}
|
||
startDelayMs={startDelayMs}
|
||
letterDelayMs={letterDelayMs}
|
||
/>
|
||
);
|
||
}
|