feat: 持久化视觉模板切换历史
This commit is contained in:
1 parent
6ce162345c
commit
a951504563
3 files changed
+45
No files matched your search
@@ -655,6 +655,28 @@ export class AdminConfigController {
|
||||
? (current.config as Record<string, unknown>)
|
||||
: {};
|
||||
const nextConfig = config ? { ...currentConfig, ...config } : undefined;
|
||||
if (config?.visualTemplateKey && config.visualTemplateKey !== currentConfig.visualTemplateKey) {
|
||||
const installation = await this.prisma.brandTemplateInstallation.findFirst({
|
||||
where: { brandId: this.brandId() },
|
||||
});
|
||||
if (installation) {
|
||||
const history = Array.isArray(installation.previousSnapshots)
|
||||
? installation.previousSnapshots
|
||||
: [];
|
||||
await this.prisma.brandTemplateInstallation.update({
|
||||
where: { id: installation.id },
|
||||
data: {
|
||||
previousSnapshots: [
|
||||
...history,
|
||||
{
|
||||
visualTemplateKey: currentConfig.visualTemplateKey ?? "linjing-editorial",
|
||||
savedAt: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return this.prisma.brandProfile.update({
|
||||
where: { id: this.brandId() },
|
||||
data: {
|
||||
@@ -663,6 +685,23 @@ export class AdminConfigController {
|
||||
},
|
||||
});
|
||||
}
|
||||
@Get("visual-template/history")
|
||||
getVisualTemplateHistory(@Req() request: FastifyRequest): unknown {
|
||||
this.requireAdmin(request);
|
||||
return this.prisma.brandTemplateInstallation
|
||||
.findFirst({ where: { brandId: this.brandId() }, select: { previousSnapshots: true } })
|
||||
.then((installation) => ({
|
||||
history: Array.isArray(installation?.previousSnapshots)
|
||||
? installation.previousSnapshots.filter(
|
||||
(item) =>
|
||||
item &&
|
||||
typeof item === "object" &&
|
||||
!Array.isArray(item) &&
|
||||
"visualTemplateKey" in item,
|
||||
)
|
||||
: [],
|
||||
}));
|
||||
}
|
||||
@Get("visual-template/preview")
|
||||
getVisualTemplatePreview(@Req() request: FastifyRequest): unknown {
|
||||
this.requireAdmin(request);
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
- [x] 集成测试验证视觉模板切换会影响公开 Runtime Workspace 的主题和变体。
|
||||
- [x] 增加视觉模板预览接口,并在品牌配置更新时合并 config,避免覆盖其他配置。
|
||||
- [x] 后台视觉模板切换增加确认和差异说明,避免误操作覆盖业务内容。
|
||||
- [x] 视觉模板切换记录历史快照,并提供后台历史查询接口。
|
||||
- [ ] Phase 4:Capability Plugin。
|
||||
- [ ] Phase 5:林境门作与第二行业双模板验证。
|
||||
- [ ] Phase 6:Stitch 到 Manifest 的转换流水线。
|
||||
|
||||
@@ -378,6 +378,11 @@ export class ApiClient {
|
||||
}> {
|
||||
return this.request("/admin/config/visual-template/preview");
|
||||
}
|
||||
getAdminVisualTemplateHistory(): Promise<{
|
||||
history: Array<{ visualTemplateKey: string; savedAt: string }>;
|
||||
}> {
|
||||
return this.request("/admin/config/visual-template/history");
|
||||
}
|
||||
updateAdminBrand(body: BrandUpdate): Promise<BrandProfile> {
|
||||
return this.request("/admin/config/brand", { method: "PATCH", body });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user