feat: Next.js 后端 + SQLite + 暗门后台 /virtheart + 服务咨询页
后端(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 均为存量)。
This commit is contained in:
+3
-1
@@ -43,4 +43,6 @@ next-env.d.ts
|
|||||||
haoqi_clone
|
haoqi_clone
|
||||||
|
|
||||||
.workbuddy/
|
.workbuddy/
|
||||||
outputs/
|
outputs/
|
||||||
|
# SQLite 数据(后台内容库,部署时需持久化)
|
||||||
|
/data
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
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";
|
||||||
|
import RouteTransitionOverlay from "@/components/dom/RouteTransitionOverlay";
|
||||||
|
import { getPasscodeAccessServer } from "@/lib/passcodeServer";
|
||||||
|
import { getSiteConfig } from "@/lib/siteConfig";
|
||||||
|
import type { Metadata } from "next";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (site) 布局 — 公开站点的完整壳层:WebGL 画布、网格、平滑滚动、
|
||||||
|
* Header、路由过渡。/virtheart 后台不套用此壳层(纯净布局)。
|
||||||
|
* 站点文案从 site_config 读出后以 props 下发(Header 品牌/版权、
|
||||||
|
* 自我介绍槽位等),后台改完即时生效。
|
||||||
|
*/
|
||||||
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
|
const config = getSiteConfig();
|
||||||
|
return {
|
||||||
|
title: config.site_title,
|
||||||
|
description: config.site_description,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function SiteLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
const [initialAccess, config] = await Promise.all([
|
||||||
|
getPasscodeAccessServer(),
|
||||||
|
Promise.resolve(getSiteConfig()),
|
||||||
|
]);
|
||||||
|
return (
|
||||||
|
<PasscodeAccessProvider initialAccess={initialAccess}>
|
||||||
|
<FullscreenTransitionProvider>
|
||||||
|
{/* Original stacking (1:1): the WebGL canvas host is a plain `fixed`
|
||||||
|
z-auto element first in the body; the grid overlay (z-20) comes
|
||||||
|
AFTER it in DOM order so it paints above the canvas, exactly like
|
||||||
|
the original's main > canvas + z-20 grid sibling. */}
|
||||||
|
<HeroScene />
|
||||||
|
<BackgroundGrid />
|
||||||
|
<SmoothScroller />
|
||||||
|
<Header brandName={config.brand_name} copyrightName={config.copyright_name} />
|
||||||
|
{children}
|
||||||
|
<CustomScrollbar />
|
||||||
|
<RouteTransitionOverlay />
|
||||||
|
<LoadingOverlay />
|
||||||
|
</FullscreenTransitionProvider>
|
||||||
|
</PasscodeAccessProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,14 +4,28 @@ import FooterSection from "@/components/dom/FooterSection";
|
|||||||
import WorkSection from "@/components/dom/WorkSection";
|
import WorkSection from "@/components/dom/WorkSection";
|
||||||
import HyperSpaceSection from "@/components/dom/HyperSpaceSection";
|
import HyperSpaceSection from "@/components/dom/HyperSpaceSection";
|
||||||
import PasscodeRevealText from "@/components/dom/PasscodeRevealText";
|
import PasscodeRevealText from "@/components/dom/PasscodeRevealText";
|
||||||
|
import { getSiteConfig, listWorks } from "@/lib/siteConfig";
|
||||||
|
import type { WorkItem } from "@/lib/workItems";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page content matching the original DOM (haoqi_body.html):
|
* 首页 — 结构复刻原站(haoqi_body.html),文案全部来自 site_config
|
||||||
* - banner section (h-dvh) with meta row + big title, all scramble-revealed
|
*(/virtheart 后台「配置」可改,保存即生效);作品来自 works 表。
|
||||||
* - signature/about section (kept simple)
|
|
||||||
*/
|
*/
|
||||||
|
export default async function Home() {
|
||||||
export default function Home() {
|
const config = getSiteConfig();
|
||||||
|
const items: WorkItem[] = listWorks(true)
|
||||||
|
.filter((w) => w.name && (w.image_url || w.href))
|
||||||
|
.map((w) => ({
|
||||||
|
name: w.name,
|
||||||
|
imageUrl: w.image_url,
|
||||||
|
hoverImageUrl: w.hover_image_url,
|
||||||
|
href: w.href || `/work/${w.slug}`,
|
||||||
|
year: w.year,
|
||||||
|
type: w.type,
|
||||||
|
gridClass: w.grid_class || "col-span-12 lg:col-span-6 xl:col-span-4",
|
||||||
|
codingProject: w.coding_project === 1,
|
||||||
|
passcodeProtected: w.passcode_protected === 1,
|
||||||
|
}));
|
||||||
return (
|
return (
|
||||||
// NOTE: the original scrolls INSIDE <main> (its Lenis wraps the main
|
// NOTE: the original scrolls INSIDE <main> (its Lenis wraps the main
|
||||||
// container), which is what lets its position:sticky children pin. Our
|
// container), which is what lets its position:sticky children pin. Our
|
||||||
@@ -26,25 +40,30 @@ export default function Home() {
|
|||||||
>
|
>
|
||||||
<div className="flex flex-col order-2 lg:order-1 lg:grid lg:grid-cols-12 col-span-12 font-mono text-base">
|
<div className="flex flex-col order-2 lg:order-1 lg:grid lg:grid-cols-12 col-span-12 font-mono text-base">
|
||||||
<span className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-1 xl:col-start-1 p-2 font-sans font-medium text-[4svw] sm:text-2xl lg:text-3xl leading-tight">
|
<span className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-1 xl:col-start-1 p-2 font-sans font-medium text-[4svw] sm:text-2xl lg:text-3xl leading-tight">
|
||||||
<ScrambleReveal text="设计与" startDelayMs={300} letterDelayMs={10} />
|
<ScrambleReveal text={config.hero_line1} startDelayMs={300} letterDelayMs={10} />
|
||||||
<br />
|
<br />
|
||||||
<ScrambleReveal text="工程" startDelayMs={300} letterDelayMs={10} />
|
<ScrambleReveal text={config.hero_line2} startDelayMs={300} letterDelayMs={10} />
|
||||||
</span>
|
</span>
|
||||||
<ScrambleReveal
|
<ScrambleReveal
|
||||||
className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-4 xl:col-start-5 p-2 text-balance"
|
className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-4 xl:col-start-5 p-2 text-balance"
|
||||||
text="以系统思维思考,用心做出设计。"
|
text={config.hero_tagline}
|
||||||
startDelayMs={300}
|
startDelayMs={300}
|
||||||
letterDelayMs={10}
|
letterDelayMs={10}
|
||||||
/>
|
/>
|
||||||
<PasscodeRevealText className="col-span-12 lg:col-span-6 xl:col-span-4 lg:col-start-7 xl:col-start-9 mt-auto lg:mt-0 p-2" />
|
<PasscodeRevealText
|
||||||
|
className="col-span-12 lg:col-span-6 xl:col-span-4 lg:col-start-7 xl:col-start-9 mt-auto lg:mt-0 p-2"
|
||||||
|
prefix={config.intro_prefix}
|
||||||
|
suffix={config.intro_suffix}
|
||||||
|
brandName={config.brand_name}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="flex flex-col self-end order-1 lg:order-2 col-span-12 px-2 font-bold text-[7.2svw] lg:text-[6svw] 2xl:text-[5svw] xl:text-[5.6svw] uppercase leading-none"
|
className="flex flex-col self-end order-1 lg:order-2 col-span-12 px-2 font-bold text-[7.2svw] lg:text-[6svw] 2xl:text-[5svw] xl:text-[5.6svw] uppercase leading-none"
|
||||||
style={{ fontVariationSettings: '"wdth" 120' }}
|
style={{ fontVariationSettings: '"wdth" 120' }}
|
||||||
>
|
>
|
||||||
<ScrambleReveal text="我把匠心" startDelayMs={300} />
|
<ScrambleReveal text={config.hero_big_1} startDelayMs={300} />
|
||||||
<ScrambleReveal text="与品味" startDelayMs={500} />
|
<ScrambleReveal text={config.hero_big_2} startDelayMs={500} />
|
||||||
<ScrambleReveal text="带进数字作品" startDelayMs={700} />
|
<ScrambleReveal text={config.hero_big_3} startDelayMs={700} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -59,10 +78,7 @@ export default function Home() {
|
|||||||
'var(--font-tiktok), "MiSans", sans-serif',
|
'var(--font-tiktok), "MiSans", sans-serif',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span>
|
<span className="select-text">{config.about_p1}</span>
|
||||||
全栈开发者,融合产品设计与工程能力,负责从产品构思、界面设计到前后端、跨端客户端的完整应用交付,现阶段深耕
|
|
||||||
AI 应用开发。
|
|
||||||
</span>
|
|
||||||
</p>
|
</p>
|
||||||
<p
|
<p
|
||||||
className="p-2 w-full text-l2 md:text-[4.2svw] text-xl leading-[1.3] md:leading-none select-text"
|
className="p-2 w-full text-l2 md:text-[4.2svw] text-xl leading-[1.3] md:leading-none select-text"
|
||||||
@@ -71,22 +87,34 @@ export default function Home() {
|
|||||||
'var(--font-tiktok), "MiSans", sans-serif',
|
'var(--font-tiktok), "MiSans", sans-serif',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span>
|
<span className="select-text">
|
||||||
我相信工程塑造可靠的产品,设计赋予它们灵魂;
|
{config.about_p2}
|
||||||
<a
|
<a
|
||||||
href="#selected-work"
|
href={config.about_p2_link_href || "#selected-work"}
|
||||||
className="inline text-l1 underline underline-offset-[0.08em] decoration-solid decoration-(--label-3) transition-[text-decoration-color] duration-150 ease-out lg:[@media(hover:hover)]:hover:decoration-(--label-1)"
|
className="inline text-l1 underline underline-offset-[0.08em] decoration-solid decoration-(--label-3) transition-[text-decoration-color] duration-150 ease-out lg:[@media(hover:hover)]:hover:decoration-(--label-1)"
|
||||||
>
|
>
|
||||||
我的作品
|
{config.about_p2_link_label}
|
||||||
</a>
|
</a>
|
||||||
里记录了这些探索的痕迹。
|
{config.about_p2.endsWith(";") || config.about_p2.endsWith(",")
|
||||||
|
? "里记录了这些探索的痕迹。"
|
||||||
|
: ""}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Selected Work grid (id="selected-work", WebGL image layers) */}
|
{/* Selected Work grid (id="selected-work", WebGL image layers) */}
|
||||||
<WorkSection />
|
<WorkSection
|
||||||
|
items={items}
|
||||||
|
emptyText={{
|
||||||
|
headline: config.work_empty_headline,
|
||||||
|
note: config.work_empty_note,
|
||||||
|
ctaPrefix: config.work_empty_cta_prefix,
|
||||||
|
ctaSuffix: config.work_empty_cta_suffix,
|
||||||
|
ctaAction: config.work_empty_cta_action,
|
||||||
|
}}
|
||||||
|
contactEmail={config.contact_email}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Hyper-space scroll section (id="hyper-space"): the WebGL
|
{/* Hyper-space scroll section (id="hyper-space"): the WebGL
|
||||||
hyperspace arrow (cursor.glb stripes) tracks this section's
|
hyperspace arrow (cursor.glb stripes) tracks this section's
|
||||||
@@ -94,7 +122,7 @@ export default function Home() {
|
|||||||
<HyperSpaceSection />
|
<HyperSpaceSection />
|
||||||
|
|
||||||
{/* Contact / Footer Section (#contact, data-section="footer") */}
|
{/* Contact / Footer Section (#contact, data-section="footer") */}
|
||||||
<FooterSection />
|
<FooterSection contactEmail={config.contact_email} />
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务页(client)— 与主站同一设计语言:
|
||||||
|
* 大字 scramble 标题、编号服务菜单(NO.01…)、选择后展开留言表单,
|
||||||
|
* 提交触发全屏居中滑块验证码,通过后 POST /api/inquiry(后端入库 +
|
||||||
|
* 邮件通知 chenchun@virtheart.com)。
|
||||||
|
*/
|
||||||
|
import { useCallback, useMemo, useState } from "react";
|
||||||
|
import ScrambleReveal from "@/components/dom/ScrambleReveal";
|
||||||
|
import SliderCaptcha from "@/components/dom/SliderCaptcha";
|
||||||
|
import { useRouteTransitionController } from "@/lib/routeTransition";
|
||||||
|
import { CONTACT_EMAIL } from "@/lib/socials";
|
||||||
|
|
||||||
|
export type ServiceOption = {
|
||||||
|
slug: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
priceNote: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const inputCls =
|
||||||
|
"w-full border border-line bg-b1 px-3 py-2.5 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1 placeholder:text-l3";
|
||||||
|
const labelCls = "mb-1.5 block font-mono-2 text-xs uppercase tracking-widest text-l2";
|
||||||
|
const dotted =
|
||||||
|
"relative before:content-[''] before:absolute before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1";
|
||||||
|
|
||||||
|
export default function ServicesClient({
|
||||||
|
headline,
|
||||||
|
submitNote,
|
||||||
|
services,
|
||||||
|
}: {
|
||||||
|
headline: string;
|
||||||
|
submitNote: string;
|
||||||
|
services: ServiceOption[];
|
||||||
|
}) {
|
||||||
|
const { startNavigation } = useRouteTransitionController();
|
||||||
|
const headlineLines = useMemo(
|
||||||
|
() => (headline || "可提供的服务|选择你需要的服务,留言告诉我").split("|"),
|
||||||
|
[headline]
|
||||||
|
);
|
||||||
|
const [selected, setSelected] = useState<ServiceOption | null>(null);
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [contact, setContact] = useState("");
|
||||||
|
const [message, setMessage] = useState("");
|
||||||
|
const [captchaOpen, setCaptchaOpen] = useState(false);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [doneId, setDoneId] = useState<number | null>(null);
|
||||||
|
|
||||||
|
const canSubmit = selected && name.trim() && contact.trim() && message.trim();
|
||||||
|
|
||||||
|
const startSubmit = useCallback(() => {
|
||||||
|
if (!canSubmit || submitting) return;
|
||||||
|
setError(null);
|
||||||
|
setCaptchaOpen(true);
|
||||||
|
}, [canSubmit, submitting]);
|
||||||
|
|
||||||
|
const onCaptchaVerified = useCallback(
|
||||||
|
async (submitToken: string) => {
|
||||||
|
if (!selected) return;
|
||||||
|
setSubmitting(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/inquiry", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
submitToken,
|
||||||
|
name: name.trim(),
|
||||||
|
contact: contact.trim(),
|
||||||
|
serviceSlug: selected.slug,
|
||||||
|
serviceTitle: selected.title,
|
||||||
|
message: message.trim(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as { id?: number; error?: string };
|
||||||
|
if (!res.ok) {
|
||||||
|
setError(data.error ?? "提交失败,请重试");
|
||||||
|
setCaptchaOpen(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDoneId(data.id ?? 0);
|
||||||
|
setCaptchaOpen(false);
|
||||||
|
} catch {
|
||||||
|
setError("网络错误,请重试");
|
||||||
|
setCaptchaOpen(false);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[selected, name, contact, message]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (doneId !== null) {
|
||||||
|
return (
|
||||||
|
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px]">
|
||||||
|
<div className="pt-[14vh] flex flex-col gap-4">
|
||||||
|
<h1
|
||||||
|
className="font-bold text-[7.2svw] lg:text-[4.6svw] leading-none text-l1"
|
||||||
|
style={{ fontVariationSettings: '"wdth" 120' }}
|
||||||
|
>
|
||||||
|
<ScrambleReveal text="已收到" startDelayMs={200} scrambleColors={false} />
|
||||||
|
</h1>
|
||||||
|
<p className="font-mono-2 text-sm lg:text-base text-l2">
|
||||||
|
<ScrambleReveal
|
||||||
|
text={`留言编号 #${doneId} —— 我会尽快通过你留下的联系方式回复。`}
|
||||||
|
startDelayMs={400}
|
||||||
|
letterDelayMs={10}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
<div className="mt-4 flex gap-6 font-mono text-sm">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => startNavigation("/")}
|
||||||
|
className={`${dotted} p-2 uppercase cursor-pointer text-l1`}
|
||||||
|
>
|
||||||
|
<ScrambleReveal text="← 返回首页" startDelayMs={300} scrambleColors={false} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setDoneId(null);
|
||||||
|
setName("");
|
||||||
|
setContact("");
|
||||||
|
setMessage("");
|
||||||
|
setSelected(null);
|
||||||
|
}}
|
||||||
|
className={`${dotted} p-2 uppercase cursor-pointer text-l2`}
|
||||||
|
>
|
||||||
|
<ScrambleReveal text="再提交一条" startDelayMs={300} scrambleColors={false} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px]">
|
||||||
|
<header className="pt-[10vh]">
|
||||||
|
<h1
|
||||||
|
className="font-bold text-[7.2svw] lg:text-[4.6svw] leading-none text-l1"
|
||||||
|
style={{ fontVariationSettings: '"wdth" 120' }}
|
||||||
|
>
|
||||||
|
{headlineLines.map((line, i) => (
|
||||||
|
<span key={i} className={i > 0 ? "block text-right lg:text-right" : "block"}>
|
||||||
|
<ScrambleReveal
|
||||||
|
text={line}
|
||||||
|
startDelayMs={200 + i * 220}
|
||||||
|
reverse={i > 0}
|
||||||
|
scrambleColors={false}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</h1>
|
||||||
|
<div className="mt-2 border-line border-b" />
|
||||||
|
<p className="pt-3 font-mono-2 text-xs text-l3">
|
||||||
|
<ScrambleReveal
|
||||||
|
text={`服务咨询 · 邮件直达 ${CONTACT_EMAIL}`}
|
||||||
|
startDelayMs={500}
|
||||||
|
letterDelayMs={10}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{/* 服务菜单 */}
|
||||||
|
<section className="mt-12" aria-label="服务列表">
|
||||||
|
{services.length === 0 ? (
|
||||||
|
<p className="font-mono-2 text-sm text-l2 border border-dashed border-line p-8 text-center">
|
||||||
|
服务清单整理中——有需要可直接写邮件给我。
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="flex flex-col divide-y divide-line border-y border-line">
|
||||||
|
{services.map((s, i) => {
|
||||||
|
const active = selected?.slug === s.slug;
|
||||||
|
return (
|
||||||
|
<li key={s.slug}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setSelected(active ? null : s)}
|
||||||
|
aria-pressed={active}
|
||||||
|
className={`${dotted} w-full text-left cursor-pointer px-2 py-5 flex items-baseline gap-4 transition-colors ${
|
||||||
|
active ? "bg-[rgba(var(--label-d),0.04)]" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<span className="font-mono-2 text-xs text-l3 tabular-nums shrink-0">
|
||||||
|
NO.{String(i + 1).padStart(2, "0")}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className={`font-semibold text-lg lg:text-xl ${
|
||||||
|
active ? "text-l1" : "text-l2"
|
||||||
|
}`}
|
||||||
|
style={{ fontFamily: 'var(--font-tiktok), "MiSans", sans-serif' }}
|
||||||
|
>
|
||||||
|
{s.title}
|
||||||
|
</span>
|
||||||
|
{s.priceNote && (
|
||||||
|
<span className="ml-auto font-mono-2 text-xs text-l3 shrink-0">
|
||||||
|
{s.priceNote}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span
|
||||||
|
aria-hidden="true"
|
||||||
|
className={`font-mono text-sm shrink-0 transition-transform ${
|
||||||
|
active ? "rotate-45 text-l1" : "text-l3"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
+
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
{active && s.description && (
|
||||||
|
<p className="px-2 pb-5 pl-12 font-mono-2 text-sm leading-relaxed text-l2 whitespace-pre-wrap">
|
||||||
|
{s.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* 留言表单 */}
|
||||||
|
<section className="mt-12 flex flex-col gap-5" aria-label="咨询表单">
|
||||||
|
<p className="font-mono-2 text-xs text-l3 uppercase tracking-widest">
|
||||||
|
{selected ? `咨询:${selected.title}` : "留言"}
|
||||||
|
</p>
|
||||||
|
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2">
|
||||||
|
<div>
|
||||||
|
<label className={labelCls} htmlFor="svc-name">
|
||||||
|
怎么称呼你 *
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="svc-name"
|
||||||
|
className={inputCls}
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
maxLength={40}
|
||||||
|
placeholder="姓名 / 昵称"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelCls} htmlFor="svc-contact">
|
||||||
|
联系方式 *
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="svc-contact"
|
||||||
|
className={inputCls}
|
||||||
|
value={contact}
|
||||||
|
onChange={(e) => setContact(e.target.value)}
|
||||||
|
maxLength={80}
|
||||||
|
placeholder="邮箱 / 微信 / 手机号"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelCls} htmlFor="svc-message">
|
||||||
|
具体需求 *
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
id="svc-message"
|
||||||
|
className={`${inputCls} min-h-32`}
|
||||||
|
value={message}
|
||||||
|
onChange={(e) => setMessage(e.target.value)}
|
||||||
|
maxLength={2000}
|
||||||
|
placeholder={
|
||||||
|
selected
|
||||||
|
? `关于「${selected.title}」,简单描述一下你的场景、周期和预算范围…`
|
||||||
|
: "简单描述一下你的场景、周期和预算范围…"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<p className="mt-1.5 font-mono-2 text-xs text-l3">{submitNote}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="border-l-2 border-selection pl-2 text-sm text-l1" role="alert">
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={startSubmit}
|
||||||
|
disabled={!canSubmit || submitting}
|
||||||
|
className="w-full border border-l1 bg-l1 py-3.5 font-mono text-sm uppercase tracking-widest text-b1 transition-opacity hover:opacity-85 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer"
|
||||||
|
>
|
||||||
|
{submitting ? "提交中…" : "提交(需完成滑块验证)"}
|
||||||
|
</button>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<SliderCaptcha
|
||||||
|
open={captchaOpen}
|
||||||
|
onClose={() => !submitting && setCaptchaOpen(false)}
|
||||||
|
onVerified={onCaptchaVerified}
|
||||||
|
/>
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import ServicesClient from "./ServicesClient";
|
||||||
|
import { getSiteConfig, listServices } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "服务 · 北极新一",
|
||||||
|
description: "可提供的服务 — 选择你需要的服务,留言告诉我",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
/** /services — 服务列表(server 读 DB)+ 咨询表单(滑块验证码)。 */
|
||||||
|
export default function ServicesPage() {
|
||||||
|
const config = getSiteConfig();
|
||||||
|
const services = listServices(true).map((s) => ({
|
||||||
|
slug: s.slug,
|
||||||
|
title: s.title,
|
||||||
|
description: s.description,
|
||||||
|
priceNote: s.price_note,
|
||||||
|
}));
|
||||||
|
return (
|
||||||
|
<ServicesClient
|
||||||
|
headline={config.services_hero}
|
||||||
|
submitNote={config.services_submit_note}
|
||||||
|
services={services}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/** /api/admin/config — 站点配置读写。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { getSession, verifyCsrf } from "@/lib/auth";
|
||||||
|
import { CONFIG_KEYS, getSiteConfig, setSiteConfig, type SiteConfig } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
if (!(await getSession())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
return NextResponse.json({ config: getSiteConfig() });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PUT(req: Request) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
let body: Partial<SiteConfig>;
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const patch: Partial<Record<keyof SiteConfig, string>> = {};
|
||||||
|
for (const key of CONFIG_KEYS) {
|
||||||
|
const v = (body as Record<string, unknown>)[key];
|
||||||
|
if (typeof v === "string") patch[key] = v;
|
||||||
|
}
|
||||||
|
setSiteConfig(patch);
|
||||||
|
return NextResponse.json({ ok: true, config: getSiteConfig() });
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/** /api/admin/inquiries — 留言箱:列表 / 状态更新 / 删除。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { getSession, verifyCsrf } from "@/lib/auth";
|
||||||
|
import {
|
||||||
|
deleteInquiry,
|
||||||
|
listInquiries,
|
||||||
|
updateInquiryStatus,
|
||||||
|
type InquiryRow,
|
||||||
|
} from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
if (!(await getSession())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
return NextResponse.json({ inquiries: listInquiries(200) });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PATCH(req: Request) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
let body: { id?: number; status?: InquiryRow["status"] };
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const valid: InquiryRow["status"][] = ["new", "read", "replied", "archived"];
|
||||||
|
if (
|
||||||
|
!Number.isInteger(body.id) ||
|
||||||
|
!body.status ||
|
||||||
|
!valid.includes(body.status)
|
||||||
|
) {
|
||||||
|
return NextResponse.json({ error: "参数错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
updateInquiryStatus(body.id as number, body.status);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DELETE(req: Request) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
const { searchParams } = new URL(req.url);
|
||||||
|
const id = Number(searchParams.get("id"));
|
||||||
|
if (!Number.isInteger(id)) {
|
||||||
|
return NextResponse.json({ error: "无效 ID" }, { status: 400 });
|
||||||
|
}
|
||||||
|
deleteInquiry(id);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* /api/admin/login — 后台登录。
|
||||||
|
* POST { username, password } → 设置 httpOnly 会话 cookie。
|
||||||
|
*/
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { createSession, SESSION_COOKIE } from "@/lib/auth";
|
||||||
|
import { verifyAdminPassword } from "@/lib/auth";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
let body: { username?: string; password?: string };
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const username = String(body.username ?? "").trim();
|
||||||
|
const password = String(body.password ?? "");
|
||||||
|
if (!username || !password) {
|
||||||
|
return NextResponse.json({ error: "请输入用户名和密码" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const userId = verifyAdminPassword(username, password);
|
||||||
|
if (userId === null) {
|
||||||
|
// 统一错误信息,不区分用户名/密码错误(防枚举)
|
||||||
|
return NextResponse.json({ error: "用户名或密码不正确" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { token, csrf } = createSession(userId);
|
||||||
|
const res = NextResponse.json({ ok: true, csrf });
|
||||||
|
res.cookies.set(SESSION_COOKIE, token, {
|
||||||
|
httpOnly: true,
|
||||||
|
sameSite: "lax",
|
||||||
|
secure: process.env.NODE_ENV === "production",
|
||||||
|
path: "/",
|
||||||
|
maxAge: 60 * 60 * 24 * 7,
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/** /api/admin/logout — 清除会话。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { destroySession, getSession, SESSION_COOKIE } from "@/lib/auth";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function POST() {
|
||||||
|
const session = await getSession();
|
||||||
|
if (session) destroySession(session.token);
|
||||||
|
const res = NextResponse.json({ ok: true });
|
||||||
|
res.cookies.set(SESSION_COOKIE, "", { path: "/", maxAge: 0 });
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/** /api/admin/password — 修改后台密码。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { changeAdminPassword, getSession, verifyCsrf } from "@/lib/auth";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function PUT(req: Request) {
|
||||||
|
const session = await getSession();
|
||||||
|
if (!session || !(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
let body: { password?: string };
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const password = String(body.password ?? "");
|
||||||
|
if (password.length < 8) {
|
||||||
|
return NextResponse.json({ error: "密码至少 8 位" }, { status: 400 });
|
||||||
|
}
|
||||||
|
await changeAdminPassword(session.user_id, password);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/** /api/admin/services/[id] — 删除服务。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { verifyCsrf } from "@/lib/auth";
|
||||||
|
import { deleteService } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function DELETE(
|
||||||
|
_req: Request,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
const { id } = await params;
|
||||||
|
const numId = Number(id);
|
||||||
|
if (!Number.isInteger(numId)) {
|
||||||
|
return NextResponse.json({ error: "无效 ID" }, { status: 400 });
|
||||||
|
}
|
||||||
|
deleteService(numId);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/** /api/admin/services — 服务项目管理。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { getSession, verifyCsrf } from "@/lib/auth";
|
||||||
|
import { listServices, upsertService } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
if (!(await getSession())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
return NextResponse.json({ services: listServices(false) });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
let body: {
|
||||||
|
id?: number;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
price_note?: string;
|
||||||
|
sort_order?: number;
|
||||||
|
enabled?: number;
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const title = String(body.title ?? "").trim();
|
||||||
|
if (!title) {
|
||||||
|
return NextResponse.json({ error: "服务名称必填" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const row = upsertService({
|
||||||
|
id: body.id,
|
||||||
|
title,
|
||||||
|
description: body.description,
|
||||||
|
price_note: body.price_note,
|
||||||
|
sort_order: body.sort_order,
|
||||||
|
enabled: body.enabled,
|
||||||
|
});
|
||||||
|
return NextResponse.json({ ok: true, service: row });
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* /api/admin/upload — 图片上传(作品封面 / 服务配图)。
|
||||||
|
* multipart/form-data: file → 保存到 public/work/,返回可访问路径。
|
||||||
|
* 文件类型白名单 png/jpg/webp,大小 ≤ 8MB。
|
||||||
|
*/
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import crypto from "node:crypto";
|
||||||
|
import fs from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
import { verifyCsrf } from "@/lib/auth";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
const ALLOWED: Record<string, string> = {
|
||||||
|
"image/png": "png",
|
||||||
|
"image/jpeg": "jpg",
|
||||||
|
"image/webp": "webp",
|
||||||
|
};
|
||||||
|
const MAX_SIZE = 8 * 1024 * 1024;
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
let form: FormData;
|
||||||
|
try {
|
||||||
|
form = await req.formData();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const file = form.get("file");
|
||||||
|
if (!(file instanceof File)) {
|
||||||
|
return NextResponse.json({ error: "缺少文件" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const ext = ALLOWED[file.type];
|
||||||
|
if (!ext) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "仅支持 PNG / JPG / WebP" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (file.size > MAX_SIZE) {
|
||||||
|
return NextResponse.json({ error: "文件不能超过 8MB" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const dir = path.join(process.cwd(), "public", "work");
|
||||||
|
await fs.mkdir(dir, { recursive: true });
|
||||||
|
const name = `${Date.now().toString(36)}-${crypto
|
||||||
|
.randomBytes(4)
|
||||||
|
.toString("hex")}.${ext}`;
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(dir, name),
|
||||||
|
Buffer.from(await file.arrayBuffer())
|
||||||
|
);
|
||||||
|
return NextResponse.json({ ok: true, url: `/work/${name}` });
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/** /api/admin/works/[id] — 删除作品。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { verifyCsrf } from "@/lib/auth";
|
||||||
|
import { deleteWork } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function DELETE(
|
||||||
|
_req: Request,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
const { id } = await params;
|
||||||
|
const numId = Number(id);
|
||||||
|
if (!Number.isInteger(numId)) {
|
||||||
|
return NextResponse.json({ error: "无效 ID" }, { status: 400 });
|
||||||
|
}
|
||||||
|
deleteWork(numId);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/** /api/admin/works — 作品列表 + 新增/更新(upsert by slug)。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { getSession, verifyCsrf } from "@/lib/auth";
|
||||||
|
import { listWorks, upsertWork, type WorkRow } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
if (!(await getSession())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
return NextResponse.json({ works: listWorks(false) });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
if (!(await verifyCsrf())) {
|
||||||
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||||||
|
}
|
||||||
|
let body: Partial<WorkRow> & { name?: string };
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const name = String(body.name ?? "").trim();
|
||||||
|
if (!name) {
|
||||||
|
return NextResponse.json({ error: "作品名称必填" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const row = upsertWork({ ...body, name });
|
||||||
|
return NextResponse.json({ ok: true, work: row });
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/** /api/captcha/new — 生成滑块挑战(公开)。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { createCaptchaChallenge } from "@/lib/captcha";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function POST() {
|
||||||
|
const challenge = createCaptchaChallenge();
|
||||||
|
return NextResponse.json(challenge);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/** /api/captcha/verify — 校验滑块位置,通过则签发一次性提交令牌。 */
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { verifyCaptcha } from "@/lib/captcha";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
let body: { token?: string; x?: number };
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const token = String(body.token ?? "");
|
||||||
|
const x = Number(body.x);
|
||||||
|
if (!token || !Number.isFinite(x)) {
|
||||||
|
return NextResponse.json({ error: "参数错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
const result = verifyCaptcha(token, Math.round(x));
|
||||||
|
if (!result.ok) {
|
||||||
|
return NextResponse.json({ error: result.error }, { status: 400 });
|
||||||
|
}
|
||||||
|
return NextResponse.json({ ok: true, submitToken: result.submitToken });
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/**
|
||||||
|
* /api/inquiry — 服务咨询提交(公开)。
|
||||||
|
* 必须携带滑块验证通过后签发的一次性 submitToken。
|
||||||
|
* 入库后异步发通知邮件到 chenchun@virtheart.com(失败不影响入库,
|
||||||
|
* 状态记录在 inquiries.email_sent / email_error,后台留言箱可见)。
|
||||||
|
*/
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { consumeSubmitToken } from "@/lib/captcha";
|
||||||
|
import { createInquiry, markInquiryEmail } from "@/lib/siteConfig";
|
||||||
|
import { sendInquiryNotification } from "@/lib/mailer";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
const NAME_MAX = 40;
|
||||||
|
const CONTACT_MAX = 80;
|
||||||
|
const MESSAGE_MAX = 2000;
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
let body: {
|
||||||
|
submitToken?: string;
|
||||||
|
name?: string;
|
||||||
|
contact?: string;
|
||||||
|
serviceSlug?: string;
|
||||||
|
serviceTitle?: string;
|
||||||
|
message?: string;
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
body = await req.json();
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = String(body.name ?? "").trim();
|
||||||
|
const contact = String(body.contact ?? "").trim();
|
||||||
|
const message = String(body.message ?? "").trim();
|
||||||
|
const serviceSlug = String(body.serviceSlug ?? "").slice(0, 80);
|
||||||
|
const serviceTitle = String(body.serviceTitle ?? "").slice(0, 120);
|
||||||
|
|
||||||
|
if (!name || !contact || !message) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "姓名、联系方式和留言内容都不能为空" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (name.length > NAME_MAX || contact.length > CONTACT_MAX || message.length > MESSAGE_MAX) {
|
||||||
|
return NextResponse.json({ error: "内容超出长度限制" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 滑块一次性令牌校验(消费即作废,防重放)
|
||||||
|
const submitToken = String(body.submitToken ?? "");
|
||||||
|
if (!submitToken || !consumeSubmitToken(submitToken)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "验证已失效,请重新完成滑块验证" },
|
||||||
|
{ status: 403 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const inquiry = createInquiry({
|
||||||
|
name,
|
||||||
|
contact,
|
||||||
|
service_slug: serviceSlug,
|
||||||
|
service_title: serviceTitle,
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 邮件通知:失败不阻塞提交
|
||||||
|
try {
|
||||||
|
await sendInquiryNotification({
|
||||||
|
id: inquiry.id,
|
||||||
|
name: inquiry.name,
|
||||||
|
contact: inquiry.contact,
|
||||||
|
service_title: inquiry.service_title,
|
||||||
|
message: inquiry.message,
|
||||||
|
created_at: inquiry.created_at,
|
||||||
|
});
|
||||||
|
markInquiryEmail(inquiry.id, true);
|
||||||
|
} catch (err) {
|
||||||
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
|
markInquiryEmail(inquiry.id, false, msg.slice(0, 300));
|
||||||
|
console.error("[inquiry] 邮件通知失败:", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({ ok: true, id: inquiry.id });
|
||||||
|
}
|
||||||
@@ -140,6 +140,26 @@ html::-webkit-scrollbar, body::-webkit-scrollbar {
|
|||||||
animation: caret-blink 1s step-end infinite;
|
animation: caret-blink 1s step-end infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 滑块验证码 — 校验失败抖动。 */
|
||||||
|
@keyframes vh-shake {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
20% {
|
||||||
|
transform: translateX(-6px);
|
||||||
|
}
|
||||||
|
40% {
|
||||||
|
transform: translateX(6px);
|
||||||
|
}
|
||||||
|
60% {
|
||||||
|
transform: translateX(-4px);
|
||||||
|
}
|
||||||
|
80% {
|
||||||
|
transform: translateX(4px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes hsstFadeIn {
|
@keyframes hsstFadeIn {
|
||||||
0% {
|
0% {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|||||||
+8
-32
@@ -1,16 +1,6 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import localFont from "next/font/local";
|
import localFont from "next/font/local";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
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";
|
|
||||||
import RouteTransitionOverlay from "@/components/dom/RouteTransitionOverlay";
|
|
||||||
import { getPasscodeAccessServer } from "@/lib/passcodeServer";
|
|
||||||
|
|
||||||
const tiktokSans = localFont({
|
const tiktokSans = localFont({
|
||||||
src: "./fonts/TikTokSans.ttf",
|
src: "./fonts/TikTokSans.ttf",
|
||||||
@@ -34,18 +24,21 @@ const departureMono = localFont({
|
|||||||
// 以 <link> 引入 —— 见下方 <head>;不进 next/font 管线(整包 5MB/字重)。
|
// 以 <link> 引入 —— 见下方 <head>;不进 next/font 管线(整包 5MB/字重)。
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
// Detail pages override the title via generateMetadata in
|
// 站点标题/描述可在 /virtheart 后台「配置」中修改(site_config 表)。
|
||||||
// app/work/[slug]/layout.tsx (original: per-page title).
|
|
||||||
title: "北极新一©2026",
|
title: "北极新一©2026",
|
||||||
description: "设计与工程 / 数字产品与 AI 应用 © 2026",
|
description: "设计与工程 / 数字产品与 AI 应用 © 2026",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function RootLayout({
|
/**
|
||||||
|
* 根布局 — 仅承载 html/body/字体/全局样式。
|
||||||
|
* 站点壳层(画布、Header、滚动)在 app/(site)/layout.tsx;
|
||||||
|
* 后台 /virtheart 使用独立布局,不加载站点壳层。
|
||||||
|
*/
|
||||||
|
export default function RootLayout({
|
||||||
children,
|
children,
|
||||||
}: Readonly<{
|
}: Readonly<{
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}>) {
|
}>) {
|
||||||
const initialAccess = await getPasscodeAccessServer();
|
|
||||||
return (
|
return (
|
||||||
<html
|
<html
|
||||||
lang="zh-CN"
|
lang="zh-CN"
|
||||||
@@ -85,24 +78,7 @@ export default async function RootLayout({
|
|||||||
suppressHydrationWarning
|
suppressHydrationWarning
|
||||||
/>
|
/>
|
||||||
</head>
|
</head>
|
||||||
<body className="min-h-screen relative">
|
<body className="min-h-screen relative">{children}</body>
|
||||||
<PasscodeAccessProvider initialAccess={initialAccess}>
|
|
||||||
<FullscreenTransitionProvider>
|
|
||||||
{/* Original stacking (1:1): the WebGL canvas host is a plain `fixed`
|
|
||||||
z-auto element first in the body; the grid overlay (z-20) comes
|
|
||||||
AFTER it in DOM order so it paints above the canvas, exactly like
|
|
||||||
the original's main > canvas + z-20 grid sibling. */}
|
|
||||||
<HeroScene />
|
|
||||||
<BackgroundGrid />
|
|
||||||
<SmoothScroller />
|
|
||||||
<Header />
|
|
||||||
{children}
|
|
||||||
<CustomScrollbar />
|
|
||||||
<RouteTransitionOverlay />
|
|
||||||
<LoadingOverlay />
|
|
||||||
</FullscreenTransitionProvider>
|
|
||||||
</PasscodeAccessProvider>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AdminShell — 后台框架:顶栏(品牌 + 导航 + 退出)+ 内容区。
|
||||||
|
* 设计与主站一致:点阵底、mono 标签、无圆角卡片堆砌。
|
||||||
|
*/
|
||||||
|
import Link from "next/link";
|
||||||
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
|
||||||
|
const NAV = [
|
||||||
|
{ href: "/virtheart/dashboard", label: "概览" },
|
||||||
|
{ href: "/virtheart/works", label: "作品" },
|
||||||
|
{ href: "/virtheart/services", label: "服务" },
|
||||||
|
{ href: "/virtheart/inquiries", label: "留言箱" },
|
||||||
|
{ href: "/virtheart/settings", label: "配置" },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function AdminShell({
|
||||||
|
csrf,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
csrf: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const logout = useCallback(async () => {
|
||||||
|
await fetch("/api/admin/logout", { method: "POST" });
|
||||||
|
router.replace("/virtheart/login");
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminCsrfContext.Provider value={csrf}>
|
||||||
|
<div
|
||||||
|
className="min-h-screen bg-b1"
|
||||||
|
style={{
|
||||||
|
backgroundImage:
|
||||||
|
"radial-gradient(var(--grid-dot) 1px, transparent 1px)",
|
||||||
|
backgroundSize: "22px 22px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<header className="sticky top-0 z-40 border-b border-line bg-b1/95 backdrop-blur-sm">
|
||||||
|
<div className="mx-auto flex max-w-6xl flex-wrap items-center gap-x-6 gap-y-2 px-4 py-3 lg:px-8">
|
||||||
|
<Link
|
||||||
|
href="/virtheart/dashboard"
|
||||||
|
className="font-mono-2 text-xs uppercase tracking-widest text-l2"
|
||||||
|
>
|
||||||
|
virtheart · control
|
||||||
|
</Link>
|
||||||
|
<nav className="flex flex-wrap items-center gap-x-4 gap-y-1">
|
||||||
|
{NAV.map((item) => {
|
||||||
|
const active = pathname.startsWith(item.href);
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={item.href}
|
||||||
|
href={item.href}
|
||||||
|
className={`font-mono text-sm transition-colors ${
|
||||||
|
active
|
||||||
|
? "text-l1 underline underline-offset-4"
|
||||||
|
: "text-l2 hover:text-l1"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</nav>
|
||||||
|
<div className="ml-auto flex items-center gap-4">
|
||||||
|
<Link
|
||||||
|
href="/"
|
||||||
|
target="_blank"
|
||||||
|
className="font-mono-2 text-xs text-l3 hover:text-l2"
|
||||||
|
>
|
||||||
|
查看站点 ↗
|
||||||
|
</Link>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={logout}
|
||||||
|
className="cursor-pointer font-mono-2 text-xs text-l3 hover:text-l1"
|
||||||
|
>
|
||||||
|
退出
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main className="mx-auto max-w-6xl px-4 py-8 lg:px-8">{children}</main>
|
||||||
|
</div>
|
||||||
|
</AdminCsrfContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
import { createContext, useContext } from "react";
|
||||||
|
|
||||||
|
const AdminCsrfContext = createContext("");
|
||||||
|
|
||||||
|
/** 后台 mutation 统一带上 CSRF 头。 */
|
||||||
|
export function useAdminFetch() {
|
||||||
|
const csrf = useContext(AdminCsrfContext);
|
||||||
|
return useCallback(
|
||||||
|
(input: string, init?: RequestInit) => {
|
||||||
|
const headers = new Headers(init?.headers);
|
||||||
|
headers.set(CSRF_HEADER_NAME, csrf);
|
||||||
|
return fetch(input, { ...init, headers });
|
||||||
|
},
|
||||||
|
[csrf]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CSRF_HEADER_NAME = "x-vh-csrf";
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/** /virtheart/dashboard — 概览:统计 + 最近留言。 */
|
||||||
|
import Link from "next/link";
|
||||||
|
import { listInquiries, listServices, listWorks } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
function StatCard({ label, value, href }: { label: string; value: number | string; href: string }) {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
href={href}
|
||||||
|
className="block border border-line bg-be p-5 transition-colors hover:border-l2"
|
||||||
|
>
|
||||||
|
<div className="font-mono-2 text-xs uppercase tracking-widest text-l3">
|
||||||
|
{label}
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 font-bold text-3xl text-l1 tabular-nums">{value}</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DashboardPage() {
|
||||||
|
const works = listWorks(false);
|
||||||
|
const services = listServices(false);
|
||||||
|
const inquiries = listInquiries(200);
|
||||||
|
const newCount = inquiries.filter((i) => i.status === "new").length;
|
||||||
|
const latest = inquiries.slice(0, 5);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-8">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-bold text-2xl text-l1">概览</h1>
|
||||||
|
<p className="mt-1 font-mono-2 text-sm text-l3">
|
||||||
|
站点运行状态一目了然
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4 lg:grid-cols-4">
|
||||||
|
<StatCard label="作品" value={works.length} href="/virtheart/works" />
|
||||||
|
<StatCard label="已发布" value={works.filter((w) => w.published).length} href="/virtheart/works" />
|
||||||
|
<StatCard label="服务" value={services.length} href="/virtheart/services" />
|
||||||
|
<StatCard label="新留言" value={newCount} href="/virtheart/inquiries" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section className="border border-line bg-be p-5">
|
||||||
|
<div className="mb-4 flex items-center justify-between">
|
||||||
|
<h2 className="font-semibold text-l1">最近留言</h2>
|
||||||
|
<Link href="/virtheart/inquiries" className="font-mono-2 text-xs text-l2 hover:text-l1">
|
||||||
|
全部 →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
{latest.length === 0 ? (
|
||||||
|
<p className="font-mono-2 text-sm text-l3">
|
||||||
|
暂无留言——有人通过服务页联系你时会出现在这里。
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="flex flex-col divide-y divide-line">
|
||||||
|
{latest.map((i) => (
|
||||||
|
<li key={i.id} className="flex flex-wrap items-center gap-x-4 gap-y-1 py-3">
|
||||||
|
<span className="font-mono-2 text-xs text-l3">#{i.id}</span>
|
||||||
|
<span className="text-sm text-l1">{i.name}</span>
|
||||||
|
<span className="text-sm text-l2">{i.service_title || "未选择服务"}</span>
|
||||||
|
{i.status === "new" && (
|
||||||
|
<span className="bg-selection px-1.5 text-xs text-black">NEW</span>
|
||||||
|
)}
|
||||||
|
<span className="ml-auto font-mono-2 text-xs text-l3">
|
||||||
|
{i.created_at}
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/** /virtheart/inquiries — 留言箱:查看 / 标记状态 / 删除。 */
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { useAdminFetch } from "../AdminShell";
|
||||||
|
import type { InquiryRow } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
const STATUS_LABELS: Record<InquiryRow["status"], string> = {
|
||||||
|
new: "新",
|
||||||
|
read: "已读",
|
||||||
|
replied: "已回复",
|
||||||
|
archived: "归档",
|
||||||
|
};
|
||||||
|
|
||||||
|
const NEXT_STATUS: Record<InquiryRow["status"], InquiryRow["status"]> = {
|
||||||
|
new: "read",
|
||||||
|
read: "replied",
|
||||||
|
replied: "archived",
|
||||||
|
archived: "new",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function InquiriesAdminPage() {
|
||||||
|
const adminFetch = useAdminFetch();
|
||||||
|
const [items, setItems] = useState<InquiryRow[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
// 数据加载(async 内 setState,避免 effect 同步路径触发级联渲染)。
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
void (async () => {
|
||||||
|
const res = await adminFetch("/api/admin/inquiries");
|
||||||
|
const data = (await res.json()) as { inquiries?: InquiryRow[] };
|
||||||
|
if (cancelled) return;
|
||||||
|
setItems(data.inquiries ?? []);
|
||||||
|
setLoading(false);
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [adminFetch]);
|
||||||
|
|
||||||
|
// mutation 后刷新列表(不回置 loading 骨架)。
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
const res = await adminFetch("/api/admin/inquiries");
|
||||||
|
const data = (await res.json()) as { inquiries?: InquiryRow[] };
|
||||||
|
setItems(data.inquiries ?? []);
|
||||||
|
}, [adminFetch]);
|
||||||
|
|
||||||
|
const setStatus = useCallback(
|
||||||
|
async (id: number, status: InquiryRow["status"]) => {
|
||||||
|
await adminFetch("/api/admin/inquiries", {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ id, status }),
|
||||||
|
});
|
||||||
|
void load();
|
||||||
|
},
|
||||||
|
[adminFetch, load]
|
||||||
|
);
|
||||||
|
|
||||||
|
const remove = useCallback(
|
||||||
|
async (id: number) => {
|
||||||
|
if (!window.confirm(`确定删除留言 #${id}?`)) return;
|
||||||
|
await adminFetch(`/api/admin/inquiries?id=${id}`, { method: "DELETE" });
|
||||||
|
void load();
|
||||||
|
},
|
||||||
|
[adminFetch, load]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-bold text-2xl text-l1">留言箱</h1>
|
||||||
|
<p className="mt-1 font-mono-2 text-sm text-l3">
|
||||||
|
服务页提交的咨询都会记录在这里,并同步邮件通知到联系邮箱
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<p className="font-mono-2 text-sm text-l3">加载中…</p>
|
||||||
|
) : items.length === 0 ? (
|
||||||
|
<div className="border border-dashed border-line p-8 text-center font-mono-2 text-sm text-l2">
|
||||||
|
暂无留言。
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<ul className="flex flex-col gap-4">
|
||||||
|
{items.map((i) => (
|
||||||
|
<li key={i.id} className="border border-line bg-be p-4">
|
||||||
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-1">
|
||||||
|
<span className="font-mono-2 text-xs text-l3">#{i.id}</span>
|
||||||
|
<span className="text-sm text-l1">{i.name}</span>
|
||||||
|
<a
|
||||||
|
href={i.contact.includes("@") ? `mailto:${i.contact}` : "#"}
|
||||||
|
className="font-mono text-sm text-l2 underline underline-offset-2"
|
||||||
|
>
|
||||||
|
{i.contact}
|
||||||
|
</a>
|
||||||
|
<span className="font-mono-2 text-xs text-l2">
|
||||||
|
{i.service_title || "未选择服务"}
|
||||||
|
</span>
|
||||||
|
{i.status === "new" && (
|
||||||
|
<span className="bg-selection px-1.5 font-mono-2 text-xs text-black">
|
||||||
|
NEW
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span className="ml-auto font-mono-2 text-xs text-l3">
|
||||||
|
{i.created_at}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p className="mt-3 text-sm leading-relaxed whitespace-pre-wrap text-l1">
|
||||||
|
{i.message}
|
||||||
|
</p>
|
||||||
|
<div className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setStatus(i.id, NEXT_STATUS[i.status])}
|
||||||
|
className="cursor-pointer font-mono text-sm text-l2 hover:text-l1"
|
||||||
|
>
|
||||||
|
标记为「{STATUS_LABELS[NEXT_STATUS[i.status]]}」
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => remove(i.id)}
|
||||||
|
className="cursor-pointer font-mono text-sm text-l3 hover:text-l1"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
<span className="ml-auto font-mono-2 text-xs text-l3">
|
||||||
|
{i.email_sent ? "邮件已通知" : i.email_error ? `邮件失败:${i.email_error}` : ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getSession, isAdmin } from "@/lib/auth";
|
||||||
|
import type { Metadata } from "next";
|
||||||
|
import AdminShell from "./AdminShell";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "控制台",
|
||||||
|
robots: { index: false, follow: false },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* /virtheart/(protected) 布局 — 服务端鉴权:未登录一律跳 /virtheart/login。
|
||||||
|
* 会话中的 csrf_token 传给 AdminShell,mutation 请求头统一回传。
|
||||||
|
*/
|
||||||
|
export default async function ProtectedLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{ children: React.ReactNode }>) {
|
||||||
|
if (!(await isAdmin())) {
|
||||||
|
redirect("/virtheart/login");
|
||||||
|
}
|
||||||
|
const session = await getSession();
|
||||||
|
return <AdminShell csrf={session?.csrf_token ?? ""}>{children}</AdminShell>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/** /virtheart/services — 服务项目管理(增删改 + 启用开关)。 */
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { useAdminFetch } from "../AdminShell";
|
||||||
|
import type { ServiceRow } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
const inputCls =
|
||||||
|
"w-full border border-line bg-b1 px-3 py-2 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1";
|
||||||
|
|
||||||
|
type Draft = {
|
||||||
|
id?: number;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
price_note: string;
|
||||||
|
sort_order: number;
|
||||||
|
enabled: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const EMPTY: Draft = { title: "", description: "", price_note: "", sort_order: 0, enabled: 1 };
|
||||||
|
|
||||||
|
export default function ServicesAdminPage() {
|
||||||
|
const adminFetch = useAdminFetch();
|
||||||
|
const [services, setServices] = useState<ServiceRow[]>([]);
|
||||||
|
const [draft, setDraft] = useState<Draft | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// 数据加载(async 内 setState,避免 effect 同步路径触发级联渲染)。
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
void (async () => {
|
||||||
|
const res = await adminFetch("/api/admin/services");
|
||||||
|
const data = (await res.json()) as { services?: ServiceRow[] };
|
||||||
|
if (cancelled) return;
|
||||||
|
setServices(data.services ?? []);
|
||||||
|
setLoading(false);
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [adminFetch]);
|
||||||
|
|
||||||
|
// mutation 后刷新列表(不回置 loading 骨架)。
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
const res = await adminFetch("/api/admin/services");
|
||||||
|
const data = (await res.json()) as { services?: ServiceRow[] };
|
||||||
|
setServices(data.services ?? []);
|
||||||
|
}, [adminFetch]);
|
||||||
|
|
||||||
|
const save = useCallback(async () => {
|
||||||
|
if (!draft) return;
|
||||||
|
setError(null);
|
||||||
|
const res = await adminFetch("/api/admin/services", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify(draft),
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as { error?: string };
|
||||||
|
if (!res.ok) {
|
||||||
|
setError(data.error ?? "保存失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDraft(null);
|
||||||
|
void load();
|
||||||
|
}, [draft, adminFetch, load]);
|
||||||
|
|
||||||
|
const remove = useCallback(
|
||||||
|
async (id: number) => {
|
||||||
|
if (!window.confirm(`确定删除服务 #${id}?`)) return;
|
||||||
|
await adminFetch(`/api/admin/services/${id}`, { method: "DELETE" });
|
||||||
|
void load();
|
||||||
|
},
|
||||||
|
[adminFetch, load]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-bold text-2xl text-l1">服务</h1>
|
||||||
|
<p className="mt-1 font-mono-2 text-sm text-l3">
|
||||||
|
/services 页面展示已启用的服务条目
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setDraft({ ...EMPTY })}
|
||||||
|
className="cursor-pointer border border-l1 bg-l1 px-4 py-2 font-mono text-sm text-b1 hover:opacity-85"
|
||||||
|
>
|
||||||
|
+ 新服务
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="border-l-2 border-selection pl-2 text-sm text-l1">{error}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<p className="font-mono-2 text-sm text-l3">加载中…</p>
|
||||||
|
) : services.length === 0 ? (
|
||||||
|
<div className="border border-dashed border-line p-8 text-center font-mono-2 text-sm text-l2">
|
||||||
|
暂无服务——服务页将只显示联系引导。
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<ul className="flex flex-col divide-y divide-line border border-line bg-be">
|
||||||
|
{services.map((s) => (
|
||||||
|
<li key={s.id} className="flex flex-wrap items-center gap-x-4 gap-y-2 p-4">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="text-sm text-l1">
|
||||||
|
{s.title}
|
||||||
|
{!s.enabled && (
|
||||||
|
<span className="ml-2 border border-line px-1 font-mono-2 text-xs text-l3">
|
||||||
|
已停用
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="max-w-xl truncate font-mono-2 text-xs text-l3">
|
||||||
|
{s.description}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
setDraft({
|
||||||
|
id: s.id,
|
||||||
|
title: s.title,
|
||||||
|
description: s.description,
|
||||||
|
price_note: s.price_note,
|
||||||
|
sort_order: s.sort_order,
|
||||||
|
enabled: s.enabled,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
className="cursor-pointer font-mono text-sm text-l2 hover:text-l1"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => remove(s.id)}
|
||||||
|
className="cursor-pointer font-mono text-sm text-l3 hover:text-l1"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{draft && (
|
||||||
|
<div className="inset-0 z-50 fixed flex justify-center items-center overflow-y-auto bg-b1/80 p-4">
|
||||||
|
<div className="w-full max-w-xl border border-line bg-be p-6 my-8">
|
||||||
|
<h2 className="mb-5 font-bold text-lg text-l1">
|
||||||
|
{draft.id ? "编辑服务" : "新增服务"}
|
||||||
|
</h2>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block font-mono-2 text-xs text-l2">名称 *</label>
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.title}
|
||||||
|
onChange={(e) => setDraft({ ...draft, title: e.target.value })}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block font-mono-2 text-xs text-l2">描述</label>
|
||||||
|
<textarea
|
||||||
|
className={`${inputCls} min-h-20`}
|
||||||
|
value={draft.description}
|
||||||
|
onChange={(e) => setDraft({ ...draft, description: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block font-mono-2 text-xs text-l2">
|
||||||
|
价格说明
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.price_note}
|
||||||
|
onChange={(e) => setDraft({ ...draft, price_note: e.target.value })}
|
||||||
|
placeholder="¥X,XXX 起 / 面议"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block font-mono-2 text-xs text-l2">排序</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.sort_order}
|
||||||
|
onChange={(e) =>
|
||||||
|
setDraft({ ...draft, sort_order: Number(e.target.value) || 0 })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label className="flex cursor-pointer items-center gap-2 text-sm text-l1">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={draft.enabled === 1}
|
||||||
|
onChange={(e) =>
|
||||||
|
setDraft({ ...draft, enabled: e.target.checked ? 1 : 0 })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
启用(在服务页展示)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="mt-6 flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={save}
|
||||||
|
disabled={!draft.title.trim()}
|
||||||
|
className="cursor-pointer border border-l1 bg-l1 px-5 py-2 font-mono text-sm text-b1 hover:opacity-85 disabled:opacity-40"
|
||||||
|
>
|
||||||
|
保存
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setDraft(null)}
|
||||||
|
className="cursor-pointer border border-line px-5 py-2 font-mono text-sm text-l2 hover:text-l1"
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* /virtheart/settings — 站点配置编辑(分组字段 + 修改密码)。
|
||||||
|
* 改动保存到 site_config 表,前台页面即时读取生效。
|
||||||
|
*/
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { useAdminFetch } from "../AdminShell";
|
||||||
|
import type { SiteConfig } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
const inputCls =
|
||||||
|
"w-full border border-line bg-b1 px-3 py-2 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1";
|
||||||
|
const labelCls = "mb-1 block font-mono-2 text-xs text-l2";
|
||||||
|
|
||||||
|
const FIELD_LABELS: Record<keyof SiteConfig, string> = {
|
||||||
|
site_title: "浏览器标题",
|
||||||
|
site_description: "站点描述(SEO)",
|
||||||
|
brand_name: "Header 品牌名",
|
||||||
|
copyright_name: "页脚版权名",
|
||||||
|
hero_line1: "首屏标签 · 第一段",
|
||||||
|
hero_line2: "首屏标签 · 第二段",
|
||||||
|
hero_tagline: "首屏标语",
|
||||||
|
hero_big_1: "首屏大字 · 行一",
|
||||||
|
hero_big_2: "首屏大字 · 行二",
|
||||||
|
hero_big_3: "首屏大字 · 行三",
|
||||||
|
intro_prefix: "自我介绍 · 前半句",
|
||||||
|
intro_suffix: "自我介绍 · 后半句",
|
||||||
|
intro_brand: "自我介绍 · 品牌位(口令解锁前显示 ■■■)",
|
||||||
|
about_p1: "关于 · 第一段",
|
||||||
|
about_p2: "关于 · 第二段(链接前)",
|
||||||
|
about_p2_link_label: "关于 · 链接文字",
|
||||||
|
about_p2_link_href: "关于 · 链接地址",
|
||||||
|
footer_headline: "页脚大字(用 | 分行)",
|
||||||
|
contact_email: "联系邮箱",
|
||||||
|
work_empty_headline: "作品区空状态 · 大字(用 | 分行)",
|
||||||
|
work_empty_note: "作品区空状态 · 说明",
|
||||||
|
work_empty_cta_prefix: "作品区空状态 · CTA 前缀",
|
||||||
|
work_empty_cta_suffix: "作品区空状态 · CTA 中缀",
|
||||||
|
work_empty_cta_action: "作品区空状态 · CTA 动作文字",
|
||||||
|
services_hero: "服务页大字(用 | 分行)",
|
||||||
|
services_submit_note: "服务页 · 提交说明",
|
||||||
|
};
|
||||||
|
|
||||||
|
const MULTILINE: (keyof SiteConfig)[] = [
|
||||||
|
"about_p1",
|
||||||
|
"about_p2",
|
||||||
|
"intro_prefix",
|
||||||
|
"intro_suffix",
|
||||||
|
"work_empty_note",
|
||||||
|
"services_submit_note",
|
||||||
|
];
|
||||||
|
|
||||||
|
const GROUP_TITLES: Record<string, string> = {
|
||||||
|
basic: "基础",
|
||||||
|
hero: "首屏",
|
||||||
|
about: "关于",
|
||||||
|
footer: "页脚",
|
||||||
|
empty: "作品区空状态",
|
||||||
|
services: "服务页",
|
||||||
|
};
|
||||||
|
|
||||||
|
const GROUPS: { id: string; keys: (keyof SiteConfig)[] }[] = [
|
||||||
|
{ id: "basic", keys: ["site_title", "site_description", "brand_name", "copyright_name"] },
|
||||||
|
{
|
||||||
|
id: "hero",
|
||||||
|
keys: [
|
||||||
|
"hero_line1",
|
||||||
|
"hero_line2",
|
||||||
|
"hero_tagline",
|
||||||
|
"hero_big_1",
|
||||||
|
"hero_big_2",
|
||||||
|
"hero_big_3",
|
||||||
|
"intro_prefix",
|
||||||
|
"intro_suffix",
|
||||||
|
"intro_brand",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ id: "about", keys: ["about_p1", "about_p2", "about_p2_link_label", "about_p2_link_href"] },
|
||||||
|
{ id: "footer", keys: ["footer_headline", "contact_email"] },
|
||||||
|
{
|
||||||
|
id: "empty",
|
||||||
|
keys: [
|
||||||
|
"work_empty_headline",
|
||||||
|
"work_empty_note",
|
||||||
|
"work_empty_cta_prefix",
|
||||||
|
"work_empty_cta_suffix",
|
||||||
|
"work_empty_cta_action",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ id: "services", keys: ["services_hero", "services_submit_note"] },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function SettingsAdminPage() {
|
||||||
|
const adminFetch = useAdminFetch();
|
||||||
|
const [config, setConfig] = useState<SiteConfig | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [saved, setSaved] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const [newPassword, setNewPassword] = useState("");
|
||||||
|
const [pwMsg, setPwMsg] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void (async () => {
|
||||||
|
const res = await adminFetch("/api/admin/config");
|
||||||
|
const data = (await res.json()) as { config?: SiteConfig };
|
||||||
|
setConfig(data.config ?? null);
|
||||||
|
})();
|
||||||
|
}, [adminFetch]);
|
||||||
|
|
||||||
|
const save = useCallback(async () => {
|
||||||
|
if (!config) return;
|
||||||
|
setSaving(true);
|
||||||
|
setError(null);
|
||||||
|
setSaved(false);
|
||||||
|
const res = await adminFetch("/api/admin/config", {
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify(config),
|
||||||
|
});
|
||||||
|
setSaving(false);
|
||||||
|
if (!res.ok) {
|
||||||
|
const data = (await res.json()) as { error?: string };
|
||||||
|
setError(data.error ?? "保存失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSaved(true);
|
||||||
|
window.setTimeout(() => setSaved(false), 2000);
|
||||||
|
}, [config, adminFetch]);
|
||||||
|
|
||||||
|
const changePassword = useCallback(async () => {
|
||||||
|
setPwMsg(null);
|
||||||
|
if (newPassword.length < 8) {
|
||||||
|
setPwMsg("密码至少 8 位");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const res = await adminFetch("/api/admin/password", {
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ password: newPassword }),
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as { error?: string };
|
||||||
|
if (!res.ok) {
|
||||||
|
setPwMsg(data.error ?? "修改失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setPwMsg("密码已更新,下次登录生效");
|
||||||
|
setNewPassword("");
|
||||||
|
}, [newPassword, adminFetch]);
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
return <p className="font-mono-2 text-sm text-l3">加载中…</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-8">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-bold text-2xl text-l1">配置</h1>
|
||||||
|
<p className="mt-1 font-mono-2 text-sm text-l3">
|
||||||
|
站点文案与信息,保存后前台即时生效
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
{saved && (
|
||||||
|
<span className="font-mono-2 text-xs text-l2">已保存 ✓</span>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={save}
|
||||||
|
disabled={saving}
|
||||||
|
className="cursor-pointer border border-l1 bg-l1 px-4 py-2 font-mono text-sm text-b1 hover:opacity-85 disabled:opacity-40"
|
||||||
|
>
|
||||||
|
{saving ? "保存中…" : "保存全部"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="border-l-2 border-selection pl-2 text-sm text-l1">{error}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{GROUPS.map((group) => (
|
||||||
|
<section key={group.id} className="border border-line bg-be p-5">
|
||||||
|
<h2 className="mb-4 font-semibold text-l1">
|
||||||
|
{GROUP_TITLES[group.id]}
|
||||||
|
</h2>
|
||||||
|
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||||
|
{group.keys.map((key) => (
|
||||||
|
<div
|
||||||
|
key={key}
|
||||||
|
className={MULTILINE.includes(key) ? "lg:col-span-2" : ""}
|
||||||
|
>
|
||||||
|
<label className={labelCls}>{FIELD_LABELS[key]}</label>
|
||||||
|
{MULTILINE.includes(key) ? (
|
||||||
|
<textarea
|
||||||
|
className={`${inputCls} min-h-20`}
|
||||||
|
value={config[key]}
|
||||||
|
onChange={(e) => setConfig({ ...config, [key]: e.target.value })}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={config[key]}
|
||||||
|
onChange={(e) => setConfig({ ...config, [key]: e.target.value })}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<section className="border border-line bg-be p-5">
|
||||||
|
<h2 className="mb-4 font-semibold text-l1">修改密码</h2>
|
||||||
|
<div className="flex flex-wrap items-end gap-3">
|
||||||
|
<div className="w-full max-w-xs">
|
||||||
|
<label className={labelCls}>新密码(至少 8 位)</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
className={inputCls}
|
||||||
|
value={newPassword}
|
||||||
|
onChange={(e) => setNewPassword(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={changePassword}
|
||||||
|
disabled={!newPassword}
|
||||||
|
className="cursor-pointer border border-line px-4 py-2 font-mono text-sm text-l2 hover:text-l1 hover:border-l2 disabled:opacity-40"
|
||||||
|
>
|
||||||
|
更新密码
|
||||||
|
</button>
|
||||||
|
{pwMsg && <span className="font-mono-2 text-xs text-l2">{pwMsg}</span>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,401 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* /virtheart/works — 作品管理:列表 + 新增/编辑。
|
||||||
|
* 单页内联编辑(终端风),字段与 lib/siteConfig 的 works 表对应。
|
||||||
|
*/
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { useAdminFetch } from "../AdminShell";
|
||||||
|
import type { WorkRow } from "@/lib/siteConfig";
|
||||||
|
|
||||||
|
const GRID_PRESETS = [
|
||||||
|
{ label: "大卡(8列居中)", value: "col-span-12 lg:col-span-8 lg:col-start-3" },
|
||||||
|
{ label: "中卡(6列)", value: "col-span-12 lg:col-span-6 xl:col-span-4" },
|
||||||
|
{ label: "宽左(5列)", value: "col-span-12 lg:col-start-1 lg:col-span-6 xl:col-span-5" },
|
||||||
|
{ label: "宽右(5列)", value: "col-span-12 lg:col-span-6 xl:col-span-5 lg:col-start-7 xl:col-start-7" },
|
||||||
|
{ label: "小卡(3列)", value: "col-span-6 lg:col-span-4 xl:col-span-3" },
|
||||||
|
{ label: "小卡右(3列)", value: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-10 xl:col-span-3" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const TYPE_OPTIONS = [
|
||||||
|
{ label: "文章", value: "post" },
|
||||||
|
{ label: "工具", value: "tools" },
|
||||||
|
{ label: "活动", value: "event" },
|
||||||
|
];
|
||||||
|
|
||||||
|
type Draft = {
|
||||||
|
id?: number;
|
||||||
|
slug?: string;
|
||||||
|
name: string;
|
||||||
|
year: string;
|
||||||
|
type: string;
|
||||||
|
href: string;
|
||||||
|
image_url: string;
|
||||||
|
hover_image_url: string;
|
||||||
|
grid_class: string;
|
||||||
|
coding_project: number;
|
||||||
|
sort_order: number;
|
||||||
|
published: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const EMPTY_DRAFT: Draft = {
|
||||||
|
name: "",
|
||||||
|
year: new Date().getFullYear().toString(),
|
||||||
|
type: "post",
|
||||||
|
href: "",
|
||||||
|
image_url: "",
|
||||||
|
hover_image_url: "",
|
||||||
|
grid_class: GRID_PRESETS[1].value,
|
||||||
|
coding_project: 0,
|
||||||
|
sort_order: 0,
|
||||||
|
published: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const inputCls =
|
||||||
|
"w-full border border-line bg-b1 px-3 py-2 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1";
|
||||||
|
const labelCls = "mb-1 block font-mono-2 text-xs text-l2";
|
||||||
|
|
||||||
|
export default function WorksAdminPage() {
|
||||||
|
const adminFetch = useAdminFetch();
|
||||||
|
const [works, setWorks] = useState<WorkRow[]>([]);
|
||||||
|
const [draft, setDraft] = useState<Draft | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [uploading, setUploading] = useState(false);
|
||||||
|
|
||||||
|
// 数据加载(async 内 setState,避免 effect 同步路径触发级联渲染)。
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
void (async () => {
|
||||||
|
const res = await adminFetch("/api/admin/works");
|
||||||
|
const data = (await res.json()) as { works?: WorkRow[] };
|
||||||
|
if (cancelled) return;
|
||||||
|
setWorks(data.works ?? []);
|
||||||
|
setLoading(false);
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [adminFetch]);
|
||||||
|
|
||||||
|
// mutation 后刷新列表(不回置 loading 骨架)。
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
const res = await adminFetch("/api/admin/works");
|
||||||
|
const data = (await res.json()) as { works?: WorkRow[] };
|
||||||
|
setWorks(data.works ?? []);
|
||||||
|
}, [adminFetch]);
|
||||||
|
|
||||||
|
const save = useCallback(async () => {
|
||||||
|
if (!draft) return;
|
||||||
|
setSaving(true);
|
||||||
|
setError(null);
|
||||||
|
const res = await adminFetch("/api/admin/works", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify(draft),
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as { error?: string };
|
||||||
|
setSaving(false);
|
||||||
|
if (!res.ok) {
|
||||||
|
setError(data.error ?? "保存失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDraft(null);
|
||||||
|
void load();
|
||||||
|
}, [draft, adminFetch, load]);
|
||||||
|
|
||||||
|
const remove = useCallback(
|
||||||
|
async (id: number) => {
|
||||||
|
if (!window.confirm(`确定删除作品 #${id}?`)) return;
|
||||||
|
await adminFetch(`/api/admin/works/${id}`, { method: "DELETE" });
|
||||||
|
void load();
|
||||||
|
},
|
||||||
|
[adminFetch, load]
|
||||||
|
);
|
||||||
|
|
||||||
|
const upload = useCallback(
|
||||||
|
async (file: File, field: "image_url" | "hover_image_url") => {
|
||||||
|
setUploading(true);
|
||||||
|
setError(null);
|
||||||
|
const form = new FormData();
|
||||||
|
form.append("file", file);
|
||||||
|
const res = await adminFetch("/api/admin/upload", {
|
||||||
|
method: "POST",
|
||||||
|
body: form,
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as { url?: string; error?: string };
|
||||||
|
setUploading(false);
|
||||||
|
if (!res.ok || !data.url) {
|
||||||
|
setError(data.error ?? "上传失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDraft((d) => (d ? { ...d, [field]: data.url as string } : d));
|
||||||
|
},
|
||||||
|
[adminFetch]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-bold text-2xl text-l1">作品</h1>
|
||||||
|
<p className="mt-1 font-mono-2 text-sm text-l3">
|
||||||
|
首页「精选作品」网格按排序展示已发布条目
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setDraft({ ...EMPTY_DRAFT })}
|
||||||
|
className="cursor-pointer border border-l1 bg-l1 px-4 py-2 font-mono text-sm text-b1 hover:opacity-85"
|
||||||
|
>
|
||||||
|
+ 新作品
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="border-l-2 border-selection pl-2 text-sm text-l1">{error}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<p className="font-mono-2 text-sm text-l3">加载中…</p>
|
||||||
|
) : works.length === 0 && !draft ? (
|
||||||
|
<div className="border border-dashed border-line p-8 text-center">
|
||||||
|
<p className="font-mono-2 text-sm text-l2">
|
||||||
|
暂无作品——首页作品区当前展示「制作中」占位。
|
||||||
|
</p>
|
||||||
|
<p className="mt-1 font-mono-2 text-xs text-l3">
|
||||||
|
添加第一个作品后,占位自动消失。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
works.length > 0 && (
|
||||||
|
<ul className="flex flex-col divide-y divide-line border border-line bg-be">
|
||||||
|
{works.map((w) => (
|
||||||
|
<li key={w.id} className="flex flex-wrap items-center gap-x-4 gap-y-2 p-4">
|
||||||
|
{w.image_url && (
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element -- 后台缩略图
|
||||||
|
<img
|
||||||
|
src={w.image_url}
|
||||||
|
alt=""
|
||||||
|
className="h-12 w-16 border border-line object-cover"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="truncate text-sm text-l1">
|
||||||
|
{w.name}
|
||||||
|
{!w.published && (
|
||||||
|
<span className="ml-2 border border-line px-1 font-mono-2 text-xs text-l3">
|
||||||
|
未发布
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="font-mono-2 text-xs text-l3">
|
||||||
|
{w.year} · {w.slug} · 排序 {w.sort_order}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
setDraft({
|
||||||
|
id: w.id,
|
||||||
|
slug: w.slug,
|
||||||
|
name: w.name,
|
||||||
|
year: w.year,
|
||||||
|
type: w.type,
|
||||||
|
href: w.href,
|
||||||
|
image_url: w.image_url,
|
||||||
|
hover_image_url: w.hover_image_url,
|
||||||
|
grid_class: w.grid_class,
|
||||||
|
coding_project: w.coding_project,
|
||||||
|
sort_order: w.sort_order,
|
||||||
|
published: w.published,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
className="cursor-pointer font-mono text-sm text-l2 hover:text-l1"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => remove(w.id)}
|
||||||
|
className="cursor-pointer font-mono text-sm text-l3 hover:text-l1"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
|
{draft && (
|
||||||
|
<div className="fixed inset-0 z-50 flex justify-center items-center overflow-y-auto bg-b1/80 p-4">
|
||||||
|
<div className="w-full max-w-2xl border border-line bg-be p-6 my-8">
|
||||||
|
<h2 className="mb-5 font-bold text-lg text-l1">
|
||||||
|
{draft.id ? `编辑作品 #${draft.id}` : "新增作品"}
|
||||||
|
</h2>
|
||||||
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
|
<div className="sm:col-span-2">
|
||||||
|
<label className={labelCls}>名称 *</label>
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.name}
|
||||||
|
onChange={(e) => setDraft({ ...draft, name: e.target.value })}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelCls}>年份</label>
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.year}
|
||||||
|
onChange={(e) => setDraft({ ...draft, year: e.target.value })}
|
||||||
|
placeholder="2026"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelCls}>类型</label>
|
||||||
|
<select
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.type}
|
||||||
|
onChange={(e) => setDraft({ ...draft, type: e.target.value })}
|
||||||
|
>
|
||||||
|
{TYPE_OPTIONS.map((o) => (
|
||||||
|
<option key={o.value} value={o.value}>
|
||||||
|
{o.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="sm:col-span-2">
|
||||||
|
<label className={labelCls}>链接(外链 https://… 或站内 /path,留空则卡片不可点击)</label>
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.href}
|
||||||
|
onChange={(e) => setDraft({ ...draft, href: e.target.value })}
|
||||||
|
placeholder="https://example.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelCls}>封面图</label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.image_url}
|
||||||
|
onChange={(e) => setDraft({ ...draft, image_url: e.target.value })}
|
||||||
|
placeholder="/work/xxx.png"
|
||||||
|
/>
|
||||||
|
<label className="shrink-0 cursor-pointer border border-line px-3 py-2 font-mono-2 text-xs text-l2 hover:text-l1 hover:border-l2">
|
||||||
|
{uploading ? "…" : "上传"}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept="image/png,image/jpeg,image/webp"
|
||||||
|
className="hidden"
|
||||||
|
onChange={(e) => {
|
||||||
|
const f = e.target.files?.[0];
|
||||||
|
if (f) void upload(f, "image_url");
|
||||||
|
e.target.value = "";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelCls}>悬停图(可选)</label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<input
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.hover_image_url}
|
||||||
|
onChange={(e) => setDraft({ ...draft, hover_image_url: e.target.value })}
|
||||||
|
placeholder="/work/xxx-hover.png"
|
||||||
|
/>
|
||||||
|
<label className="shrink-0 cursor-pointer border border-line px-3 py-2 font-mono-2 text-xs text-l2 hover:text-l1 hover:border-l2">
|
||||||
|
{uploading ? "…" : "上传"}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept="image/png,image/jpeg,image/webp"
|
||||||
|
className="hidden"
|
||||||
|
onChange={(e) => {
|
||||||
|
const f = e.target.files?.[0];
|
||||||
|
if (f) void upload(f, "hover_image_url");
|
||||||
|
e.target.value = "";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="sm:col-span-2">
|
||||||
|
<label className={labelCls}>网格位置</label>
|
||||||
|
<select
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.grid_class}
|
||||||
|
onChange={(e) => setDraft({ ...draft, grid_class: e.target.value })}
|
||||||
|
>
|
||||||
|
{GRID_PRESETS.map((o) => (
|
||||||
|
<option key={o.value} value={o.value}>
|
||||||
|
{o.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelCls}>排序(小的在前)</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className={inputCls}
|
||||||
|
value={draft.sort_order}
|
||||||
|
onChange={(e) =>
|
||||||
|
setDraft({ ...draft, sort_order: Number(e.target.value) || 0 })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-end gap-6 pb-1">
|
||||||
|
<label className="flex cursor-pointer items-center gap-2 text-sm text-l1">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={draft.published === 1}
|
||||||
|
onChange={(e) =>
|
||||||
|
setDraft({ ...draft, published: e.target.checked ? 1 : 0 })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
发布
|
||||||
|
</label>
|
||||||
|
<label className="flex cursor-pointer items-center gap-2 text-sm text-l1">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={draft.coding_project === 1}
|
||||||
|
onChange={(e) =>
|
||||||
|
setDraft({ ...draft, coding_project: e.target.checked ? 1 : 0 })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
代码项目角标
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-6 flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={save}
|
||||||
|
disabled={saving || !draft.name.trim()}
|
||||||
|
className="cursor-pointer border border-l1 bg-l1 px-5 py-2 font-mono text-sm text-b1 hover:opacity-85 disabled:opacity-40"
|
||||||
|
>
|
||||||
|
{saving ? "保存中…" : "保存"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setDraft(null)}
|
||||||
|
className="cursor-pointer border border-line px-5 py-2 font-mono text-sm text-l2 hover:text-l1"
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "登录",
|
||||||
|
robots: { index: false, follow: false },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function VirtheartLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{ children: React.ReactNode }>) {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* /virtheart/login — 后台登录页。
|
||||||
|
* 设计语言与主站对齐:暗底、等宽字体、点阵网格、scramble 式聚焦;
|
||||||
|
* 不用传统后台模板。登录成功 → /virtheart/dashboard。
|
||||||
|
*/
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
|
export default function VirtheartLoginPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
const submit = useCallback(
|
||||||
|
async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (busy) return;
|
||||||
|
setBusy(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/admin/login", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ username, password }),
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as { error?: string };
|
||||||
|
if (!res.ok) {
|
||||||
|
setError(data.error ?? "登录失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
router.replace("/virtheart/dashboard");
|
||||||
|
} catch {
|
||||||
|
setError("网络错误,请重试");
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[busy, username, password, router]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main
|
||||||
|
className="min-h-screen flex justify-center items-center bg-b1 px-4"
|
||||||
|
style={{
|
||||||
|
backgroundImage: "radial-gradient(var(--grid-dot) 1px, transparent 1px)",
|
||||||
|
backgroundSize: "22px 22px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<form
|
||||||
|
onSubmit={submit}
|
||||||
|
className="w-full max-w-sm border border-line bg-be p-8"
|
||||||
|
>
|
||||||
|
<div className="mb-8 flex flex-col gap-1">
|
||||||
|
<span className="font-mono-2 text-xs text-l3 uppercase tracking-widest">
|
||||||
|
virtheart · control
|
||||||
|
</span>
|
||||||
|
<h1 className="font-bold text-2xl text-l1 leading-tight">
|
||||||
|
后台登录
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label className="mb-1 block font-mono-2 text-xs text-l2">
|
||||||
|
用户名
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
autoComplete="username"
|
||||||
|
autoFocus
|
||||||
|
className="mb-4 w-full border border-line bg-b1 px-3 py-2.5 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label className="mb-1 block font-mono-2 text-xs text-l2">
|
||||||
|
密码
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
autoComplete="current-password"
|
||||||
|
className="mb-2 w-full border border-line bg-b1 px-3 py-2.5 font-mono text-sm text-l1 outline-none transition-colors focus:border-l1"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="mt-2 border-l-2 border-selection pl-2 text-sm text-l1" role="alert">
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={busy || !username || !password}
|
||||||
|
className="mt-6 w-full border border-l1 bg-l1 py-3 font-mono text-sm text-b1 uppercase tracking-widest transition-opacity disabled:opacity-40 cursor-pointer disabled:cursor-not-allowed hover:opacity-85"
|
||||||
|
>
|
||||||
|
{busy ? "验证中…" : "进入控制台"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p className="mt-6 font-mono-2 text-xs text-l3">
|
||||||
|
仅限站点所有者访问 · 会话 7 天有效
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { isAdmin } from "@/lib/auth";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* /virtheart — 后台暗门入口。
|
||||||
|
* 未登录 → /virtheart/login;已登录 → /virtheart/dashboard。
|
||||||
|
* 该路径不进站点地图、不进导航,仅手动访问。
|
||||||
|
*/
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export default async function VirtheartEntry() {
|
||||||
|
if (await isAdmin()) {
|
||||||
|
redirect("/virtheart/dashboard");
|
||||||
|
}
|
||||||
|
redirect("/virtheart/login");
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ import { CONTACT_EMAIL } from "@/lib/socials";
|
|||||||
* - 微信:无链接,点击弹出二维码浮层(移动端无 hover 也能查看)。
|
* - 微信:无链接,点击弹出二维码浮层(移动端无 hover 也能查看)。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// CONTACT_EMAIL 来自 @/lib/socials(与空作品区 CTA 共享)。
|
// CONTACT_EMAIL 作为默认值 fallback;页面级会传入 site_config 的 contact_email。
|
||||||
|
|
||||||
const dottedLink =
|
const dottedLink =
|
||||||
"block before:absolute relative before:inset-0 p-2 lg:hover:before:border-l1 before:border-2 before:border-transparent active:before:border-l1 before:border-dotted uppercase before:content-[''] before:transition-colors before:duration-200 cursor-pointer pointer-events-auto before:pointer-events-none";
|
"block before:absolute relative before:inset-0 p-2 lg:hover:before:border-l1 before:border-2 before:border-transparent active:before:border-l1 before:border-dotted uppercase before:content-[''] before:transition-colors before:duration-200 cursor-pointer pointer-events-auto before:pointer-events-none";
|
||||||
@@ -85,7 +85,11 @@ function QrPreview({ social }: { social: Social }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FooterSection() {
|
export default function FooterSection({
|
||||||
|
contactEmail = CONTACT_EMAIL,
|
||||||
|
}: {
|
||||||
|
contactEmail?: string;
|
||||||
|
}) {
|
||||||
const [activeQr, setActiveQr] = useState<Social | null>(null);
|
const [activeQr, setActiveQr] = useState<Social | null>(null);
|
||||||
const closeQr = useCallback(() => setActiveQr(null), []);
|
const closeQr = useCallback(() => setActiveQr(null), []);
|
||||||
|
|
||||||
@@ -138,9 +142,9 @@ export default function FooterSection() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="absolute inset-0 flex flex-col justify-end px-4 lg:px-14 py-18 lg:py-24 font-mono-2 text-sm lg:text-base">
|
<div className="absolute inset-0 flex flex-col justify-end px-4 lg:px-14 py-18 lg:py-24 font-mono-2 text-sm lg:text-base">
|
||||||
<div className="flex lg:flex-row flex-col justify-between w-full">
|
<div className="flex lg:flex-row flex-col justify-between w-full">
|
||||||
<a className={dottedLink} href={`mailto:${CONTACT_EMAIL}`}>
|
<a className={dottedLink} href={`mailto:${contactEmail}`}>
|
||||||
<ScrambleReveal
|
<ScrambleReveal
|
||||||
text={CONTACT_EMAIL}
|
text={contactEmail}
|
||||||
startDelayMs={300}
|
startDelayMs={300}
|
||||||
scrambleColors={false}
|
scrambleColors={false}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import ScrambleReveal from "@/components/dom/ScrambleReveal";
|
|||||||
import { useShellMedia, type ThemeSetting } from "@/lib/shellMedia";
|
import { useShellMedia, type ThemeSetting } from "@/lib/shellMedia";
|
||||||
import { useBgm } from "@/lib/useBgm";
|
import { useBgm } from "@/lib/useBgm";
|
||||||
import { scrollEnv } from "@/lib/scrollEnv";
|
import { scrollEnv } from "@/lib/scrollEnv";
|
||||||
|
import { useRouteTransitionController } from "@/lib/routeTransition";
|
||||||
import {
|
import {
|
||||||
useArrowFullscreenPastThreshold,
|
useArrowFullscreenPastThreshold,
|
||||||
ARROW_FULLSCREEN_DOM_COLOR_TRANSITION,
|
ARROW_FULLSCREEN_DOM_COLOR_TRANSITION,
|
||||||
@@ -49,9 +50,16 @@ function useBrowserName(): string {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header({
|
||||||
|
brandName = "北极新一",
|
||||||
|
copyrightName = "北极新一",
|
||||||
|
}: {
|
||||||
|
brandName?: string;
|
||||||
|
copyrightName?: string;
|
||||||
|
}) {
|
||||||
const { theme, setTheme, soundEnabled, setSoundEnabled } = useShellMedia();
|
const { theme, setTheme, soundEnabled, setSoundEnabled } = useShellMedia();
|
||||||
useBgm(soundEnabled);
|
useBgm(soundEnabled);
|
||||||
|
const { startNavigation } = useRouteTransitionController();
|
||||||
// Arrow-fullscreen state: past the 0.5 reveal threshold the whole header
|
// Arrow-fullscreen state: past the 0.5 reveal threshold the whole header
|
||||||
// (and the hyper-space section) turn white over the black stripe base
|
// (and the hyper-space section) turn white over the black stripe base
|
||||||
// (original X = useArrowFullscreenPastThreshold()).
|
// (original X = useArrowFullscreenPastThreshold()).
|
||||||
@@ -199,7 +207,7 @@ export default function Header() {
|
|||||||
style={{ fontVariationSettings: '"wght" 700, "wdth" 120' }}
|
style={{ fontVariationSettings: '"wght" 700, "wdth" 120' }}
|
||||||
href="/"
|
href="/"
|
||||||
>
|
>
|
||||||
<ScrambleReveal text="北极新一" startDelayMs={300} scrambleColors={false} />
|
<ScrambleReveal text={brandName} startDelayMs={300} scrambleColors={false} />
|
||||||
</a>
|
</a>
|
||||||
<div className="hidden lg:flex flex-wrap justify-between items-center gap-x-3 gap-y-2 pointer-events-auto basis-1/2 xl:basis-1/3">
|
<div className="hidden lg:flex flex-wrap justify-between items-center gap-x-3 gap-y-2 pointer-events-auto basis-1/2 xl:basis-1/3">
|
||||||
<button
|
<button
|
||||||
@@ -209,6 +217,13 @@ export default function Header() {
|
|||||||
>
|
>
|
||||||
<ScrambleReveal text="作品" startDelayMs={300} scrambleColors={false} />
|
<ScrambleReveal text="作品" startDelayMs={300} scrambleColors={false} />
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`${dotted} p-2 uppercase cursor-pointer`}
|
||||||
|
onClick={() => startNavigation("/services")}
|
||||||
|
>
|
||||||
|
<ScrambleReveal text="服务" startDelayMs={300} scrambleColors={false} />
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`${dotted} p-2 uppercase cursor-pointer`}
|
className={`${dotted} p-2 uppercase cursor-pointer`}
|
||||||
@@ -342,7 +357,7 @@ export default function Header() {
|
|||||||
{/* 版权行 — 替代原站的 RotatingGlobe。 */}
|
{/* 版权行 — 替代原站的 RotatingGlobe。 */}
|
||||||
<span className="hidden lg:inline p-2">
|
<span className="hidden lg:inline p-2">
|
||||||
<ScrambleReveal
|
<ScrambleReveal
|
||||||
text={`北极新一 (c) ${year}`}
|
text={`${copyrightName} (c) ${year}`}
|
||||||
startDelayMs={300}
|
startDelayMs={300}
|
||||||
letterDelayMs={40}
|
letterDelayMs={40}
|
||||||
scrambleColors={false}
|
scrambleColors={false}
|
||||||
|
|||||||
@@ -110,21 +110,31 @@ export default function PasscodeRevealText({
|
|||||||
className,
|
className,
|
||||||
startDelayMs = 300,
|
startDelayMs = 300,
|
||||||
letterDelayMs = 10,
|
letterDelayMs = 10,
|
||||||
|
prefix,
|
||||||
|
suffix,
|
||||||
|
brandName = "北极新一",
|
||||||
}: {
|
}: {
|
||||||
className?: string;
|
className?: string;
|
||||||
startDelayMs?: number;
|
startDelayMs?: number;
|
||||||
letterDelayMs?: number;
|
letterDelayMs?: number;
|
||||||
|
/** 自我介绍前半句(site_config.intro_prefix,后台可改) */
|
||||||
|
prefix: string;
|
||||||
|
/** 自我介绍后半句(site_config.intro_suffix) */
|
||||||
|
suffix: string;
|
||||||
|
/** 介绍文字里的自称(品牌名) */
|
||||||
|
brandName?: string;
|
||||||
}) {
|
}) {
|
||||||
const allowed = usePasscodeAllowed(SCOPE);
|
const allowed = usePasscodeAllowed(SCOPE);
|
||||||
|
const introPrefix = prefix.replace("北极新一", brandName);
|
||||||
const parts = [
|
const parts = [
|
||||||
"我是北极新一,一名横跨设计与工程的全栈开发者:Web 前端与后端、Flutter 客户端、AI 应用开发都有实践,也从产品设计一路做到工程落地。工作之外,我常在 ",
|
introPrefix,
|
||||||
{
|
{
|
||||||
length: BRAND_LEN,
|
length: BRAND_LEN,
|
||||||
scramble: allowed ? BRAND : passcodeLockedPlaceholderText(),
|
scramble: allowed ? BRAND : passcodeLockedPlaceholderText(),
|
||||||
className: allowed ? undefined : PASSCODE_LOCKED_SCRAMBLE_CLASS,
|
className: allowed ? undefined : PASSCODE_LOCKED_SCRAMBLE_CLASS,
|
||||||
settled: <RevealLabelButton />,
|
settled: <RevealLabelButton />,
|
||||||
},
|
},
|
||||||
" 上记录与分享这些探索。",
|
suffix,
|
||||||
];
|
];
|
||||||
return (
|
return (
|
||||||
<ScrambleReveal
|
<ScrambleReveal
|
||||||
|
|||||||
@@ -0,0 +1,247 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SliderCaptcha — 滑块拼图验证码(全屏居中弹层)。
|
||||||
|
*
|
||||||
|
* - 打开时向 /api/captcha/new 要 challenge:{ token, puzzleX }(缺口位置,
|
||||||
|
* 500 坐标系)。
|
||||||
|
* - 轨道点阵背景 + 缺口槽(虚线 lime 框);拖动滑块使图案连续对齐缺口。
|
||||||
|
* - 松手提交 { token, x } → 校验通过返回一次性 submitToken(5 分钟单次),
|
||||||
|
* 由父组件携带它提交咨询接口。
|
||||||
|
* - 校验失败抖动重置;challenge 失效自动换新。
|
||||||
|
*/
|
||||||
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
|
const COORD_SPACE = 500; // 服务器缺口坐标系宽度
|
||||||
|
const PIECE_W = 48;
|
||||||
|
|
||||||
|
export default function SliderCaptcha({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onVerified,
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onVerified: (submitToken: string) => void;
|
||||||
|
}) {
|
||||||
|
const [challenge, setChallenge] = useState<{
|
||||||
|
token: string;
|
||||||
|
puzzleX: number;
|
||||||
|
} | null>(null);
|
||||||
|
const [dragX, setDragX] = useState(0);
|
||||||
|
const [status, setStatus] = useState<"idle" | "dragging" | "checking" | "error">(
|
||||||
|
"idle"
|
||||||
|
);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const trackRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const trackPxRef = useRef(300);
|
||||||
|
const [trackPx, setTrackPx] = useState(300);
|
||||||
|
const [nonce, setNonce] = useState(0); // 失效后重取 challenge
|
||||||
|
const startXRef = useRef(0);
|
||||||
|
const startDragRef = useRef(0);
|
||||||
|
const [shake, setShake] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/captcha/new", { method: "POST" });
|
||||||
|
const data = (await res.json()) as { token?: string; puzzleX?: number };
|
||||||
|
if (cancelled) return;
|
||||||
|
if (data.token && typeof data.puzzleX === "number") {
|
||||||
|
setChallenge({ token: data.token, puzzleX: data.puzzleX });
|
||||||
|
} else {
|
||||||
|
setError("验证码加载失败");
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
if (!cancelled) setError("网络错误,请重试");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [open, nonce]);
|
||||||
|
|
||||||
|
// 轨道实际像素宽度(500 坐标系缩放)——ResizeObserver 的初始通知是
|
||||||
|
// 异步派发的,不在 effect 里同步 setState。
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const el = trackRef.current;
|
||||||
|
if (!el) return;
|
||||||
|
const apply = (w: number) => {
|
||||||
|
const px = Math.round(w) || 300;
|
||||||
|
trackPxRef.current = px;
|
||||||
|
setTrackPx(px);
|
||||||
|
};
|
||||||
|
// observe 的初始尺寸通知由浏览器异步派发,这里不手动同步测量
|
||||||
|
// (避免在 effect 内同步 setState 触发级联渲染)。
|
||||||
|
const ro = new ResizeObserver((entries) => {
|
||||||
|
apply(entries[0].contentRect.width);
|
||||||
|
});
|
||||||
|
ro.observe(el);
|
||||||
|
return () => ro.disconnect();
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const verify = useCallback(
|
||||||
|
async (finalDragX: number) => {
|
||||||
|
if (!challenge) return;
|
||||||
|
setStatus("checking");
|
||||||
|
const track = trackPxRef.current || 1;
|
||||||
|
const x = Math.round((finalDragX / track) * COORD_SPACE);
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/captcha/verify", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ token: challenge.token, x }),
|
||||||
|
});
|
||||||
|
const data = (await res.json()) as {
|
||||||
|
ok?: boolean;
|
||||||
|
submitToken?: string;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
if (res.ok && data.submitToken) {
|
||||||
|
setStatus("idle");
|
||||||
|
onVerified(data.submitToken);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setStatus("error");
|
||||||
|
setError(data.error ?? "位置不对,再试一次");
|
||||||
|
setShake(true);
|
||||||
|
window.setTimeout(() => setShake(false), 400);
|
||||||
|
if (data.error?.includes("失效") || data.error?.includes("过期")) {
|
||||||
|
setChallenge(null);
|
||||||
|
setDragX(0);
|
||||||
|
setNonce((n) => n + 1);
|
||||||
|
} else {
|
||||||
|
setDragX(0);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
setStatus("error");
|
||||||
|
setError("网络错误,请重试");
|
||||||
|
setDragX(0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[challenge, onVerified]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!open) return null;
|
||||||
|
|
||||||
|
const slotX = challenge ? (challenge.puzzleX / COORD_SPACE) * trackPx : 0;
|
||||||
|
const maxDrag = Math.max(0, trackPx - PIECE_W);
|
||||||
|
|
||||||
|
const onPointerDown = (e: React.PointerEvent) => {
|
||||||
|
if (status === "checking") return;
|
||||||
|
(e.target as HTMLElement).setPointerCapture?.(e.pointerId);
|
||||||
|
startXRef.current = e.clientX;
|
||||||
|
startDragRef.current = dragX;
|
||||||
|
setStatus("dragging");
|
||||||
|
};
|
||||||
|
const onPointerMove = (e: React.PointerEvent) => {
|
||||||
|
if (status !== "dragging") return;
|
||||||
|
const next = startDragRef.current + (e.clientX - startXRef.current);
|
||||||
|
setDragX(Math.max(0, Math.min(maxDrag, next)));
|
||||||
|
};
|
||||||
|
const onPointerUp = () => {
|
||||||
|
if (status !== "dragging") return;
|
||||||
|
void verify(dragX);
|
||||||
|
};
|
||||||
|
|
||||||
|
const dottedBg: React.CSSProperties = {
|
||||||
|
backgroundImage: "radial-gradient(var(--grid-dot) 1px, transparent 1px)",
|
||||||
|
backgroundSize: "12px 12px",
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="inset-0 z-[80] fixed flex justify-center items-center bg-b1/85 p-4"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-label="滑块验证"
|
||||||
|
onClick={(e) => {
|
||||||
|
if (e.target === e.currentTarget) onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="w-full max-w-sm border border-line bg-be p-5 select-none">
|
||||||
|
<div className="mb-4 flex items-center justify-between">
|
||||||
|
<span className="font-mono-2 text-xs uppercase tracking-widest text-l3">
|
||||||
|
安全验证
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onClose}
|
||||||
|
aria-label="关闭验证"
|
||||||
|
className="cursor-pointer font-mono text-sm text-l3 hover:text-l1"
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 拼图轨道 */}
|
||||||
|
<div
|
||||||
|
ref={trackRef}
|
||||||
|
className="relative h-14 overflow-hidden border border-line bg-b1"
|
||||||
|
style={dottedBg}
|
||||||
|
>
|
||||||
|
{/* 缺口槽 */}
|
||||||
|
{challenge && (
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
className="absolute top-0 h-full border-2 border-dashed border-(--selection-bg) bg-black/30"
|
||||||
|
style={{ left: slotX, width: PIECE_W }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{/* 可拖动滑块(点阵与轨道同源,拖到缺口处图案连续) */}
|
||||||
|
<div
|
||||||
|
role="slider"
|
||||||
|
aria-label="拖动滑块完成拼图"
|
||||||
|
aria-valuenow={Math.round((dragX / maxDrag) * 100) || 0}
|
||||||
|
aria-valuemin={0}
|
||||||
|
aria-valuemax={100}
|
||||||
|
tabIndex={0}
|
||||||
|
className={`absolute top-0 h-full cursor-grab border-2 border-l1 bg-b1 active:cursor-grabbing ${
|
||||||
|
shake ? "animate-[vh-shake_0.35s_ease-in-out]" : ""
|
||||||
|
}`}
|
||||||
|
style={{
|
||||||
|
left: dragX,
|
||||||
|
width: PIECE_W,
|
||||||
|
...dottedBg,
|
||||||
|
backgroundPositionX: -dragX,
|
||||||
|
}}
|
||||||
|
onPointerDown={onPointerDown}
|
||||||
|
onPointerMove={onPointerMove}
|
||||||
|
onPointerUp={onPointerUp}
|
||||||
|
onPointerCancel={onPointerUp}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "ArrowRight") {
|
||||||
|
e.preventDefault();
|
||||||
|
setDragX((x) => Math.min(maxDrag, x + PIECE_W));
|
||||||
|
void verify(Math.min(maxDrag, dragX + PIECE_W));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute inset-0 flex justify-center items-center font-mono text-l1">
|
||||||
|
➜
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 进度条 */}
|
||||||
|
<div className="mt-3 h-1 w-full bg-line">
|
||||||
|
<div
|
||||||
|
className="h-full bg-(--selection-bg) transition-[width] duration-75"
|
||||||
|
style={{ width: `${maxDrag ? (dragX / maxDrag) * 100 : 0}%` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="mt-3 font-mono-2 text-xs text-l2">
|
||||||
|
{status === "checking"
|
||||||
|
? "校验中…"
|
||||||
|
: error
|
||||||
|
? error
|
||||||
|
: "拖动滑块,将虚线框与图案对齐"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import {
|
import {
|
||||||
SELECTED_WORK_SECTION_ID,
|
SELECTED_WORK_SECTION_ID,
|
||||||
WORK_ITEMS,
|
WORK_ITEMS as STATIC_WORK_ITEMS,
|
||||||
type WorkItem,
|
type WorkItem,
|
||||||
} from "@/lib/workItems";
|
} from "@/lib/workItems";
|
||||||
import {
|
import {
|
||||||
@@ -45,6 +45,8 @@ import { CONTACT_EMAIL, SOCIAL_LINKS } from "@/lib/socials";
|
|||||||
// Module-level cache mirroring the original `o` (persists across remounts).
|
// Module-level cache mirroring the original `o` (persists across remounts).
|
||||||
const ratioCache: Record<string, string> = {};
|
const ratioCache: Record<string, string> = {};
|
||||||
|
|
||||||
|
const DEFAULT_EMPTY_NOTE = "把它们当作这个站的「加载动画」——完成后会在这里逐个揭晓。";
|
||||||
|
|
||||||
/** 作品卡片右下角类型角标(post 不显示角标)。 */
|
/** 作品卡片右下角类型角标(post 不显示角标)。 */
|
||||||
const TYPE_LABELS: Record<WorkItem["type"], string> = {
|
const TYPE_LABELS: Record<WorkItem["type"], string> = {
|
||||||
post: "文章",
|
post: "文章",
|
||||||
@@ -67,29 +69,56 @@ const EMPTY_PLACEHOLDERS = [
|
|||||||
},
|
},
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export default function WorkSection() {
|
export type WorkSectionProps = {
|
||||||
|
/** 服务端从 works 表读出的作品(published,camelCase 已映射) */
|
||||||
|
items?: WorkItem[];
|
||||||
|
/** 空状态文案(site_config.work_empty_*,后台可改) */
|
||||||
|
emptyText?: {
|
||||||
|
headline: string;
|
||||||
|
note: string;
|
||||||
|
ctaPrefix: string;
|
||||||
|
ctaSuffix: string;
|
||||||
|
ctaAction: string;
|
||||||
|
};
|
||||||
|
/** 空状态 CTA 邮箱(site_config.contact_email) */
|
||||||
|
contactEmail?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function WorkSection({
|
||||||
|
items,
|
||||||
|
emptyText,
|
||||||
|
contactEmail,
|
||||||
|
}: WorkSectionProps = {}) {
|
||||||
const [ratios, setRatios] = useState<Record<string, string>>({ ...ratioCache });
|
const [ratios, setRatios] = useState<Record<string, string>>({ ...ratioCache });
|
||||||
const [colWidth, setColWidth] = useState(0);
|
const [colWidth, setColWidth] = useState(0);
|
||||||
const gridRef = useRef<HTMLDivElement | null>(null);
|
const gridRef = useRef<HTMLDivElement | null>(null);
|
||||||
const lookup = usePasscodeAccessLookup();
|
const lookup = usePasscodeAccessLookup();
|
||||||
|
|
||||||
|
// 服务端传入的作品优先;直接渲染 <WorkSection />(无 props)时回退为
|
||||||
|
// 静态 WORK_ITEMS(当前为空数组 → 空状态占位)。
|
||||||
|
const sourceItems = useMemo(
|
||||||
|
() => items ?? STATIC_WORK_ITEMS,
|
||||||
|
[items]
|
||||||
|
);
|
||||||
|
|
||||||
// Original `f` — passcode-protected items stay hidden until unlocked.
|
// Original `f` — passcode-protected items stay hidden until unlocked.
|
||||||
const visibleItems = useMemo(
|
const visibleItems = useMemo(
|
||||||
() => WORK_ITEMS.filter((item) => !item.passcodeProtected || lookup(item.href)),
|
() =>
|
||||||
[lookup]
|
sourceItems.filter((item) => !item.passcodeProtected || lookup(item.href)),
|
||||||
|
[sourceItems, lookup]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Register canvas layer defs for every item (locked ones simply have no
|
// Register canvas layer defs for every item (locked ones simply have no
|
||||||
// target on screen; idempotent data write — version bump happens once
|
// target on screen; idempotent data write — version bump happens once
|
||||||
// targets exist, in the effect).
|
// targets exist, in the effect).
|
||||||
useMemo(() => {
|
useMemo(() => {
|
||||||
for (const item of WORK_ITEMS) {
|
for (const item of sourceItems) {
|
||||||
setLayerDef(item.href, {
|
setLayerDef(item.href, {
|
||||||
imageUrl: item.imageUrl,
|
imageUrl: item.imageUrl,
|
||||||
hoverImageUrl: item.hoverImageUrl,
|
hoverImageUrl: item.hoverImageUrl,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, []);
|
}, [sourceItems]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
touchLayerRegistry();
|
touchLayerRegistry();
|
||||||
@@ -146,7 +175,10 @@ export default function WorkSection() {
|
|||||||
style={{ rowGap: `${colWidth}px` }}
|
style={{ rowGap: `${colWidth}px` }}
|
||||||
>
|
>
|
||||||
{showEmpty ? (
|
{showEmpty ? (
|
||||||
<EmptyWorkState />
|
<EmptyWorkState
|
||||||
|
emptyText={emptyText}
|
||||||
|
contactEmail={contactEmail}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
visibleItems.map((item) => (
|
visibleItems.map((item) => (
|
||||||
<WorkCard key={item.href} item={item} ratio={ratios[item.imageUrl]} />
|
<WorkCard key={item.href} item={item} ratio={ratios[item.imageUrl]} />
|
||||||
@@ -163,7 +195,17 @@ export default function WorkSection() {
|
|||||||
* 占位卡刻意保留真实卡片的网格位置与标签行结构,但视觉是纯 DOM 点阵 +
|
* 占位卡刻意保留真实卡片的网格位置与标签行结构,但视觉是纯 DOM 点阵 +
|
||||||
* 虚线框(不注册 WebGL 图层),hover 不会触发 canvas 投影。
|
* 虚线框(不注册 WebGL 图层),hover 不会触发 canvas 投影。
|
||||||
*/
|
*/
|
||||||
function EmptyWorkState() {
|
function EmptyWorkState({
|
||||||
|
emptyText,
|
||||||
|
contactEmail,
|
||||||
|
}: {
|
||||||
|
emptyText?: WorkSectionProps["emptyText"];
|
||||||
|
contactEmail?: string;
|
||||||
|
}) {
|
||||||
|
const headlineLines = (
|
||||||
|
emptyText?.headline ?? "第一批作品|正在打磨"
|
||||||
|
).split("|");
|
||||||
|
const email = contactEmail ?? CONTACT_EMAIL;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="col-span-12 flex flex-col gap-4 p-2">
|
<div className="col-span-12 flex flex-col gap-4 p-2">
|
||||||
@@ -171,32 +213,40 @@ function EmptyWorkState() {
|
|||||||
className="font-bold text-[7.2svw] lg:text-[4svw] leading-none"
|
className="font-bold text-[7.2svw] lg:text-[4svw] leading-none"
|
||||||
style={{ fontVariationSettings: '"wdth" 120' }}
|
style={{ fontVariationSettings: '"wdth" 120' }}
|
||||||
>
|
>
|
||||||
<ScrambleReveal text="第一批作品" startDelayMs={300} />
|
{headlineLines.map((line, i) => (
|
||||||
<br />
|
<span key={i}>
|
||||||
<ScrambleReveal
|
<ScrambleReveal
|
||||||
text="正在打磨"
|
text={line}
|
||||||
startDelayMs={500}
|
startDelayMs={300 + i * 200}
|
||||||
reverse
|
reverse={i > 0}
|
||||||
scrambleColors={false}
|
scrambleColors={i === 0}
|
||||||
/>
|
/>
|
||||||
|
{i < headlineLines.length - 1 && <br />}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
<span
|
<span
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className="ml-3 inline-block bg-l1 h-[0.72em] w-[0.45ch] align-baseline caret-blink"
|
className="ml-3 inline-block bg-l1 h-[0.72em] w-[0.45ch] align-baseline caret-blink"
|
||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
<p className="font-mono-2 text-sm lg:text-base text-l2">
|
{(emptyText?.note ?? DEFAULT_EMPTY_NOTE) && (
|
||||||
<ScrambleReveal
|
<p className="font-mono-2 text-sm lg:text-base text-l2">
|
||||||
text="把它们当作这个站的「加载动画」——完成后会在这里逐个揭晓。"
|
<ScrambleReveal
|
||||||
startDelayMs={700}
|
text={emptyText?.note ?? DEFAULT_EMPTY_NOTE}
|
||||||
letterDelayMs={10}
|
startDelayMs={700}
|
||||||
/>
|
letterDelayMs={10}
|
||||||
</p>
|
/>
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{EMPTY_PLACEHOLDERS.map((p) => (
|
{EMPTY_PLACEHOLDERS.map((p) => (
|
||||||
<PlaceholderCard key={p.no} no={p.no} gridClass={p.gridClass} />
|
<PlaceholderCard key={p.no} no={p.no} gridClass={p.gridClass} />
|
||||||
))}
|
))}
|
||||||
<div className="col-span-12 flex flex-wrap items-center gap-x-2 gap-y-1 p-2 font-mono-2 text-sm lg:text-base text-l2">
|
<div className="col-span-12 flex flex-wrap items-center gap-x-2 gap-y-1 p-2 font-mono-2 text-sm lg:text-base text-l2">
|
||||||
<ScrambleReveal text="过程记录同步在" startDelayMs={900} />
|
<ScrambleReveal
|
||||||
|
text={emptyText?.ctaPrefix ?? "过程记录同步在"}
|
||||||
|
startDelayMs={900}
|
||||||
|
/>
|
||||||
{SOCIAL_LINKS.map((s) => (
|
{SOCIAL_LINKS.map((s) => (
|
||||||
<a
|
<a
|
||||||
key={s.key}
|
key={s.key}
|
||||||
@@ -208,12 +258,16 @@ function EmptyWorkState() {
|
|||||||
<ScrambleReveal text={s.label} startDelayMs={300} scrambleColors={false} />
|
<ScrambleReveal text={s.label} startDelayMs={300} scrambleColors={false} />
|
||||||
</a>
|
</a>
|
||||||
))}
|
))}
|
||||||
<span aria-hidden="true">,或者</span>
|
<span aria-hidden="true">{emptyText?.ctaSuffix ?? ",或者"}</span>
|
||||||
<a
|
<a
|
||||||
href={`mailto:${CONTACT_EMAIL}`}
|
href={`mailto:${email}`}
|
||||||
className="text-l1 underline underline-offset-4 decoration-(--label-3) transition-[text-decoration-color] duration-150 ease-out lg:hover:decoration-(--label-1)"
|
className="text-l1 underline underline-offset-4 decoration-(--label-3) transition-[text-decoration-color] duration-150 ease-out lg:hover:decoration-(--label-1)"
|
||||||
>
|
>
|
||||||
<ScrambleReveal text="写信给我" startDelayMs={300} scrambleColors={false} />
|
<ScrambleReveal
|
||||||
|
text={emptyText?.ctaAction ?? "写信给我"}
|
||||||
|
startDelayMs={300}
|
||||||
|
scrambleColors={false}
|
||||||
|
/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* 后台认证 — DB 会话 + httpOnly cookie。
|
||||||
|
*
|
||||||
|
* - admin_users 由 lib/db.ts 种子创建(ADMIN_USERNAME / ADMIN_PASSWORD)。
|
||||||
|
* - 登录成功 → 生成随机 token 存 admin_sessions(7 天),cookie 仅携带
|
||||||
|
* 随机 token;CSRF token 单独存库、由后台前端在 mutation 请求头回传。
|
||||||
|
* - isAdmin():供 /virtheart 布局与 /api/admin/* 校验;延迟清理过期会话。
|
||||||
|
*/
|
||||||
|
import crypto from "node:crypto";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
import { db, verifyPassword, hashPassword } from "@/lib/db";
|
||||||
|
|
||||||
|
export const SESSION_COOKIE = "vh_admin_session";
|
||||||
|
export const CSRF_HEADER = "x-vh-csrf";
|
||||||
|
const SESSION_TTL_DAYS = 7;
|
||||||
|
|
||||||
|
type SessionRow = {
|
||||||
|
token: string;
|
||||||
|
user_id: number;
|
||||||
|
csrf_token: string;
|
||||||
|
expires_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function purgeExpired() {
|
||||||
|
db.prepare("DELETE FROM admin_sessions WHERE expires_at < datetime('now')").run();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createSession(userId: number): { token: string; csrf: string } {
|
||||||
|
purgeExpired();
|
||||||
|
const token = crypto.randomBytes(32).toString("hex");
|
||||||
|
const csrf = crypto.randomBytes(16).toString("hex");
|
||||||
|
db.prepare(
|
||||||
|
`INSERT INTO admin_sessions (token, user_id, csrf_token, expires_at)
|
||||||
|
VALUES (?, ?, ?, datetime('now', '+${SESSION_TTL_DAYS} day'))`
|
||||||
|
).run(token, userId, csrf);
|
||||||
|
return { token, csrf };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function destroySession(token: string) {
|
||||||
|
db.prepare("DELETE FROM admin_sessions WHERE token = ?").run(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSession(): Promise<SessionRow | null> {
|
||||||
|
const store = await cookies();
|
||||||
|
const token = store.get(SESSION_COOKIE)?.value;
|
||||||
|
if (!token) return null;
|
||||||
|
purgeExpired();
|
||||||
|
const row = db
|
||||||
|
.prepare("SELECT token, user_id, csrf_token, expires_at FROM admin_sessions WHERE token = ?")
|
||||||
|
.get(token) as SessionRow | undefined;
|
||||||
|
return row ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function isAdmin(): Promise<boolean> {
|
||||||
|
return (await getSession()) !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** mutation 请求的 CSRF 校验(同站 cookie + 自定义头双重确认)。 */
|
||||||
|
export async function verifyCsrf(): Promise<boolean> {
|
||||||
|
const session = await getSession();
|
||||||
|
if (!session) return false;
|
||||||
|
const { headers } = await import("next/headers");
|
||||||
|
const h = await headers();
|
||||||
|
return h.get(CSRF_HEADER) === session.csrf_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function verifyAdminPassword(
|
||||||
|
username: string,
|
||||||
|
password: string
|
||||||
|
): number | null {
|
||||||
|
const row = db
|
||||||
|
.prepare("SELECT id, password_salt, password_hash FROM admin_users WHERE username = ?")
|
||||||
|
.get(username) as
|
||||||
|
| { id: number; password_salt: string; password_hash: string }
|
||||||
|
| undefined;
|
||||||
|
if (!row) return null;
|
||||||
|
return verifyPassword(password, row.password_salt, row.password_hash)
|
||||||
|
? row.id
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function changeAdminPassword(
|
||||||
|
userId: number,
|
||||||
|
newPassword: string
|
||||||
|
) {
|
||||||
|
const { salt, hash } = hashPassword(newPassword);
|
||||||
|
db.prepare(
|
||||||
|
"UPDATE admin_users SET password_salt = ?, password_hash = ? WHERE id = ?"
|
||||||
|
).run(salt, hash, userId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* 滑块验证码 — 服务端Challenge/Verify。
|
||||||
|
*
|
||||||
|
* 生成:随机缺口位置(80-420px)+ 一次性 token(10 分钟有效)。
|
||||||
|
* 校验:客户端提交拖动终点 x,|x - answer| <= CAPTCHA_TOLERANCE 即通过;
|
||||||
|
* 通过后签发一次性 submitToken(5 分钟、单次消费),提交接口凭它放行。
|
||||||
|
* 失败计数 5 次作废 challenge,防暴力枚举。
|
||||||
|
*/
|
||||||
|
import crypto from "node:crypto";
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
|
export const CAPTCHA_TOLERANCE = 8;
|
||||||
|
const CHALLENGE_TTL_MIN = 10;
|
||||||
|
const SUBMIT_TOKEN_TTL_MIN = 5;
|
||||||
|
const MAX_ATTEMPTS = 5;
|
||||||
|
|
||||||
|
export function createCaptchaChallenge(): {
|
||||||
|
id: number;
|
||||||
|
puzzleX: number; // 缺口随机位置(前端展示用)
|
||||||
|
trackWidth: number;
|
||||||
|
token: string;
|
||||||
|
} {
|
||||||
|
const puzzleX = 80 + crypto.randomInt(0, 341); // 80..420
|
||||||
|
const token = crypto.randomBytes(24).toString("hex");
|
||||||
|
db.prepare(
|
||||||
|
`INSERT INTO captcha_challenges (token, answer_x, expires_at)
|
||||||
|
VALUES (?, ?, datetime('now', '+${CHALLENGE_TTL_MIN} minutes'))`
|
||||||
|
).run(token, puzzleX);
|
||||||
|
const row = db
|
||||||
|
.prepare("SELECT id FROM captcha_challenges WHERE token = ?")
|
||||||
|
.get(token) as { id: number };
|
||||||
|
db.prepare("DELETE FROM captcha_challenges WHERE expires_at < datetime('now')").run();
|
||||||
|
return { id: row.id, puzzleX, trackWidth: 500, token };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function verifyCaptcha(
|
||||||
|
token: string,
|
||||||
|
answerX: number
|
||||||
|
): { ok: true; submitToken: string } | { ok: false; error: string } {
|
||||||
|
const row = db
|
||||||
|
.prepare(
|
||||||
|
"SELECT id, answer_x, consumed, attempts, expires_at FROM captcha_challenges WHERE token = ?"
|
||||||
|
)
|
||||||
|
.get(token) as
|
||||||
|
| { id: number; answer_x: number; consumed: number; attempts: number; expires_at: string }
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
if (!row || row.consumed) return { ok: false, error: "验证已失效,请刷新重试" };
|
||||||
|
if (new Date(row.expires_at + "Z") < new Date()) {
|
||||||
|
return { ok: false, error: "验证已过期,请刷新重试" };
|
||||||
|
}
|
||||||
|
if (row.attempts >= MAX_ATTEMPTS) {
|
||||||
|
db.prepare("UPDATE captcha_challenges SET consumed = 1 WHERE id = ?").run(row.id);
|
||||||
|
return { ok: false, error: "尝试次数过多,请刷新重试" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const delta = Math.abs(answerX - row.answer_x);
|
||||||
|
if (delta > CAPTCHA_TOLERANCE) {
|
||||||
|
db.prepare(
|
||||||
|
"UPDATE captcha_challenges SET attempts = attempts + 1 WHERE id = ?"
|
||||||
|
).run(row.id);
|
||||||
|
return { ok: false, error: "位置不对,再试一次" };
|
||||||
|
}
|
||||||
|
|
||||||
|
db.prepare("UPDATE captcha_challenges SET consumed = 1 WHERE id = ?").run(row.id);
|
||||||
|
const submitToken = crypto.randomBytes(24).toString("hex");
|
||||||
|
db.prepare(
|
||||||
|
`UPDATE captcha_challenges SET token = ?, consumed = 0, expires_at = datetime('now', '+${SUBMIT_TOKEN_TTL_MIN} minutes') WHERE id = ?`
|
||||||
|
).run(`submit:${submitToken}`, row.id);
|
||||||
|
return { ok: true, submitToken };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提交接口用:校验并消费一次性 submitToken(前缀 submit:)。 */
|
||||||
|
export function consumeSubmitToken(submitToken: string): boolean {
|
||||||
|
const row = db
|
||||||
|
.prepare(
|
||||||
|
"SELECT id, consumed, expires_at FROM captcha_challenges WHERE token = ?"
|
||||||
|
)
|
||||||
|
.get(`submit:${submitToken}`) as
|
||||||
|
| { id: number; consumed: number; expires_at: string }
|
||||||
|
| undefined;
|
||||||
|
if (!row || row.consumed) return false;
|
||||||
|
if (new Date(row.expires_at + "Z") < new Date()) return false;
|
||||||
|
db.prepare("UPDATE captcha_challenges SET consumed = 1 WHERE id = ?").run(row.id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
/**
|
||||||
|
* SQLite 数据层 — node:sqlite(Node 22+ 内置,无原生依赖)。
|
||||||
|
*
|
||||||
|
* 设计:
|
||||||
|
* - 单例连接(dev 热重载复用 globalThis 引用避免重复打开)。
|
||||||
|
* - 库文件 data/site.db(gitignore;容器/服务器部署需持久化该目录)。
|
||||||
|
* - 启动时 CREATE TABLE IF NOT EXISTS + 种子数据(幂等)。
|
||||||
|
* - 站点文案全部入 site_config(key-value JSON),后台可改。
|
||||||
|
*/
|
||||||
|
import { DatabaseSync } from "node:sqlite";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import crypto from "node:crypto";
|
||||||
|
|
||||||
|
const DATA_DIR = path.join(process.cwd(), "data");
|
||||||
|
const DB_PATH = path.join(DATA_DIR, "site.db");
|
||||||
|
|
||||||
|
function openDb(): DatabaseSync {
|
||||||
|
fs.mkdirSync(DATA_DIR, { recursive: true });
|
||||||
|
// Next 构建会用多个 worker 同时 import 本模块:首次建库时并发
|
||||||
|
// CREATE TABLE 会触发 SQLITE_BUSY —— busy_timeout + 整体重试兜底。
|
||||||
|
let lastErr: unknown;
|
||||||
|
for (let attempt = 0; attempt < 5; attempt++) {
|
||||||
|
try {
|
||||||
|
const db = new DatabaseSync(DB_PATH);
|
||||||
|
db.exec("PRAGMA busy_timeout = 8000;");
|
||||||
|
db.exec("PRAGMA journal_mode = WAL;");
|
||||||
|
db.exec("PRAGMA foreign_keys = ON;");
|
||||||
|
return db;
|
||||||
|
} catch (err) {
|
||||||
|
lastErr = err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw lastErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalForDb = globalThis as unknown as {
|
||||||
|
__siteDb?: DatabaseSync;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const db = (globalForDb.__siteDb ??= openDb());
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Schema
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS site_config (
|
||||||
|
key TEXT PRIMARY KEY,
|
||||||
|
value TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS admin_users (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
username TEXT NOT NULL UNIQUE,
|
||||||
|
password_salt TEXT NOT NULL,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS admin_sessions (
|
||||||
|
token TEXT PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,
|
||||||
|
csrf_token TEXT NOT NULL,
|
||||||
|
expires_at TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS works (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
slug TEXT NOT NULL UNIQUE,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
year TEXT NOT NULL DEFAULT '',
|
||||||
|
type TEXT NOT NULL DEFAULT 'post' CHECK (type IN ('post','tools','event')),
|
||||||
|
href TEXT NOT NULL DEFAULT '',
|
||||||
|
image_url TEXT NOT NULL DEFAULT '',
|
||||||
|
hover_image_url TEXT NOT NULL DEFAULT '',
|
||||||
|
grid_class TEXT NOT NULL DEFAULT '',
|
||||||
|
coding_project INTEGER NOT NULL DEFAULT 0,
|
||||||
|
passcode_protected INTEGER NOT NULL DEFAULT 0,
|
||||||
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||||
|
published INTEGER NOT NULL DEFAULT 1,
|
||||||
|
article_date TEXT NOT NULL DEFAULT '',
|
||||||
|
article_year TEXT NOT NULL DEFAULT '',
|
||||||
|
article_iframe_src TEXT NOT NULL DEFAULT '',
|
||||||
|
article_markdown TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||||
|
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS service_items (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
slug TEXT NOT NULL UNIQUE,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
price_note TEXT NOT NULL DEFAULT '',
|
||||||
|
icon TEXT NOT NULL DEFAULT '',
|
||||||
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||||
|
enabled INTEGER NOT NULL DEFAULT 1,
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS inquiries (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
contact TEXT NOT NULL,
|
||||||
|
service_slug TEXT NOT NULL DEFAULT '',
|
||||||
|
service_title TEXT NOT NULL DEFAULT '',
|
||||||
|
message TEXT NOT NULL,
|
||||||
|
status TEXT NOT NULL DEFAULT 'new' CHECK (status IN ('new','read','replied','archived')),
|
||||||
|
email_sent INTEGER NOT NULL DEFAULT 0,
|
||||||
|
email_error TEXT,
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS captcha_challenges (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
token TEXT NOT NULL UNIQUE,
|
||||||
|
answer_x INTEGER NOT NULL,
|
||||||
|
consumed INTEGER NOT NULL DEFAULT 0,
|
||||||
|
attempts INTEGER NOT NULL DEFAULT 0,
|
||||||
|
expires_at TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
db.exec(
|
||||||
|
"CREATE INDEX IF NOT EXISTS idx_inquiries_status ON inquiries(status, created_at DESC);"
|
||||||
|
);
|
||||||
|
db.exec(
|
||||||
|
"CREATE INDEX IF NOT EXISTS idx_captcha_expiry ON captcha_challenges(expires_at);"
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 密码哈希(scrypt,无 bcrypt 原生依赖)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export function hashPassword(password: string, salt?: string) {
|
||||||
|
const useSalt = salt ?? crypto.randomBytes(16).toString("hex");
|
||||||
|
const hash = crypto.scryptSync(password, useSalt, 64).toString("hex");
|
||||||
|
return { salt: useSalt, hash };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function verifyPassword(password: string, salt: string, hash: string) {
|
||||||
|
const candidate = hashPassword(password, salt).hash;
|
||||||
|
const a = Buffer.from(candidate, "hex");
|
||||||
|
const b = Buffer.from(hash, "hex");
|
||||||
|
return a.length === b.length && crypto.timingSafeEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 种子数据(幂等)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function seed() {
|
||||||
|
const adminCount = (
|
||||||
|
db.prepare("SELECT COUNT(*) AS c FROM admin_users").get() as { c: number }
|
||||||
|
).c;
|
||||||
|
if (adminCount === 0) {
|
||||||
|
const username = process.env.ADMIN_USERNAME || "admin";
|
||||||
|
const password = process.env.ADMIN_PASSWORD || "changeme-2026";
|
||||||
|
const { salt, hash } = hashPassword(password);
|
||||||
|
db.prepare(
|
||||||
|
"INSERT INTO admin_users (username, password_salt, password_hash) VALUES (?, ?, ?)"
|
||||||
|
).run(username, salt, hash);
|
||||||
|
console.log(
|
||||||
|
`[db] 已创建管理员 ${username}(初始密码来自 ADMIN_PASSWORD 或默认值,请登录后修改)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cfgCount = (
|
||||||
|
db.prepare("SELECT COUNT(*) AS c FROM site_config").get() as { c: number }
|
||||||
|
).c;
|
||||||
|
if (cfgCount === 0) {
|
||||||
|
const seedConfig: Record<string, string> = {
|
||||||
|
site_title: "北极新一©2026",
|
||||||
|
site_description: "设计与工程 / 数字产品与 AI 应用 © 2026",
|
||||||
|
brand_name: "北极新一",
|
||||||
|
hero_line1: "设计与",
|
||||||
|
hero_line2: "工程",
|
||||||
|
hero_tagline: "以系统思维思考,用心做出设计。",
|
||||||
|
hero_big_1: "我把匠心",
|
||||||
|
hero_big_2: "与品味",
|
||||||
|
hero_big_3: "带进数字作品",
|
||||||
|
about_p1:
|
||||||
|
"全栈开发者,融合产品设计与工程能力,负责从产品构思、界面设计到前后端、跨端客户端的完整应用交付,现阶段深耕 AI 应用开发。",
|
||||||
|
about_p2: "我相信工程塑造可靠的产品,设计赋予它们灵魂;",
|
||||||
|
about_p2_link_label: "我的作品",
|
||||||
|
about_p2_link_href: "#selected-work",
|
||||||
|
intro_prefix:
|
||||||
|
"我是北极新一,一名横跨设计与工程的全栈开发者:Web 前端与后端、Flutter 客户端、AI 应用开发都有实践,也从产品设计一路做到工程落地。工作之外,我常在 ",
|
||||||
|
intro_suffix: " 上记录与分享这些探索。",
|
||||||
|
intro_brand: "小红书",
|
||||||
|
footer_headline: "让我们|创造|一些不凡的|数字作品",
|
||||||
|
contact_email: "chenchun@virtheart.com",
|
||||||
|
work_empty_headline: "第一批作品|正在打磨",
|
||||||
|
work_empty_note:
|
||||||
|
"把它们当作这个站的「加载动画」——完成后会在这里逐个揭晓。",
|
||||||
|
work_empty_cta_prefix: "过程记录同步在",
|
||||||
|
work_empty_cta_suffix: ",或者",
|
||||||
|
work_empty_cta_action: "写信给我",
|
||||||
|
copyright_name: "北极新一",
|
||||||
|
services_hero: "可提供的服务|选择你需要的服务,留言告诉我",
|
||||||
|
services_submit_note:
|
||||||
|
"提交即视为同意通过邮件与你取得联系;信息仅用于回复咨询。",
|
||||||
|
};
|
||||||
|
const insert = db.prepare(
|
||||||
|
"INSERT OR IGNORE INTO site_config (key, value) VALUES (?, ?)"
|
||||||
|
);
|
||||||
|
for (const [k, v] of Object.entries(seedConfig)) insert.run(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seed();
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/**
|
||||||
|
* SMTP 邮件 — 飞书邮箱(notify@virtheart.com)。
|
||||||
|
* 凭据全部来自环境变量(.env.local,不入库不入 git)。
|
||||||
|
*/
|
||||||
|
import nodemailer from "nodemailer";
|
||||||
|
|
||||||
|
const SMTP_HOST = process.env.SMTP_HOST || "smtp.feishu.cn";
|
||||||
|
const SMTP_PORT = Number(process.env.SMTP_PORT || 465);
|
||||||
|
const SMTP_USER = process.env.SMTP_USER || "";
|
||||||
|
const SMTP_PASS = process.env.SMTP_PASS || "";
|
||||||
|
const NOTIFY_TO = process.env.NOTIFY_TO || "chenchun@virtheart.com";
|
||||||
|
|
||||||
|
let transporter: nodemailer.Transporter | null = null;
|
||||||
|
|
||||||
|
function getTransporter(): nodemailer.Transporter {
|
||||||
|
if (!transporter) {
|
||||||
|
transporter = nodemailer.createTransport({
|
||||||
|
host: SMTP_HOST,
|
||||||
|
port: SMTP_PORT,
|
||||||
|
secure: SMTP_PORT === 465,
|
||||||
|
auth: SMTP_USER ? { user: SMTP_USER, pass: SMTP_PASS } : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return transporter;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InquiryEmailData = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
contact: string;
|
||||||
|
service_title: string;
|
||||||
|
message: string;
|
||||||
|
created_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function sendInquiryNotification(
|
||||||
|
data: InquiryEmailData
|
||||||
|
): Promise<void> {
|
||||||
|
if (!SMTP_USER) {
|
||||||
|
throw new Error("SMTP_USER 未配置(.env.local)");
|
||||||
|
}
|
||||||
|
const rows: [string, string][] = [
|
||||||
|
["留言编号", `#${data.id}`],
|
||||||
|
["姓名", data.name],
|
||||||
|
["联系方式", data.contact],
|
||||||
|
["感兴趣的服务", data.service_title || "(未选择)"],
|
||||||
|
["提交时间", data.created_at],
|
||||||
|
];
|
||||||
|
const html = `
|
||||||
|
<div style="font-family:-apple-system,'PingFang SC','Microsoft YaHei',sans-serif;max-width:560px">
|
||||||
|
<h2 style="font-size:16px">新服务咨询 · 北极新一</h2>
|
||||||
|
<table style="border-collapse:collapse;width:100%;font-size:14px">
|
||||||
|
${rows
|
||||||
|
.map(
|
||||||
|
([k, v]) =>
|
||||||
|
`<tr><td style="padding:6px 12px 6px 0;color:#666;white-space:nowrap;vertical-align:top">${k}</td><td style="padding:6px 0"><strong>${escapeHtml(
|
||||||
|
v
|
||||||
|
)}</strong></td></tr>`
|
||||||
|
)
|
||||||
|
.join("")}
|
||||||
|
</table>
|
||||||
|
<div style="margin-top:16px;padding:12px;background:#f6f6f2;border-radius:8px;font-size:14px;white-space:pre-wrap">${escapeHtml(
|
||||||
|
data.message
|
||||||
|
)}</div>
|
||||||
|
<p style="color:#999;font-size:12px;margin-top:16px">可登录 /virtheart 后台留言箱查看与更新状态。</p>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
await getTransporter().sendMail({
|
||||||
|
from: `"通知邮箱" <${SMTP_USER}>`,
|
||||||
|
to: NOTIFY_TO,
|
||||||
|
subject: `【服务咨询 #${data.id}】${data.name} - ${
|
||||||
|
data.service_title || "未选择服务"
|
||||||
|
}`,
|
||||||
|
text: rows.map(([k, v]) => `${k}:${v}`).join("\n") + `\n\n留言:\n${data.message}`,
|
||||||
|
html,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(s: string) {
|
||||||
|
return s
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """);
|
||||||
|
}
|
||||||
@@ -0,0 +1,370 @@
|
|||||||
|
/**
|
||||||
|
* 站点配置访问层 — site_config(key→JSON value) 的类型化读写。
|
||||||
|
* getSiteConfig() 每次直接读库(SQLite 同步读取开销可忽略),后台改完
|
||||||
|
* 立即生效,无需缓存失效逻辑。
|
||||||
|
*/
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
|
export type SiteConfig = {
|
||||||
|
site_title: string;
|
||||||
|
site_description: string;
|
||||||
|
brand_name: string;
|
||||||
|
hero_line1: string;
|
||||||
|
hero_line2: string;
|
||||||
|
hero_tagline: string;
|
||||||
|
hero_big_1: string;
|
||||||
|
hero_big_2: string;
|
||||||
|
hero_big_3: string;
|
||||||
|
about_p1: string;
|
||||||
|
about_p2: string;
|
||||||
|
about_p2_link_label: string;
|
||||||
|
about_p2_link_href: string;
|
||||||
|
intro_prefix: string;
|
||||||
|
intro_suffix: string;
|
||||||
|
intro_brand: string;
|
||||||
|
footer_headline: string;
|
||||||
|
contact_email: string;
|
||||||
|
work_empty_headline: string;
|
||||||
|
work_empty_note: string;
|
||||||
|
work_empty_cta_prefix: string;
|
||||||
|
work_empty_cta_suffix: string;
|
||||||
|
work_empty_cta_action: string;
|
||||||
|
copyright_name: string;
|
||||||
|
services_hero: string;
|
||||||
|
services_submit_note: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CONFIG_KEYS = [
|
||||||
|
"site_title",
|
||||||
|
"site_description",
|
||||||
|
"brand_name",
|
||||||
|
"hero_line1",
|
||||||
|
"hero_line2",
|
||||||
|
"hero_tagline",
|
||||||
|
"hero_big_1",
|
||||||
|
"hero_big_2",
|
||||||
|
"hero_big_3",
|
||||||
|
"about_p1",
|
||||||
|
"about_p2",
|
||||||
|
"about_p2_link_label",
|
||||||
|
"about_p2_link_href",
|
||||||
|
"intro_prefix",
|
||||||
|
"intro_suffix",
|
||||||
|
"intro_brand",
|
||||||
|
"footer_headline",
|
||||||
|
"contact_email",
|
||||||
|
"work_empty_headline",
|
||||||
|
"work_empty_note",
|
||||||
|
"work_empty_cta_prefix",
|
||||||
|
"work_empty_cta_suffix",
|
||||||
|
"work_empty_cta_action",
|
||||||
|
"copyright_name",
|
||||||
|
"services_hero",
|
||||||
|
"services_submit_note",
|
||||||
|
] as const satisfies readonly (keyof SiteConfig)[];
|
||||||
|
|
||||||
|
/** 配置分组(后台表单渲染顺序)。 */
|
||||||
|
export const CONFIG_GROUPS: { title: string; keys: (keyof SiteConfig)[] }[] = [
|
||||||
|
{
|
||||||
|
title: "基础",
|
||||||
|
keys: ["site_title", "site_description", "brand_name", "copyright_name"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "首屏",
|
||||||
|
keys: [
|
||||||
|
"hero_line1",
|
||||||
|
"hero_line2",
|
||||||
|
"hero_tagline",
|
||||||
|
"hero_big_1",
|
||||||
|
"hero_big_2",
|
||||||
|
"hero_big_3",
|
||||||
|
"intro_prefix",
|
||||||
|
"intro_suffix",
|
||||||
|
"intro_brand",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "关于",
|
||||||
|
keys: [
|
||||||
|
"about_p1",
|
||||||
|
"about_p2",
|
||||||
|
"about_p2_link_label",
|
||||||
|
"about_p2_link_href",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "页脚",
|
||||||
|
keys: ["footer_headline", "contact_email"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "作品区空状态",
|
||||||
|
keys: [
|
||||||
|
"work_empty_headline",
|
||||||
|
"work_empty_note",
|
||||||
|
"work_empty_cta_prefix",
|
||||||
|
"work_empty_cta_suffix",
|
||||||
|
"work_empty_cta_action",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "服务页",
|
||||||
|
keys: ["services_hero", "services_submit_note"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function getSiteConfig(): SiteConfig {
|
||||||
|
const rows = db.prepare("SELECT key, value FROM site_config").all() as {
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
}[];
|
||||||
|
const map = Object.fromEntries(rows.map((r) => [r.key, r.value]));
|
||||||
|
const out = {} as SiteConfig;
|
||||||
|
for (const key of CONFIG_KEYS) {
|
||||||
|
out[key] = map[key] ?? "";
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setSiteConfig(patch: Partial<Record<keyof SiteConfig, string>>) {
|
||||||
|
const stmt = db.prepare(
|
||||||
|
"INSERT INTO site_config (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value"
|
||||||
|
);
|
||||||
|
for (const [key, value] of Object.entries(patch)) {
|
||||||
|
if (CONFIG_KEYS.includes(key as keyof SiteConfig) && typeof value === "string") {
|
||||||
|
stmt.run(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 作品
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type WorkRow = {
|
||||||
|
id: number;
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
year: string;
|
||||||
|
type: "post" | "tools" | "event";
|
||||||
|
href: string;
|
||||||
|
image_url: string;
|
||||||
|
hover_image_url: string;
|
||||||
|
grid_class: string;
|
||||||
|
coding_project: number;
|
||||||
|
passcode_protected: number;
|
||||||
|
sort_order: number;
|
||||||
|
published: number;
|
||||||
|
article_date: string;
|
||||||
|
article_year: string;
|
||||||
|
article_iframe_src: string;
|
||||||
|
article_markdown: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const WORK_COLUMNS =
|
||||||
|
"id, slug, name, year, type, href, image_url, hover_image_url, grid_class, coding_project, passcode_protected, sort_order, published, article_date, article_year, article_iframe_src, article_markdown";
|
||||||
|
|
||||||
|
export function listWorks(onlyPublished = false): WorkRow[] {
|
||||||
|
const where = onlyPublished ? "WHERE published = 1" : "";
|
||||||
|
return db
|
||||||
|
.prepare(
|
||||||
|
`SELECT ${WORK_COLUMNS} FROM works ${where} ORDER BY sort_order ASC, id ASC`
|
||||||
|
)
|
||||||
|
.all() as unknown as WorkRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getWork(id: number): WorkRow | undefined {
|
||||||
|
return db
|
||||||
|
.prepare(`SELECT ${WORK_COLUMNS} FROM works WHERE id = ?`)
|
||||||
|
.get(id) as WorkRow | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 站内详情路由可用的 slug(原 /work/[slug] 语义)。 */
|
||||||
|
export function upsertWork(
|
||||||
|
data: Partial<WorkRow> & { name: string }
|
||||||
|
): WorkRow {
|
||||||
|
const slug =
|
||||||
|
data.slug ||
|
||||||
|
data.name
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9\u4e00-\u9fa5]+/g, "-")
|
||||||
|
.replace(/^-+|-+$/g, "") ||
|
||||||
|
`work-${Date.now()}`;
|
||||||
|
const existing = db.prepare("SELECT id FROM works WHERE slug = ?").get(slug) as
|
||||||
|
| { id: number }
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
const cols = {
|
||||||
|
name: data.name,
|
||||||
|
year: data.year ?? "",
|
||||||
|
type: (data.type ?? "post") as string,
|
||||||
|
href: data.href ?? "",
|
||||||
|
image_url: data.image_url ?? "",
|
||||||
|
hover_image_url: data.hover_image_url ?? "",
|
||||||
|
grid_class:
|
||||||
|
data.grid_class ?? "col-span-12 lg:col-span-6 xl:col-span-4",
|
||||||
|
coding_project: data.coding_project ?? 0,
|
||||||
|
passcode_protected: data.passcode_protected ?? 0,
|
||||||
|
sort_order: data.sort_order ?? 0,
|
||||||
|
published: data.published ?? 1,
|
||||||
|
article_date: data.article_date ?? "",
|
||||||
|
article_year: data.article_year ?? "",
|
||||||
|
article_iframe_src: data.article_iframe_src ?? "",
|
||||||
|
article_markdown: data.article_markdown ?? "",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
db.prepare(
|
||||||
|
`UPDATE works SET name=@name, year=@year, type=@type, href=@href,
|
||||||
|
image_url=@image_url, hover_image_url=@hover_image_url, grid_class=@grid_class,
|
||||||
|
coding_project=@coding_project, passcode_protected=@passcode_protected,
|
||||||
|
sort_order=@sort_order, published=@published, article_date=@article_date,
|
||||||
|
article_year=@article_year, article_iframe_src=@article_iframe_src,
|
||||||
|
article_markdown=@article_markdown, updated_at=datetime('now')
|
||||||
|
WHERE slug=@slug`
|
||||||
|
).run({ ...cols, slug });
|
||||||
|
} else {
|
||||||
|
db.prepare(
|
||||||
|
`INSERT INTO works (slug, name, year, type, href, image_url, hover_image_url,
|
||||||
|
grid_class, coding_project, passcode_protected, sort_order, published,
|
||||||
|
article_date, article_year, article_iframe_src, article_markdown)
|
||||||
|
VALUES (@slug, @name, @year, @type, @href, @image_url, @hover_image_url,
|
||||||
|
@grid_class, @coding_project, @passcode_protected, @sort_order, @published,
|
||||||
|
@article_date, @article_year, @article_iframe_src, @article_markdown)`
|
||||||
|
).run({ ...cols, slug });
|
||||||
|
}
|
||||||
|
const row = db
|
||||||
|
.prepare(`SELECT ${WORK_COLUMNS} FROM works WHERE slug = ?`)
|
||||||
|
.get(slug) as WorkRow;
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteWork(id: number) {
|
||||||
|
db.prepare("DELETE FROM works WHERE id = ?").run(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 服务
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type ServiceRow = {
|
||||||
|
id: number;
|
||||||
|
slug: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
price_note: string;
|
||||||
|
icon: string;
|
||||||
|
sort_order: number;
|
||||||
|
enabled: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function listServices(onlyEnabled = false): ServiceRow[] {
|
||||||
|
const where = onlyEnabled ? "WHERE enabled = 1" : "";
|
||||||
|
return db
|
||||||
|
.prepare(
|
||||||
|
`SELECT id, slug, title, description, price_note, icon, sort_order, enabled
|
||||||
|
FROM service_items ${where} ORDER BY sort_order ASC, id ASC`
|
||||||
|
)
|
||||||
|
.all() as unknown as ServiceRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function upsertService(data: {
|
||||||
|
id?: number;
|
||||||
|
slug?: string;
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
price_note?: string;
|
||||||
|
sort_order?: number;
|
||||||
|
enabled?: number;
|
||||||
|
}): ServiceRow {
|
||||||
|
if (data.id) {
|
||||||
|
db.prepare(
|
||||||
|
`UPDATE service_items SET title=@title, description=@description,
|
||||||
|
price_note=@price_note, sort_order=@sort_order, enabled=@enabled
|
||||||
|
WHERE id=@id`
|
||||||
|
).run({
|
||||||
|
title: data.title,
|
||||||
|
description: data.description ?? "",
|
||||||
|
price_note: data.price_note ?? "",
|
||||||
|
sort_order: data.sort_order ?? 0,
|
||||||
|
enabled: data.enabled ?? 1,
|
||||||
|
id: data.id,
|
||||||
|
});
|
||||||
|
return db
|
||||||
|
.prepare("SELECT * FROM service_items WHERE id = ?")
|
||||||
|
.get(data.id) as ServiceRow;
|
||||||
|
}
|
||||||
|
const slug =
|
||||||
|
data.slug ||
|
||||||
|
`svc-${Date.now().toString(36)}`;
|
||||||
|
db.prepare(
|
||||||
|
`INSERT INTO service_items (slug, title, description, price_note, sort_order, enabled)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)`
|
||||||
|
).run(
|
||||||
|
slug,
|
||||||
|
data.title,
|
||||||
|
data.description ?? "",
|
||||||
|
data.price_note ?? "",
|
||||||
|
data.sort_order ?? 0,
|
||||||
|
data.enabled ?? 1
|
||||||
|
);
|
||||||
|
return db
|
||||||
|
.prepare("SELECT * FROM service_items WHERE slug = ?")
|
||||||
|
.get(slug) as ServiceRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteService(id: number) {
|
||||||
|
db.prepare("DELETE FROM service_items WHERE id = ?").run(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// 留言
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type InquiryRow = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
contact: string;
|
||||||
|
service_slug: string;
|
||||||
|
service_title: string;
|
||||||
|
message: string;
|
||||||
|
status: "new" | "read" | "replied" | "archived";
|
||||||
|
email_sent: number;
|
||||||
|
email_error: string | null;
|
||||||
|
created_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createInquiry(data: {
|
||||||
|
name: string;
|
||||||
|
contact: string;
|
||||||
|
service_slug: string;
|
||||||
|
service_title: string;
|
||||||
|
message: string;
|
||||||
|
}): InquiryRow {
|
||||||
|
db.prepare(
|
||||||
|
`INSERT INTO inquiries (name, contact, service_slug, service_title, message)
|
||||||
|
VALUES (?, ?, ?, ?, ?)`
|
||||||
|
).run(data.name, data.contact, data.service_slug, data.service_title, data.message);
|
||||||
|
return db
|
||||||
|
.prepare("SELECT * FROM inquiries ORDER BY id DESC LIMIT 1")
|
||||||
|
.get() as InquiryRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listInquiries(limit = 100): InquiryRow[] {
|
||||||
|
return db
|
||||||
|
.prepare("SELECT * FROM inquiries ORDER BY id DESC LIMIT ?")
|
||||||
|
.all(limit) as unknown as InquiryRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateInquiryStatus(id: number, status: InquiryRow["status"]) {
|
||||||
|
db.prepare("UPDATE inquiries SET status = ? WHERE id = ?").run(status, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function markInquiryEmail(id: number, sent: boolean, error?: string) {
|
||||||
|
db.prepare(
|
||||||
|
"UPDATE inquiries SET email_sent = ?, email_error = ? WHERE id = ?"
|
||||||
|
).run(sent ? 1 : 0, error ?? null, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteInquiry(id: number) {
|
||||||
|
db.prepare("DELETE FROM inquiries WHERE id = ?").run(id);
|
||||||
|
}
|
||||||
+5
-107
@@ -23,110 +23,8 @@ export type WorkItem = {
|
|||||||
|
|
||||||
export const SELECTED_WORK_SECTION_ID = "selected-work";
|
export const SELECTED_WORK_SECTION_ID = "selected-work";
|
||||||
|
|
||||||
export const WORK_ITEMS: WorkItem[] = [
|
/**
|
||||||
{
|
* 作品数据已迁移至 SQLite(site_config + works 表),由后台管理。
|
||||||
name: revealBrandLabel(), // "小红书" — char-code obfuscated, 同原站方案
|
* 此处保留类型定义;运行时数据通过 lib/siteConfig.ts 从 DB 读取。
|
||||||
imageUrl: "/work/tt01.png",
|
*/
|
||||||
hoverImageUrl: "/work/tt02.png",
|
export const WORK_ITEMS: WorkItem[] = [];
|
||||||
href: "/2026",
|
|
||||||
year: "2022-2026",
|
|
||||||
type: "post",
|
|
||||||
gridClass: "col-span-12 lg:col-span-8 lg:col-start-3",
|
|
||||||
passcodeProtected: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Reunimos™",
|
|
||||||
imageUrl: "/work/reunimos01.png",
|
|
||||||
hoverImageUrl: "/work/reunimos02.png",
|
|
||||||
href: "/reunimos",
|
|
||||||
year: "2024-2026",
|
|
||||||
type: "post",
|
|
||||||
gridClass: "col-span-12 lg:col-span-8 lg:col-start-5",
|
|
||||||
codingProject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Inspire Mono",
|
|
||||||
imageUrl: "/work/inspire_mono_01.png",
|
|
||||||
hoverImageUrl: "/work/inspire_mono_02.png",
|
|
||||||
href: "/inspire_mono",
|
|
||||||
year: "2025",
|
|
||||||
type: "post",
|
|
||||||
gridClass: "col-span-12 lg:col-start-1 lg:col-span-6 xl:col-span-5",
|
|
||||||
codingProject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Wasm design utils",
|
|
||||||
imageUrl: "/work/wasm01.png",
|
|
||||||
hoverImageUrl: "/work/wasm02.png",
|
|
||||||
href: "/wasm_design_utils",
|
|
||||||
year: "2025",
|
|
||||||
type: "post",
|
|
||||||
gridClass: "col-span-12 lg:col-span-6 xl:col-span-5 lg:col-start-7 xl:col-start-7",
|
|
||||||
codingProject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "VectorSymbols",
|
|
||||||
imageUrl: "/work/vs01.png",
|
|
||||||
hoverImageUrl: "/work/vs02.png",
|
|
||||||
href: "https://www.figma.com/community/plugin/1255914175202017737/vectorsymbols",
|
|
||||||
year: "2023",
|
|
||||||
type: "tools",
|
|
||||||
gridClass: "col-span-6 lg:col-start-5 lg:col-span-4 xl:col-start-6 xl:col-span-3",
|
|
||||||
codingProject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "DarkSide",
|
|
||||||
imageUrl: "/work/ds01.png",
|
|
||||||
hoverImageUrl: "/work/ds02.png",
|
|
||||||
href: "https://www.figma.com/community/plugin/986289377230504703/darkside",
|
|
||||||
year: "2021",
|
|
||||||
type: "tools",
|
|
||||||
gridClass: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-10 xl:col-span-3",
|
|
||||||
codingProject: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "aDrive 阿里云盘",
|
|
||||||
imageUrl: "/work/ali01.png",
|
|
||||||
hoverImageUrl: "/work/ali02.png",
|
|
||||||
href: "/adrive",
|
|
||||||
year: "2020-2022",
|
|
||||||
type: "post",
|
|
||||||
gridClass: "col-span-12 lg:col-start-1 lg:col-span-4 xl:col-start-1 xl:col-span-3",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Shore Icon",
|
|
||||||
imageUrl: "/work/si.png",
|
|
||||||
hoverImageUrl: "/work/si02.png",
|
|
||||||
href: "/shore_icon",
|
|
||||||
year: "2022",
|
|
||||||
type: "post",
|
|
||||||
gridClass: "col-span-6 lg:col-start-5 lg:col-span-4 xl:col-start-5 xl:col-span-3",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Teambition",
|
|
||||||
imageUrl: "/work/c4.png",
|
|
||||||
hoverImageUrl: "/work/c4.png",
|
|
||||||
href: "/teambition",
|
|
||||||
year: "2018-2020",
|
|
||||||
type: "post",
|
|
||||||
gridClass: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-9 xl:col-span-3",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "FoF: See Hear Touch",
|
|
||||||
imageUrl: "/work/s01.png",
|
|
||||||
hoverImageUrl: "/work/s02.png",
|
|
||||||
href: "https://friends.figma.com/events/details/figma-shanghai-presents-see-hear-touch/",
|
|
||||||
year: "2022",
|
|
||||||
type: "event",
|
|
||||||
gridClass: "col-span-6 lg:col-start-5 lg:col-span-4 xl:col-start-6 xl:col-span-3",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "FoF: Design System",
|
|
||||||
imageUrl: "/work/sd01.png",
|
|
||||||
hoverImageUrl: "/work/sd02.png",
|
|
||||||
href: "https://friends.figma.com/events/details/figma-shanghai-presents-design-system/",
|
|
||||||
year: "2021",
|
|
||||||
type: "event",
|
|
||||||
gridClass: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-10 xl:col-span-3",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|||||||
+3
-1
@@ -18,6 +18,7 @@
|
|||||||
"lenis": "^1.3.26",
|
"lenis": "^1.3.26",
|
||||||
"lucide-react": "^1.37.0",
|
"lucide-react": "^1.37.0",
|
||||||
"next": "16.3.3",
|
"next": "16.3.3",
|
||||||
|
"nodemailer": "^9.1.0",
|
||||||
"postprocessing": "^6.39.4",
|
"postprocessing": "^6.39.4",
|
||||||
"react": "19.2.8",
|
"react": "19.2.8",
|
||||||
"react-dom": "19.2.8",
|
"react-dom": "19.2.8",
|
||||||
@@ -26,7 +27,8 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
"@types/node": "^20",
|
"@types/node": "^22.20.1",
|
||||||
|
"@types/nodemailer": "^8.0.1",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
"cn-font-split": "^7.4.3",
|
"cn-font-split": "^7.4.3",
|
||||||
|
|||||||
Generated
+30
-11
@@ -34,7 +34,10 @@ importers:
|
|||||||
version: 1.37.0(react@19.2.8)
|
version: 1.37.0(react@19.2.8)
|
||||||
next:
|
next:
|
||||||
specifier: 16.3.3
|
specifier: 16.3.3
|
||||||
version: 16.3.3(@babel/core@7.29.7(supports-color@7.1.0))(@types/node@20.19.43)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)
|
version: 16.3.3(@babel/core@7.29.7(supports-color@7.1.0))(@types/node@22.20.1)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)
|
||||||
|
nodemailer:
|
||||||
|
specifier: ^9.1.0
|
||||||
|
version: 9.1.0
|
||||||
postprocessing:
|
postprocessing:
|
||||||
specifier: ^6.39.4
|
specifier: ^6.39.4
|
||||||
version: 6.39.4(three@0.185.1)
|
version: 6.39.4(three@0.185.1)
|
||||||
@@ -55,8 +58,11 @@ importers:
|
|||||||
specifier: ^4
|
specifier: ^4
|
||||||
version: 4.3.3
|
version: 4.3.3
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^20
|
specifier: ^22.20.1
|
||||||
version: 20.19.43
|
version: 22.20.1
|
||||||
|
'@types/nodemailer':
|
||||||
|
specifier: ^8.0.1
|
||||||
|
version: 8.0.1
|
||||||
'@types/react':
|
'@types/react':
|
||||||
specifier: ^19
|
specifier: ^19
|
||||||
version: 19.2.18
|
version: 19.2.18
|
||||||
@@ -686,8 +692,11 @@ packages:
|
|||||||
'@types/json5@0.0.29':
|
'@types/json5@0.0.29':
|
||||||
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
|
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
|
||||||
|
|
||||||
'@types/node@20.19.43':
|
'@types/node@22.20.1':
|
||||||
resolution: {integrity: sha512-6oYBAi5ikg4Pl+kGsoYtawUMBT2zZMCvPNF7pVLnHZfd1zf38DRiWn/gT01RYCdUqkv7Fhr+C9ot4/tb+2sVvA==}
|
resolution: {integrity: sha512-EANqOCF9QFyra+4pfxUcX9STKJpCLjMbObVzljIJomAWSnuSIEAvyzEU53GaajbXJEgdh0iEcPL+DGvpUd4k1Q==}
|
||||||
|
|
||||||
|
'@types/nodemailer@8.0.1':
|
||||||
|
resolution: {integrity: sha512-PxpaInm8V1JQDd4j0ds5HfvWQk8JupS1C0Picb96QJsrrRDjBH+DlK7L4ZdNSqNULhiZRQHc40nLVShaGxXAMw==}
|
||||||
|
|
||||||
'@types/offscreencanvas@2019.7.3':
|
'@types/offscreencanvas@2019.7.3':
|
||||||
resolution: {integrity: sha512-ieXiYmgSRXUDeOntE1InxjWyvEelZGP63M+cGuquuRLuIKKT1osnkXjxev9B7d1nXSug5vpunx+gNlbVxMlC9A==}
|
resolution: {integrity: sha512-ieXiYmgSRXUDeOntE1InxjWyvEelZGP63M+cGuquuRLuIKKT1osnkXjxev9B7d1nXSug5vpunx+gNlbVxMlC9A==}
|
||||||
@@ -1872,6 +1881,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-YHs7BmmcsdAI5Ozuf8JZo6PT0mv2GIWC9vMfvUC3dp65M8hn7Ux8CPL+2oBI7juNuj9d0ndhTcznq2ODBps9cQ==}
|
resolution: {integrity: sha512-YHs7BmmcsdAI5Ozuf8JZo6PT0mv2GIWC9vMfvUC3dp65M8hn7Ux8CPL+2oBI7juNuj9d0ndhTcznq2ODBps9cQ==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
|
nodemailer@9.1.0:
|
||||||
|
resolution: {integrity: sha512-xj1Ri5Sau3qpPffHJwi2bY0oWVVWYq62Ph17l+2v1xXpxjqTls3YPc3L8dub9mcJpxj+1ucNnuYVqLlgh4pmDA==}
|
||||||
|
engines: {node: '>=6.0.0'}
|
||||||
|
|
||||||
object-assign@4.1.1:
|
object-assign@4.1.1:
|
||||||
resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
|
resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
@@ -3004,10 +3017,14 @@ snapshots:
|
|||||||
|
|
||||||
'@types/json5@0.0.29': {}
|
'@types/json5@0.0.29': {}
|
||||||
|
|
||||||
'@types/node@20.19.43':
|
'@types/node@22.20.1':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 6.21.0
|
undici-types: 6.21.0
|
||||||
|
|
||||||
|
'@types/nodemailer@8.0.1':
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 22.20.1
|
||||||
|
|
||||||
'@types/offscreencanvas@2019.7.3': {}
|
'@types/offscreencanvas@2019.7.3': {}
|
||||||
|
|
||||||
'@types/react-dom@19.2.5(@types/react@19.2.18)':
|
'@types/react-dom@19.2.5(@types/react@19.2.18)':
|
||||||
@@ -4325,7 +4342,7 @@ snapshots:
|
|||||||
|
|
||||||
natural-compare@1.4.0: {}
|
natural-compare@1.4.0: {}
|
||||||
|
|
||||||
next@16.3.3(@babel/core@7.29.7(supports-color@7.1.0))(@types/node@20.19.43)(react-dom@19.2.8(react@19.2.8))(react@19.2.8):
|
next@16.3.3(@babel/core@7.29.7(supports-color@7.1.0))(@types/node@22.20.1)(react-dom@19.2.8(react@19.2.8))(react@19.2.8):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@next/env': 16.3.3
|
'@next/env': 16.3.3
|
||||||
'@swc/helpers': 0.5.23
|
'@swc/helpers': 0.5.23
|
||||||
@@ -4344,7 +4361,7 @@ snapshots:
|
|||||||
'@next/swc-linux-x64-musl': 16.3.3
|
'@next/swc-linux-x64-musl': 16.3.3
|
||||||
'@next/swc-win32-arm64-msvc': 16.3.3
|
'@next/swc-win32-arm64-msvc': 16.3.3
|
||||||
'@next/swc-win32-x64-msvc': 16.3.3
|
'@next/swc-win32-x64-msvc': 16.3.3
|
||||||
sharp: 0.35.4(@types/node@20.19.43)
|
sharp: 0.35.4(@types/node@22.20.1)
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@babel/core'
|
- '@babel/core'
|
||||||
- '@types/node'
|
- '@types/node'
|
||||||
@@ -4359,6 +4376,8 @@ snapshots:
|
|||||||
|
|
||||||
node-releases@2.0.54: {}
|
node-releases@2.0.54: {}
|
||||||
|
|
||||||
|
nodemailer@9.1.0: {}
|
||||||
|
|
||||||
object-assign@4.1.1: {}
|
object-assign@4.1.1: {}
|
||||||
|
|
||||||
object-inspect@1.13.4: {}
|
object-inspect@1.13.4: {}
|
||||||
@@ -4509,7 +4528,7 @@ snapshots:
|
|||||||
'@protobufjs/path': 1.1.2
|
'@protobufjs/path': 1.1.2
|
||||||
'@protobufjs/pool': 1.1.0
|
'@protobufjs/pool': 1.1.0
|
||||||
'@protobufjs/utf8': 1.1.2
|
'@protobufjs/utf8': 1.1.2
|
||||||
'@types/node': 20.19.43
|
'@types/node': 22.20.1
|
||||||
long: 5.3.2
|
long: 5.3.2
|
||||||
|
|
||||||
punycode@2.3.1: {}
|
punycode@2.3.1: {}
|
||||||
@@ -4628,7 +4647,7 @@ snapshots:
|
|||||||
is-plain-object: 2.0.4
|
is-plain-object: 2.0.4
|
||||||
is-primitive: 3.0.1
|
is-primitive: 3.0.1
|
||||||
|
|
||||||
sharp@0.35.4(@types/node@20.19.43):
|
sharp@0.35.4(@types/node@22.20.1):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@img/colour': 1.1.0
|
'@img/colour': 1.1.0
|
||||||
detect-libc: 2.1.2
|
detect-libc: 2.1.2
|
||||||
@@ -4659,7 +4678,7 @@ snapshots:
|
|||||||
'@img/sharp-win32-arm64': 0.35.4
|
'@img/sharp-win32-arm64': 0.35.4
|
||||||
'@img/sharp-win32-ia32': 0.35.4
|
'@img/sharp-win32-ia32': 0.35.4
|
||||||
'@img/sharp-win32-x64': 0.35.4
|
'@img/sharp-win32-x64': 0.35.4
|
||||||
'@types/node': 20.19.43
|
'@types/node': 22.20.1
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
shebang-command@2.0.0:
|
shebang-command@2.0.0:
|
||||||
|
|||||||
Reference in New Issue
Block a user