feat: 支持公开品牌 slug 解析
This commit is contained in:
1 parent
e89b751572
commit
ff5dc4e3ba
5 files changed
+13
-2
No files matched your search
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE "BrandProfile" ADD COLUMN "slug" TEXT NOT NULL DEFAULT 'default-brand';
|
||||
CREATE UNIQUE INDEX "BrandProfile_slug_key" ON "BrandProfile"("slug");
|
||||
@@ -34,6 +34,7 @@ enum FulfillmentType {
|
||||
|
||||
model BrandProfile {
|
||||
id String @id @default(uuid())
|
||||
slug String @unique @default("default-brand")
|
||||
name String
|
||||
templateKey String @default("food")
|
||||
tagline String?
|
||||
|
||||
@@ -8,6 +8,7 @@ async function main(): Promise<void> {
|
||||
where: { id: "00000000-0000-0000-0000-000000000001" },
|
||||
update: {},
|
||||
create: {
|
||||
slug: "default-brand",
|
||||
id: "00000000-0000-0000-0000-000000000001",
|
||||
name: "阿成家常菜",
|
||||
templateKey: "food",
|
||||
|
||||
@@ -148,8 +148,12 @@ export class PublicTemplateController {
|
||||
export class PublicWorkspaceController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
@Get()
|
||||
async get(): Promise<unknown> {
|
||||
const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
||||
async get(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||
const configuredId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
||||
const selected = brandSlug
|
||||
? await this.prisma.brandProfile.findUnique({ where: { slug: brandSlug }, select: { id: true } })
|
||||
: null;
|
||||
const brandId = selected?.id ?? configuredId;
|
||||
const [
|
||||
brand,
|
||||
modules,
|
||||
|
||||
@@ -58,6 +58,9 @@ test("health and public content are available without authentication", async ()
|
||||
assert.ok(Array.isArray(runtime.capabilities));
|
||||
assert.ok(runtime.theme.colors.background);
|
||||
assert.ok(Array.isArray(runtime.plugins));
|
||||
const bySlug = await request("/public/workspace?brandSlug=default-brand");
|
||||
assert.equal(bySlug.statusCode, 200);
|
||||
assert.equal(JSON.parse(bySlug.body).brand.id, brandId);
|
||||
});
|
||||
|
||||
test("public workspace uses brand-scoped capability installations and preserves status", async () => {
|
||||
|
||||
Reference in new issue
Block a user