Files
opendance-web/web-server/src/models/model.serializer.ts
T

50 lines
1.3 KiB
TypeScript

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;
thumbnailUrl: 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;
}
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,
thumbnailUrl: urls.thumbnailUrl,
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(),
};
}