feat: 持久化视觉模板切换历史

This commit is contained in:
que01 committed 2026-09-22 23:33:09 +08:00
1 parent 6ce162345c
commit a951504563
3 files changed
+45

No files matched your search

+39
View File
@@ -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);