import { ModelFormat, PublishStatus, SourceType } from '../common/enums'; import { CharacterModel } from '../entities/model.entity'; /** 契约 data-models.md §4 的对外表示 */ export interface ModelDto { id: number; name: string; format: ModelFormat; vrmVersion: string | null; isPrimary: boolean; fileUrl: string | null; fileSize: number | null; /** 模型文件(转换产物)的 sha256 —— 每次转换都会变,仅作记录 */ fileSha256: string | null; /** 上传压缩包的 sha256(稳定);非压缩包上传为 null,此时以 fileSha256 为准 */ sourceSha256: string | null; thumbnailUrl: string | null; /** 由压缩包转换而来时的说明,例如 `Hatsune Miku.pmx → GLB,已内嵌 2 张贴图` */ conversionNote: string | null; sourceType: SourceType; sourceName: string; sourceUrl: string; license: string; author: string; status: PublishStatus; createdAt: string; updatedAt: string; } export interface ModelUrlLookup { fileUrl: string | null; thumbnailUrl: string | null; fileSize?: number | null; fileSha256?: string | null; sourceSha256?: string | null; } export function toModelDto(model: CharacterModel, urls: ModelUrlLookup): ModelDto { return { id: model.id, name: model.name, format: model.format, vrmVersion: model.vrmVersion, isPrimary: model.isPrimary, fileUrl: urls.fileUrl, fileSize: urls.fileSize ?? null, fileSha256: urls.fileSha256 ?? null, sourceSha256: urls.sourceSha256 ?? null, thumbnailUrl: urls.thumbnailUrl, conversionNote: model.conversionNote ?? null, sourceType: model.sourceType, sourceName: model.sourceName, sourceUrl: model.sourceUrl, license: model.license, author: model.author, status: model.status, createdAt: model.createdAt.toISOString(), updatedAt: model.updatedAt.toISOString(), }; }