feat: 增加视觉模板预览与配置合并
This commit is contained in:
1 parent
facf261bd6
commit
4810ed7bde
3 files changed
+56
-2
No files matched your search
+43
-2
@@ -640,17 +640,58 @@ export class AdminConfigController {
|
||||
return this.prisma.brandProfile.findUnique({ where: { id: this.brandId() } });
|
||||
}
|
||||
@Patch("brand")
|
||||
updateBrand(@Req() request: FastifyRequest, @Body() body: UpdateBrandDto): Promise<unknown> {
|
||||
async updateBrand(
|
||||
@Req() request: FastifyRequest,
|
||||
@Body() body: UpdateBrandDto,
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const { config, ...fields } = body;
|
||||
const current = await this.prisma.brandProfile.findUnique({
|
||||
where: { id: this.brandId() },
|
||||
select: { config: true },
|
||||
});
|
||||
const currentConfig =
|
||||
current?.config && typeof current.config === "object" && !Array.isArray(current.config)
|
||||
? (current.config as Record<string, unknown>)
|
||||
: {};
|
||||
const nextConfig = config ? { ...currentConfig, ...config } : undefined;
|
||||
return this.prisma.brandProfile.update({
|
||||
where: { id: this.brandId() },
|
||||
data: {
|
||||
...fields,
|
||||
...(config ? { config: config as Prisma.InputJsonValue } : {}),
|
||||
...(nextConfig ? { config: nextConfig as Prisma.InputJsonValue } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
@Get("visual-template/preview")
|
||||
getVisualTemplatePreview(@Req() request: FastifyRequest): unknown {
|
||||
this.requireAdmin(request);
|
||||
return this.prisma.brandProfile
|
||||
.findUnique({ where: { id: this.brandId() }, select: { config: true } })
|
||||
.then((brand) => {
|
||||
const config =
|
||||
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
||||
? (brand.config as Record<string, unknown>)
|
||||
: {};
|
||||
const currentKey =
|
||||
typeof config.visualTemplateKey === "string"
|
||||
? config.visualTemplateKey
|
||||
: "linjing-editorial";
|
||||
const current = getVisualTemplate(currentKey) ?? getVisualTemplate("linjing-editorial");
|
||||
return {
|
||||
current: current
|
||||
? {
|
||||
key: current.key,
|
||||
version: current.version,
|
||||
name: current.name,
|
||||
theme: current.theme,
|
||||
variants: current.variants,
|
||||
}
|
||||
: null,
|
||||
available: ["linjing-editorial", "minimal-neutral"],
|
||||
};
|
||||
});
|
||||
}
|
||||
@Get("trust-content")
|
||||
listTrustContent(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
|
||||
Reference in new issue
Block a user