feat: 新增客户端作品展示模块
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `artwork`
|
||||
ADD COLUMN `showcase_images` JSON NULL;
|
||||
@@ -221,6 +221,7 @@ model Artwork {
|
||||
archiveNo String? @unique @map("archive_no")
|
||||
dynamicFields Json? @map("dynamic_fields")
|
||||
images Json?
|
||||
showcaseImages Json? @map("showcase_images")
|
||||
showOutboundTimeline Boolean @default(false) @map("show_outbound_timeline")
|
||||
status ArtworkStatus @default(DRAFT)
|
||||
auditStatus AuditStatus @default(PENDING) @map("audit_status")
|
||||
|
||||
+32
-2
@@ -31,8 +31,8 @@ function writeStorage(key: string, buf: Buffer): string {
|
||||
return key;
|
||||
}
|
||||
|
||||
async function placeholder(text: string, bg: string): Promise<Buffer> {
|
||||
const svg = `<svg width="900" height="640" xmlns="http://www.w3.org/2000/svg">
|
||||
async function placeholder(text: string, bg: string, width = 900, height = 640): Promise<Buffer> {
|
||||
const svg = `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="100%" height="100%" fill="${bg}"/>
|
||||
<text x="50%" y="50%" font-family="Microsoft YaHei, sans-serif" font-size="56" fill="#ffffff" text-anchor="middle" dominant-baseline="middle">${text}</text>
|
||||
</svg>`;
|
||||
@@ -146,6 +146,35 @@ async function ensureSampleData(): Promise<void> {
|
||||
for (const s of samples) {
|
||||
const imgKey = writeStorage(`seed/${shortId()}.jpg`, await placeholder(s.title, s.bg));
|
||||
const img2 = writeStorage(`seed/${shortId()}.jpg`, await placeholder('细节图', s.bg));
|
||||
const showcaseImages = [
|
||||
{
|
||||
key: writeStorage(
|
||||
`seed/${shortId()}.jpg`,
|
||||
await placeholder(`${s.title} · 整体展示`, s.bg, 1200, 800),
|
||||
),
|
||||
name: '整体展示',
|
||||
description: '从正面完整展示作品器型、比例与整体效果。',
|
||||
type: 'image',
|
||||
},
|
||||
{
|
||||
key: writeStorage(
|
||||
`seed/${shortId()}.jpg`,
|
||||
await placeholder(`${s.title} · 工艺细节`, s.bg, 800, 1200),
|
||||
),
|
||||
name: '工艺细节',
|
||||
description: '近距离呈现作品纹样、釉色与手工制作细节。',
|
||||
type: 'image',
|
||||
},
|
||||
{
|
||||
key: writeStorage(
|
||||
`seed/${shortId()}.jpg`,
|
||||
await placeholder(`${s.title} · 多角度展示`, s.bg, 900, 1500),
|
||||
),
|
||||
name: '多角度展示',
|
||||
description: '按原始比例展示作品局部与不同观察角度。',
|
||||
type: 'image',
|
||||
},
|
||||
];
|
||||
const createMedia = await nodeMedia(['设计稿', '选胚图'], s.bg);
|
||||
const produceMedia = await nodeMedia(['手塑', '拉胚', '上釉', '烧制'], s.bg);
|
||||
const storageMedia = await nodeMedia(['入库实况'], s.bg);
|
||||
@@ -165,6 +194,7 @@ async function ensureSampleData(): Promise<void> {
|
||||
{ key: imgKey, name: '主图' },
|
||||
{ key: img2, name: '细节' },
|
||||
],
|
||||
showcaseImages,
|
||||
traceNodes: {
|
||||
create: [
|
||||
{ nodeType: 'CREATE', title: '创作设计', location: '景德镇', description: '设计选胚,确定器型与纹样。', sortOrder: 0, mediaFiles: createMedia },
|
||||
|
||||
@@ -21,6 +21,7 @@ function createHarness() {
|
||||
auditStatus: data.auditStatus,
|
||||
dynamicFields: data.dynamicFields,
|
||||
images: data.images,
|
||||
showcaseImages: data.showcaseImages,
|
||||
showOutboundTimeline: data.showOutboundTimeline,
|
||||
traceNodes: [],
|
||||
certificates: [],
|
||||
@@ -122,6 +123,33 @@ it('defaults outbound timeline visibility to false in the record and revision sn
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('stores showcase images in the artwork and its initial revision snapshot', async () => {
|
||||
const { service, tx } = createHarness();
|
||||
const showcaseImages = [
|
||||
{
|
||||
key: 'uploads/showcase-1.jpg',
|
||||
name: '局部细节',
|
||||
description: '作品肌理与落款细节',
|
||||
type: 'image',
|
||||
},
|
||||
];
|
||||
|
||||
await service.create(
|
||||
{
|
||||
templateId: 1,
|
||||
title: '带作品展示的作品',
|
||||
status: ArtworkStatus.ACTIVE,
|
||||
showcaseImages,
|
||||
} as any,
|
||||
user(RoleType.SUPER_ADMIN),
|
||||
);
|
||||
|
||||
expect(tx.artwork.create.mock.calls[0][0].data.showcaseImages).toEqual(showcaseImages);
|
||||
expect(
|
||||
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showcaseImages,
|
||||
).toEqual(showcaseImages);
|
||||
});
|
||||
|
||||
function updateHarness() {
|
||||
const current = {
|
||||
artwork: {
|
||||
@@ -235,6 +263,32 @@ describe('ArtworkService.update approval policy', () => {
|
||||
expect(enqueueWatermarks).toHaveBeenCalledWith(7);
|
||||
});
|
||||
|
||||
it('applies a super-admin showcase change immediately', async () => {
|
||||
const { service, tx, applySnapshot } = updateHarness();
|
||||
const showcaseImages = [
|
||||
{
|
||||
key: 'uploads/showcase-2.jpg',
|
||||
name: '装裱效果',
|
||||
description: '装裱后的整体展示',
|
||||
type: 'image',
|
||||
},
|
||||
];
|
||||
|
||||
await service.update(7, { showcaseImages } as any, user(RoleType.SUPER_ADMIN));
|
||||
|
||||
expect(
|
||||
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showcaseImages,
|
||||
).toEqual(showcaseImages);
|
||||
expect(applySnapshot).toHaveBeenCalledWith(
|
||||
tx,
|
||||
7,
|
||||
expect.objectContaining({
|
||||
artwork: expect.objectContaining({ showcaseImages }),
|
||||
}),
|
||||
expect.objectContaining({ auditStatus: AuditStatus.APPROVED, auditedBy: 9 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps an operator revision pending and does not overwrite an approved formal version', async () => {
|
||||
const { service, tx, applySnapshot } = updateHarness();
|
||||
|
||||
@@ -251,6 +305,38 @@ describe('ArtworkService.update approval policy', () => {
|
||||
expect(applySnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps an operator showcase change only in the pending snapshot', async () => {
|
||||
const { service, tx, applySnapshot } = updateHarness();
|
||||
const showcaseImages = [
|
||||
{
|
||||
key: 'uploads/showcase-pending.jpg',
|
||||
name: '待审核细节',
|
||||
description: '运营提交的展示说明',
|
||||
type: 'image',
|
||||
},
|
||||
];
|
||||
|
||||
await service.update(7, { showcaseImages } as any, user(RoleType.OPERATOR));
|
||||
|
||||
expect(
|
||||
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showcaseImages,
|
||||
).toEqual(showcaseImages);
|
||||
expect(tx.artworkRevision.create.mock.calls[0][0].data.status).toBe(
|
||||
ArtworkRevisionStatus.PENDING,
|
||||
);
|
||||
expect(applySnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('treats a legacy snapshot without showcase images as an empty list', async () => {
|
||||
const { service, tx } = updateHarness();
|
||||
|
||||
await service.update(7, { title: '兼容旧快照' } as any, user(RoleType.SUPER_ADMIN));
|
||||
|
||||
expect(
|
||||
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showcaseImages,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('activates a super-admin draft immediately without entering the pending queue', async () => {
|
||||
const { service, tx, applySnapshot, getSnapshot } = updateHarness();
|
||||
(service as any).ensureExists.mockResolvedValue({
|
||||
|
||||
@@ -25,6 +25,7 @@ interface MediaItem {
|
||||
key: string;
|
||||
name?: string;
|
||||
type?: string;
|
||||
description?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
@@ -55,6 +56,7 @@ interface ArtworkSnapshot {
|
||||
status: ArtworkStatus;
|
||||
dynamicFields: Record<string, unknown>;
|
||||
images: MediaItem[];
|
||||
showcaseImages: MediaItem[];
|
||||
showOutboundTimeline: boolean;
|
||||
};
|
||||
traceNodes: TraceNodeSnapshot[];
|
||||
@@ -92,7 +94,7 @@ export class ArtworkService {
|
||||
return `${templateId}/${archiveNo}`;
|
||||
}
|
||||
|
||||
// 把作品的既有媒体(主图/节点图/证书原件+水印件)归位到 {模板ID}/{档案编号}/,
|
||||
// 把作品的既有媒体(主图/作品展示/节点图/证书原件+水印件)归位到 {模板ID}/{档案编号}/,
|
||||
// 文件名人类可读:作品图_{时间戳}_{序号} / 节点-{标题}_... / 证书-{名称}_...;
|
||||
// 同步更新 DB 引用,返回 oldKey->newKey 映射(供调用方改写快照/DTO 中的旧引用)。
|
||||
private async relocateArtworkMedia(artworkId: number): Promise<Map<string, string>> {
|
||||
@@ -113,6 +115,19 @@ export class ArtworkService {
|
||||
});
|
||||
}
|
||||
|
||||
const showcaseSource = this.remapMedia(
|
||||
(artwork.showcaseImages ?? []) as unknown as MediaItem[],
|
||||
keyMap,
|
||||
);
|
||||
const showcaseImages = await this.storage.relocateMedia(showcaseSource, dir, '作品展示');
|
||||
showcaseImages.keyMap.forEach((v, k) => keyMap.set(k, v));
|
||||
if (showcaseImages.changed) {
|
||||
await this.prisma.artwork.update({
|
||||
where: { id: artworkId },
|
||||
data: { showcaseImages: showcaseImages.items as unknown as Prisma.InputJsonValue },
|
||||
});
|
||||
}
|
||||
|
||||
for (const node of artwork.traceNodes) {
|
||||
const media = await this.storage.relocateMedia(
|
||||
(node.mediaFiles ?? []) as unknown as MediaItem[],
|
||||
@@ -188,6 +203,7 @@ export class ArtworkService {
|
||||
auditedAt: reviewedAt,
|
||||
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
|
||||
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
|
||||
showcaseImages: (dto.showcaseImages ?? []) as unknown as Prisma.InputJsonValue,
|
||||
showOutboundTimeline: dto.showOutboundTimeline ?? false,
|
||||
createdBy: userId,
|
||||
traceNodes: traceNodes.length
|
||||
@@ -330,6 +346,7 @@ export class ArtworkService {
|
||||
return {
|
||||
...a,
|
||||
images: this.mapMedia(a.images),
|
||||
showcaseImages: this.mapMedia(a.showcaseImages),
|
||||
codeCount: a._count.traceCodes,
|
||||
queryTotal: sumMap.get(a.id) ?? 0,
|
||||
latestRevision: revision,
|
||||
@@ -373,6 +390,7 @@ export class ArtworkService {
|
||||
return {
|
||||
...a,
|
||||
images: this.mapMedia(a.images),
|
||||
showcaseImages: this.mapMedia(a.showcaseImages),
|
||||
traceNodes: a.traceNodes.map((n) => ({ ...n, mediaFiles: this.mapMedia(n.mediaFiles) })),
|
||||
certificates: a.certificates.map((c) => ({
|
||||
...c,
|
||||
@@ -398,6 +416,10 @@ export class ArtworkService {
|
||||
if (dtoImages && dir) {
|
||||
dtoImages = (await this.storage.relocateMedia(dtoImages, dir, '作品图')).items;
|
||||
}
|
||||
let dtoShowcaseImages = this.remapMedia(dto.showcaseImages as MediaItem[] | undefined, keyMap);
|
||||
if (dtoShowcaseImages && dir) {
|
||||
dtoShowcaseImages = (await this.storage.relocateMedia(dtoShowcaseImages, dir, '作品展示')).items;
|
||||
}
|
||||
let dtoNodes = dto.traceNodes ? this.normalizeTraceNodeDto(dto.traceNodes) : undefined;
|
||||
if (dtoNodes && dir) {
|
||||
dtoNodes = await Promise.all(
|
||||
@@ -437,6 +459,7 @@ export class ArtworkService {
|
||||
status: nextStatus,
|
||||
dynamicFields: dto.dynamicFields ?? current.artwork.dynamicFields,
|
||||
images: (dtoImages ?? current.artwork.images) as MediaItem[],
|
||||
showcaseImages: (dtoShowcaseImages ?? current.artwork.showcaseImages ?? []) as MediaItem[],
|
||||
showOutboundTimeline: dto.showOutboundTimeline ?? current.artwork.showOutboundTimeline ?? false,
|
||||
},
|
||||
traceNodes: dtoNodes ?? current.traceNodes,
|
||||
@@ -648,6 +671,7 @@ export class ArtworkService {
|
||||
status: string;
|
||||
dynamicFields: Prisma.JsonValue | null;
|
||||
images: Prisma.JsonValue | null;
|
||||
showcaseImages?: Prisma.JsonValue | null;
|
||||
showOutboundTimeline?: boolean;
|
||||
traceNodes: Array<{
|
||||
nodeType: string;
|
||||
@@ -675,6 +699,7 @@ export class ArtworkService {
|
||||
status: record.status as ArtworkStatus,
|
||||
dynamicFields: (record.dynamicFields as Record<string, unknown>) ?? {},
|
||||
images: (Array.isArray(record.images) ? record.images : []) as unknown as MediaItem[],
|
||||
showcaseImages: (Array.isArray(record.showcaseImages) ? record.showcaseImages : []) as unknown as MediaItem[],
|
||||
showOutboundTimeline: record.showOutboundTimeline ?? false,
|
||||
},
|
||||
traceNodes: record.traceNodes
|
||||
@@ -718,6 +743,7 @@ export class ArtworkService {
|
||||
status: snapshot.artwork.status,
|
||||
dynamicFields: this.normalizeJson(snapshot.artwork.dynamicFields ?? {}),
|
||||
images: this.normalizeMedia(snapshot.artwork.images),
|
||||
showcaseImages: this.normalizeMedia(snapshot.artwork.showcaseImages),
|
||||
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
|
||||
},
|
||||
traceNodes: snapshot.traceNodes.map((node, index) => ({
|
||||
@@ -745,6 +771,7 @@ export class ArtworkService {
|
||||
key: item.key,
|
||||
name: item.name ?? '',
|
||||
type: item.type ?? '',
|
||||
description: item.description ?? '',
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -778,6 +805,7 @@ export class ArtworkService {
|
||||
artwork: {
|
||||
...snapshot.artwork,
|
||||
images: this.mapMedia(snapshot.artwork.images),
|
||||
showcaseImages: this.mapMedia(snapshot.artwork.showcaseImages),
|
||||
},
|
||||
traceNodes: snapshot.traceNodes.map((node) => ({
|
||||
...node,
|
||||
@@ -818,6 +846,7 @@ export class ArtworkService {
|
||||
status: snapshot.artwork.status,
|
||||
dynamicFields: snapshot.artwork.dynamicFields as Prisma.InputJsonObject,
|
||||
images: snapshot.artwork.images as unknown as Prisma.InputJsonValue,
|
||||
showcaseImages: (snapshot.artwork.showcaseImages ?? []) as unknown as Prisma.InputJsonValue,
|
||||
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
|
||||
...auditData,
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
ArrayMaxSize,
|
||||
IsArray,
|
||||
IsDateString,
|
||||
IsEnum,
|
||||
@@ -31,6 +32,12 @@ export class MediaItemDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
type?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '展示说明' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(1000)
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export class CreateArtworkDto {
|
||||
@@ -68,6 +75,14 @@ export class CreateArtworkDto {
|
||||
@Type(() => MediaItemDto)
|
||||
images?: MediaItemDto[];
|
||||
|
||||
@ApiPropertyOptional({ description: '客户端作品展示图片', type: [MediaItemDto] })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(30)
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => MediaItemDto)
|
||||
showcaseImages?: MediaItemDto[];
|
||||
|
||||
@ApiPropertyOptional({ description: '状态', enum: ArtworkStatus })
|
||||
@IsOptional()
|
||||
@IsEnum(ArtworkStatus)
|
||||
@@ -192,6 +207,14 @@ export class UpdateArtworkDto {
|
||||
@Type(() => MediaItemDto)
|
||||
images?: MediaItemDto[];
|
||||
|
||||
@ApiPropertyOptional({ description: '客户端作品展示图片', type: [MediaItemDto] })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(30)
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => MediaItemDto)
|
||||
showcaseImages?: MediaItemDto[];
|
||||
|
||||
@ApiPropertyOptional({ description: '状态', enum: ArtworkStatus })
|
||||
@IsOptional()
|
||||
@IsEnum(ArtworkStatus)
|
||||
|
||||
@@ -49,6 +49,14 @@ function createHarness(options: {
|
||||
title: '草稿作品',
|
||||
artist: null,
|
||||
images: [],
|
||||
showcaseImages: [
|
||||
{
|
||||
key: 'artwork/10/showcase/detail.jpg',
|
||||
name: '笔触细节',
|
||||
description: '近距离展示作品笔触与材质',
|
||||
type: 'image',
|
||||
},
|
||||
],
|
||||
dynamicFields: null,
|
||||
showOutboundTimeline: options.showOutboundTimeline ?? false,
|
||||
template: { fields: [] },
|
||||
@@ -130,3 +138,20 @@ describe('PublicTraceService outbound timeline visibility', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('PublicTraceService artwork showcase', () => {
|
||||
it('returns showcase image titles, descriptions and public URLs', async () => {
|
||||
const { service } = createHarness({ artworkStatus: ArtworkStatus.ACTIVE });
|
||||
|
||||
const result = await service.preview('482731000001', 'inactive');
|
||||
|
||||
expect((result as any).artwork.showcaseImages).toEqual([
|
||||
{
|
||||
name: '笔触细节',
|
||||
description: '近距离展示作品笔触与材质',
|
||||
type: 'image',
|
||||
url: '/uploads/artwork/10/showcase/detail.jpg',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,11 +38,18 @@ export class PublicTraceService {
|
||||
@Inject(REDIS_CLIENT) private readonly redis: Redis,
|
||||
) {}
|
||||
|
||||
private mapMedia(items: unknown) {
|
||||
private mapMedia(
|
||||
items: unknown,
|
||||
): Array<{ name?: string; type?: string; description?: string; url: string }> {
|
||||
if (!Array.isArray(items)) return [];
|
||||
return (items as Array<{ key: string; name?: string; type?: string }>)
|
||||
return (items as Array<{ key: string; name?: string; type?: string; description?: string }>)
|
||||
.filter((i) => i && i.key)
|
||||
.map((i) => ({ name: i.name, type: i.type, url: this.storage.getUrl(i.key) }));
|
||||
.map((i) => ({
|
||||
name: i.name,
|
||||
type: i.type,
|
||||
description: i.description,
|
||||
url: this.storage.getUrl(i.key),
|
||||
}));
|
||||
}
|
||||
|
||||
private buildTimeline(
|
||||
@@ -320,6 +327,7 @@ export class PublicTraceService {
|
||||
artist: artwork.artist,
|
||||
archiveNo: artwork.archiveNo,
|
||||
images: this.mapMedia(artwork.images),
|
||||
showcaseImages: this.mapMedia(artwork.showcaseImages),
|
||||
showOutboundTimeline: artwork.showOutboundTimeline,
|
||||
fields: this.buildFields(artwork.template.fields, artwork.dynamicFields),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user