From cb5e004eb9d2f76cc40a88bd9edbf6ec650ff3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=9B=E5=85=AE?= Date: Tue, 27 Oct 2026 20:18:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(nsfw):=20=E6=96=B0=E5=A2=9E=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E6=88=90=E4=BA=BA=E5=86=85=E5=AE=B9=E5=81=8F=E5=A5=BD?= =?UTF-8?q?=E5=B9=B6=E9=BB=98=E8=AE=A4=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - src/lib/digital.ts: 补充账号 NSFW 偏好协议,兼容未返回偏好的旧响应 - src/components/digital-home.tsx: 我的页支持保存开关,收藏更新保留服务端偏好 - src/components/digital.css: 增加开关样式与键盘焦点提示 - README.md: 说明默认值、游客限制与前后端配套发布要求 --- README.md | 4 +++ src/components/digital-home.tsx | 41 +++++++++++++++++++++++----- src/components/digital.css | 47 +++++++++++++++++++++++++++++++++ src/lib/digital.ts | 2 ++ 4 files changed, 87 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ba2d7b1..a038b71 100644 --- a/README.md +++ b/README.md @@ -157,3 +157,7 @@ NPC 尚未出字就停止或失败时,“继续”仍可接续此前已完成 前台通过 `/api/auth/digital/login` 使用独立 C 端账号,由后台「用户管理」开通;不再使用管理员/员工身份。已有数字人业务账号由迁移复制密码哈希并保留会话,之后两套账号密码和状态独立。登录令牌保存在 HttpOnly Cookie,密码重置/账号停用会撤销旧登录状态。 对话设置的世界书与叙事风格使用平面列表;选中只保留轻底色和一个勾选标记,键盘焦点仍显示明确轮廓。 + +### NSFW 账号偏好 + +「我的」提供 NSFW 成人内容开关,登录账号未保存偏好时默认开启,已保存的关闭选择继续保留。保存后对已有及新会话的后续回复生效,包括发送、继续、重生成与回复灵感;游客仍须先登录。偏好由 `access-manage` 保存在本人资料中,前台不使用本地存储伪造保存结果。前后端需配套发布。 diff --git a/src/components/digital-home.tsx b/src/components/digital-home.tsx index db391f6..da118c7 100644 --- a/src/components/digital-home.tsx +++ b/src/components/digital-home.tsx @@ -1,6 +1,6 @@ "use client"; /* eslint-disable @next/next/no-img-element -- 本地封面直接读取,避免在小型服务器上运行图片转换。 */ -/** 星港数字人空间:探索、会话、世界书和身份资料的响应式入口。 */ +/** 星港数字人空间:探索、会话、世界书、身份资料和账号内容偏好。 */ import Link from "next/link"; import { useCallback, @@ -502,8 +502,13 @@ export function DigitalHome({ : [...profile.favorites, card.id], }; try { - await digital("profile", "PUT", next); - setProfile(next); + // 收藏不写内容开关,避免旧页面状态覆盖管理员刚保存的账号偏好。 + const saved = await digital("profile", "PUT", { + favorites: next.favorites, + persona: next.persona, + userName: next.userName, + }); + setProfile(saved); } catch (e) { reportError(e); } finally { @@ -874,11 +879,15 @@ export function DigitalHome({ ...profile, userName: profileDraft.userName, persona: profileDraft.persona, + nsfwEnabled: profileDraft.nsfwEnabled ?? true, }; try { - await digital("profile", "PUT", next); - setProfile(next); - setNotice("身份资料已保存"); + const saved = await digital("profile", "PUT", next); + if (saved.nsfwEnabled !== next.nsfwEnabled) + throw new Error("内容偏好未保存,请稍后重试"); + setProfile(saved); + setProfileDraft(saved); + setNotice("身份与内容偏好已保存"); } catch (e) { reportError(e); } @@ -917,6 +926,7 @@ export function DigitalHome({ } setConversation(null); currentId.current = null; + if (value === "me" && tab !== "me" && profile) setProfileDraft(profile); setTab(value); setError(""); } @@ -1763,9 +1773,26 @@ export function DigitalHome({

此资料可在新会话的「对话设定」中使用。每个会话的设定相互独立。

+
diff --git a/src/components/digital.css b/src/components/digital.css index 58c8ba2..6d48ff9 100644 --- a/src/components/digital.css +++ b/src/components/digital.css @@ -990,6 +990,53 @@ line-height: 1.9; margin: 8px 0 20px !important; } +.dh-profile-form > .dh-content-preference { + flex-direction: row; + align-items: center; + justify-content: space-between; + gap: 18px; + padding: 16px 0; + border-top: 1px solid var(--dh-line); + border-bottom: 1px solid var(--dh-line); +} +.dh-content-preference span { + min-width: 0; +} +.dh-content-preference small { + display: block; + margin-top: 6px; + color: var(--dh-muted); + line-height: 1.7; +} +.dh-content-preference input[type="checkbox"] { + appearance: none; + flex: none; + width: 44px; + height: 26px; + padding: 3px; + border: 1px solid var(--dh-line); + border-radius: 20px; + background: var(--dh-panel); + cursor: pointer; +} +.dh-content-preference input::before { + display: block; + width: 18px; + height: 18px; + border-radius: 50%; + background: #fff; + content: ""; +} +.dh-content-preference input:checked { + background: var(--dh-accent); +} +.dh-content-preference input:checked::before { + transform: translateX(18px); +} +.dh-content-preference input:focus-visible { + outline: 2px solid var(--dh-accent); + outline-offset: 3px; +} .dh-profile-stats { display: flex; border-top: 1px solid var(--dh-line); diff --git a/src/lib/digital.ts b/src/lib/digital.ts index 93a5859..49c17ff 100644 --- a/src/lib/digital.ts +++ b/src/lib/digital.ts @@ -20,6 +20,8 @@ export type Profile = { favorites: string[]; persona: string; userName: string; + /** 登录账号的成人内容偏好;旧服务未返回时沿用默认开启。 */ + nsfwEnabled?: boolean; }; /** 会话消息拥有持久化 id,避免流式刷新时重复插入。 */ export type Message = { -- 2.52.0