feat(nsfw): 新增账号成人内容偏好并默认开启
- src/lib/digital.ts: 补充账号 NSFW 偏好协议,兼容未返回偏好的旧响应 - src/components/digital-home.tsx: 我的页支持保存开关,收藏更新保留服务端偏好 - src/components/digital.css: 增加开关样式与键盘焦点提示 - README.md: 说明默认值、游客限制与前后端配套发布要求
This commit is contained in:
@@ -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>("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>("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({
|
||||
<p className="dh-form-note">
|
||||
此资料可在新会话的「对话设定」中使用。每个会话的设定相互独立。
|
||||
</p>
|
||||
<label className="dh-content-preference">
|
||||
<span>
|
||||
<strong>NSFW 成人内容</strong>
|
||||
<small>登录账号默认开启,可随时关闭;保存后用于后续回复。</small>
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
checked={profileDraft.nsfwEnabled ?? true}
|
||||
onChange={(event) =>
|
||||
setProfileDraft({
|
||||
...profileDraft,
|
||||
nsfwEnabled: event.target.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<button className="dh-primary" type="submit">
|
||||
<Check size={16} />
|
||||
保存身份
|
||||
保存身份与偏好
|
||||
</button>
|
||||
<div className="dh-profile-stats">
|
||||
<div>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -20,6 +20,8 @@ export type Profile = {
|
||||
favorites: string[];
|
||||
persona: string;
|
||||
userName: string;
|
||||
/** 登录账号的成人内容偏好;旧服务未返回时沿用默认开启。 */
|
||||
nsfwEnabled?: boolean;
|
||||
};
|
||||
/** 会话消息拥有持久化 id,避免流式刷新时重复插入。 */
|
||||
export type Message = {
|
||||
|
||||
Reference in New Issue
Block a user