refactor: 拆分品牌业务类型与页面方案
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled

This commit is contained in:
que01 committed 2026-10-20 17:04:30 +08:00
1 parent f02e2cafbb
commit 0d9f4a7d6f
86 files changed
+4111 -1543

No files matched your search

+52 -20
View File
@@ -1,9 +1,20 @@
import { existsSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { PrismaClient, type Prisma } from "@prisma/client";
import type { TemplatePackageManifest } from "@personal-brand/config";
import bcrypt from "bcryptjs";
import { buildBrandReleaseSnapshot } from "../src/brand-release.service.js";
import { latestTemplateVersion } from "../src/template-version-order.js";
const prisma = new PrismaClient();
const seedAssetsDirectory = path.join(path.dirname(fileURLToPath(import.meta.url)), "assets");
function seedMediaExists(url: unknown): boolean {
if (typeof url !== "string" || !url) return false;
if (!url.startsWith("/media/seed/")) return true;
return existsSync(path.join(seedAssetsDirectory, path.basename(url)));
}
const runtimeImages = {
doors: [
@@ -48,7 +59,7 @@ interface RuntimeSeedTemplate {
const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTemplate> = {
personal: {
templateKey: "personal",
visualTemplateKey: "linjing-editorial",
visualTemplateKey: "atelier-solopreneur",
brandConfig: {
templateData: { designPhilosophy: "先厘清问题,再设计表达" },
title: "品牌策略顾问",
@@ -299,7 +310,7 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
phone: "186-0218-9908",
wechat: "LIN-ATELIER-2024",
studioAddress: "上海市静安区威海路设计中心 A 座 / 杭州良渚研造工坊",
avatarUrl: "/media/seed/personal-avatar.jpg",
avatarUrl: "/media/seed/founder-portrait.jpg",
profilePresentation: {
coverage: [
{
@@ -718,23 +729,42 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
data: { isEnabled: false },
});
}
const incompleteOfferings = await prisma.offering.findMany({
where: { brandId, isEnabled: true, coverUrl: null },
select: { id: true, name: true },
});
for (const [index, item] of incompleteOfferings.entries()) {
const image = offerings[index % offerings.length]?.image;
if (!image) throw new Error("Development fixture has no offering image");
// 旧模板迁移后可能留下数组形态的 config 或失效媒体引用。开发种子只修复结构,
// 不删除品牌内容,也不擅自重新启用已停用的业务提供项。
const allOfferings = await prisma.offering.findMany({ where: { brandId } });
const fallbackImage = offerings[0]?.image;
if (!fallbackImage) throw new Error("Development fixture has no offering image");
for (const offering of allOfferings) {
const rawConfig = offering.config;
const config =
rawConfig && typeof rawConfig === "object" && !Array.isArray(rawConfig)
? (rawConfig as Record<string, unknown>)
: {};
const media = config.media;
const hasValidMedia =
Array.isArray(media) &&
media.length > 0 &&
media.every(
(entry) =>
entry &&
typeof entry === "object" &&
!Array.isArray(entry) &&
seedMediaExists((entry as Record<string, unknown>).url),
);
const hasValidCover = seedMediaExists(offering.coverUrl);
const coverUrl = hasValidCover ? (offering.coverUrl as string) : fallbackImage;
if (hasValidCover && hasValidMedia && !Array.isArray(rawConfig)) continue;
await prisma.offering.update({
where: { id: item.id },
where: { id: offering.id },
data: {
coverUrl: image,
coverUrl,
config: {
categoryKey: "custom",
keywords: [],
media: [{ url: image, alt: item.name, type: "image" }],
sections: [],
},
...config,
...(config.categoryKey === undefined ? { categoryKey: "custom" } : {}),
...(Array.isArray(config.keywords) ? {} : { keywords: [] }),
media: [{ url: coverUrl, alt: offering.name, type: "image" }],
...(Array.isArray(config.sections) ? {} : { sections: [] }),
} as Prisma.InputJsonValue,
},
});
}
@@ -812,10 +842,12 @@ async function ensureTemplateInstallation(brandId: string): Promise<void> {
throw new Error("Development brand installation does not satisfy the template contract");
return;
}
const packageVersion = await prisma.templatePackageVersion.findFirst({
where: { packageKey: visualKey, status: "published" },
orderBy: { importedAt: "desc" },
});
// 版本升级必须按 SemVer 判断最新版,导入时间只用于同版本排序。
const packageVersion = latestTemplateVersion(
await prisma.templatePackageVersion.findMany({
where: { packageKey: visualKey, status: "published" },
}),
);
if (!packageVersion)
throw new Error(`Development brand requires a published package version: ${visualKey}`);
const configSnapshot = packageVersion.manifestSnapshot as Prisma.InputJsonValue;