feat: 完成多品牌隔离专项验收
This commit is contained in:
1 parent
1a2f179e15
commit
dcb40f629b
16 files changed
+197
-51
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { Controller, Get, NotFoundException, Query } from "@nestjs/common";
|
||||
import { Controller, Get, Query } from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||
import {
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
@@ -16,19 +17,14 @@ import type {
|
||||
|
||||
@Controller("public/workspace")
|
||||
export class PublicWorkspaceController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly brandContext: PublicBrandContextService,
|
||||
) {}
|
||||
private readonly cache = new Map<string, { expiresAt: number; value: unknown }>();
|
||||
@Get()
|
||||
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;
|
||||
if (brandSlug && !selected) throw new NotFoundException("品牌不存在");
|
||||
const brandId = selected?.id ?? configuredId;
|
||||
const brandId = await this.brandContext.resolveId(brandSlug);
|
||||
const cached = process.env.NODE_ENV === "test" ? undefined : this.cache.get(brandId);
|
||||
if (cached && cached.expiresAt > Date.now()) return cached.value;
|
||||
const [
|
||||
|
||||
Reference in new issue
Block a user