fix: 收口模板预览状态与媒体矩阵

This commit is contained in:
que01 committed 2026-10-16 22:53:05 +08:00
1 parent 5bf54096be
commit b1e8012ded
28 files changed
+1015 -56

No files matched your search

@@ -361,8 +361,11 @@ export class AdminTemplatePackageService {
const version = await this.prisma.templatePackageVersion.findUnique({ where: { id } });
if (!version) throw new BadRequestException("模板版本不存在");
if (version.status === target) return { changed: false, version: this.publicVersion(version) };
// retired 是目录可见性的终态,但平台管理员可以显式重新发布;品牌安装与历史快照不受影响。
const valid =
target === "published" ? version.status === "imported" : version.status === "published";
target === "published"
? version.status === "imported" || version.status === "retired"
: version.status === "published";
if (!valid) throw new ConflictException(`模板版本当前状态为 ${version.status},不能执行此操作`);
const updated = await this.prisma.$transaction(async (tx) => {
const changed = await tx.templatePackageVersion.updateMany({
@@ -440,7 +440,11 @@ export class AdminTemplatePreviewService {
templateKey: industryTemplate.key,
tagline: identity?.tagline ?? `${industryTemplate.name}模板示例`,
description: identity?.description ?? "这是模板预览数据,不属于任何真实品牌。",
avatarUrl: identity?.avatarUrl ?? null,
avatarUrl:
identity?.avatarUrl ??
(typeof brandConfig.avatarUrl === "string" && brandConfig.avatarUrl.trim()
? brandConfig.avatarUrl
: null),
coverUrl: identity?.coverUrl ?? null,
hours: identity?.hours ?? "示例营业时间",
address: identity?.address ?? "示例服务范围",
+17 -1
View File
@@ -275,7 +275,7 @@ test("平台模板管理员可以按行业预览版本,且预览不写入品
assert.ok(body.preview.pages.find((page) => page.key === "home").modules.length > 0);
assert.ok(
body.preview.assets.some(
(asset) => asset.binding === "brand.avatarUrl" && asset.status === "missing",
(asset) => asset.binding === "brand.avatarUrl" && asset.status === "ready",
),
);
assert.ok(
@@ -283,6 +283,8 @@ test("平台模板管理员可以按行业预览版本,且预览不写入品
(asset) => asset.binding === "offering.coverUrl" && asset.status === "ready",
),
);
assert.match(body.preview.assetFiles["/assets/avatar.jpg"].dataUrl, /^data:image\/jpeg;base64,/);
assert.match(body.preview.assetFiles["/assets/avatar.jpg"].sha256, /^[a-f0-9]{64}$/);
assert.match(
body.preview.assetFiles["/assets/cases/campus.jpg"].dataUrl,
/^data:image\/jpeg;base64,/,
@@ -491,6 +493,20 @@ test("平台模板管理员可以按行业预览版本,且预览不写入品
headers,
});
assert.equal(retiredPreview.statusCode, 409);
// 撤回是目录可见性状态;平台管理员必须能显式恢复已撤回版本。
const republished = await request(`/admin/templates/${versionId}/publish`, {
method: "POST",
headers,
});
assert.equal(republished.statusCode, 201, republished.body);
assert.equal(JSON.parse(republished.body).changed, true);
assert.equal(JSON.parse(republished.body).version.status, "published");
const republishedPreview = await request(
`/admin/templates/${versionId}/preview?industry=personal`,
{ headers },
);
assert.equal(republishedPreview.statusCode, 200, republishedPreview.body);
});
test("admin routes remain guarded when an API prefix is configured", async () => {
@@ -115,6 +115,25 @@ test("template preview matrix keeps every deployed package, industry, and versio
assert.equal(firstPreview.preview.safety.submissions, "disabled");
assert.ok(firstPreview.workspace.offerings.length > 0);
// 每个已部署包的预览都必须有可显示的主理人身份和已验证媒体槽位。
assert.match(firstPreview.workspace.brand.founder ?? "", /\S/);
assert.match(firstPreview.workspace.brand.avatarUrl ?? "", /^\/assets\//);
assert.equal(firstPreview.preview.assets.length, fixture.manifest.assetSlots.length);
assert.deepEqual(
firstPreview.preview.assets.map((item) => item.status),
fixture.manifest.assetSlots.map(() => "ready"),
);
assert.deepEqual(
firstPreview.preview.diagnostics.filter((item) => item.code !== "LEGACY_PREVIEW_SAMPLE"),
[],
);
assert.equal(
firstPreview.preview.fixtureSource,
fixture.manifest.packageKey === "atelier-solopreneur"
? "previewFixture"
: "legacy-sampleContent",
);
// 版本 ID 进入模拟品牌 ID,不同版本不会共享同一模拟品牌身份。
assert.match(firstPreview.workspace.brand.id, new RegExp(`^template-preview:${first.id}`));
assert.match(