feat(nsfw): 持久化账号偏好并接入生成控制
- digital.profile.ts: 未保存偏好时默认开启,原子合并 JSON 保留其他资料 - digital.controller.ts、digital.users.ts: 接入本人和管理员偏好读写、事务及审计 - digital.chat.ts、digital.prompt.ts、digital.suggestions.ts: 各生成入口读取服务端账号偏好,保留游客鉴权 - tests/digital-*.test.ts: 覆盖默认值、关闭保留、旧客户端兼容与越权拦截 - README.md: 同步模块职责和发布要求
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
unauthorized,
|
||||
} from "../../shared/http-error";
|
||||
import { rows, write, json, audit, transaction } from "./digital.repository";
|
||||
import { getDigitalProfile, mergeDigitalProfile } from "./digital.profile";
|
||||
import {
|
||||
contentSchema,
|
||||
experimentSchema,
|
||||
@@ -94,10 +95,7 @@ export async function digitalRoutes(app: FastifyInstance) {
|
||||
rows<ContentRow>(
|
||||
"SELECT * FROM dh_content WHERE status='published' ORDER BY created_at ASC LIMIT 500",
|
||||
),
|
||||
rows<{ body: unknown }>(
|
||||
"SELECT body FROM dh_profiles WHERE account=?",
|
||||
[r.user.sub],
|
||||
),
|
||||
getDigitalProfile(r.user.sub),
|
||||
decide(r.user.sub, env.DIGITAL_UI_TYPE_KEY, { value: "old" }),
|
||||
]);
|
||||
const publicDecision = {
|
||||
@@ -113,9 +111,7 @@ export async function digitalRoutes(app: FastifyInstance) {
|
||||
};
|
||||
return ok({
|
||||
catalog: catalog.map(publicContent),
|
||||
profile: profile[0]
|
||||
? json(profile[0].body)
|
||||
: { favorites: [], persona: "", userName: "旅人" },
|
||||
profile,
|
||||
decision: publicDecision,
|
||||
serverNow: Date.now(),
|
||||
});
|
||||
@@ -126,13 +122,11 @@ export async function digitalRoutes(app: FastifyInstance) {
|
||||
favorites: z.array(idSchema).max(200),
|
||||
persona: z.string().max(2000),
|
||||
userName: z.string().min(1).max(60),
|
||||
nsfwEnabled: z.boolean().optional(),
|
||||
})
|
||||
.parse(r.body);
|
||||
await write(
|
||||
"INSERT INTO dh_profiles(account,body) VALUES (?,?) ON DUPLICATE KEY UPDATE body=VALUES(body)",
|
||||
[r.user.sub, JSON.stringify(body)],
|
||||
);
|
||||
return ok(body);
|
||||
await mergeDigitalProfile(r.user.sub, body);
|
||||
return ok(await getDigitalProfile(r.user.sub));
|
||||
});
|
||||
front.post("/exposure", async (r) => {
|
||||
const { decisionId } = z.object({ decisionId: z.uuid() }).parse(r.body);
|
||||
|
||||
Reference in New Issue
Block a user