* feat(inspirations): 灵感库 - 统一中文正文入口并校验译文版本 * feat(inspirations): 灵感库 - 发布完整中文提示词并阻止旧译文覆盖 统一 1319 条外部提示词和 329 条画廊引用,保留来源与模板参数;校验全部原文摘要,防止上游更新后误用过期中文。 验证:Bun 1.3.9 全量 2261 项测试通过,前端构建与 lint 通过,目录身份及媒体元数据对比无变化。
21 lines
1.0 KiB
JavaScript
21 lines
1.0 KiB
JavaScript
import { createHash } from "node:crypto";
|
|
|
|
/** 原文变更必须重新确认译文,不能只按 id 套用已过期的中文。 */
|
|
export function localizeInspirationEntries(entries, translations) {
|
|
return entries.map(({ promptZh, ...entry }) => {
|
|
const translation = translations[entry.id];
|
|
const sourceHash = createHash("sha256").update(entry.prompt).digest("hex");
|
|
if (!translation || translation.sourceHash !== sourceHash) {
|
|
throw new Error(`灵感缺少匹配当前原文的中文正文:${entry.id}。请更新 scripts/data/inspiration-prompts-zh.json 后再导入。`);
|
|
}
|
|
const prompt = translation.prompt?.trim();
|
|
if (!prompt || !/[㐀-䶿一-鿿]/.test(prompt)) throw new Error(`灵感中文正文无效:${entry.id}`);
|
|
return {
|
|
...entry,
|
|
...(translation?.title ? { title: translation.title } : {}),
|
|
...(translation?.description ? { description: translation.description } : {}),
|
|
prompt,
|
|
};
|
|
});
|
|
}
|