2023-03-30 15:38:55 -04:00
|
|
|
import { AssetEntity, AssetType } from '@app/infra/entities';
|
2022-07-13 07:23:48 -05:00
|
|
|
import { ApiProperty } from '@nestjs/swagger';
|
2023-06-30 21:52:40 -04:00
|
|
|
import { mapFace, PersonResponseDto } from '../../person/person.dto';
|
2023-01-25 11:35:28 -05:00
|
|
|
import { mapTag, TagResponseDto } from '../../tag';
|
2022-06-18 17:56:36 +02:00
|
|
|
import { ExifResponseDto, mapExif } from './exif-response.dto';
|
2023-05-17 13:07:17 -04:00
|
|
|
import { mapSmartInfo, SmartInfoResponseDto } from './smart-info-response.dto';
|
2022-06-18 17:56:36 +02:00
|
|
|
|
2022-07-08 21:26:50 -05:00
|
|
|
export class AssetResponseDto {
|
|
|
|
|
id!: string;
|
|
|
|
|
deviceAssetId!: string;
|
|
|
|
|
ownerId!: string;
|
|
|
|
|
deviceId!: string;
|
2022-07-13 07:23:48 -05:00
|
|
|
|
|
|
|
|
@ApiProperty({ enumName: 'AssetTypeEnum', enum: AssetType })
|
2022-07-08 21:26:50 -05:00
|
|
|
type!: AssetType;
|
|
|
|
|
originalPath!: string;
|
2023-04-11 05:23:39 -05:00
|
|
|
originalFileName!: string;
|
2023-05-27 21:56:17 -04:00
|
|
|
resized!: boolean;
|
2023-06-17 23:22:31 -04:00
|
|
|
/**base64 encoded thumbhash */
|
|
|
|
|
thumbhash!: string | null;
|
2023-05-29 16:05:14 +02:00
|
|
|
fileCreatedAt!: Date;
|
|
|
|
|
fileModifiedAt!: Date;
|
|
|
|
|
updatedAt!: Date;
|
2022-07-08 21:26:50 -05:00
|
|
|
isFavorite!: boolean;
|
2023-04-12 18:37:52 +03:00
|
|
|
isArchived!: boolean;
|
2022-07-08 21:26:50 -05:00
|
|
|
duration!: string;
|
2022-06-18 17:56:36 +02:00
|
|
|
exifInfo?: ExifResponseDto;
|
|
|
|
|
smartInfo?: SmartInfoResponseDto;
|
2022-11-26 17:16:02 +01:00
|
|
|
livePhotoVideoId?: string | null;
|
2023-02-06 20:47:06 -06:00
|
|
|
tags?: TagResponseDto[];
|
2023-05-17 13:07:17 -04:00
|
|
|
people?: PersonResponseDto[];
|
2023-05-27 21:56:17 -04:00
|
|
|
/**base64 encoded sha1 hash */
|
|
|
|
|
checksum!: string;
|
2022-06-18 17:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function mapAsset(entity: AssetEntity): AssetResponseDto {
|
|
|
|
|
return {
|
|
|
|
|
id: entity.id,
|
|
|
|
|
deviceAssetId: entity.deviceAssetId,
|
2023-02-19 16:44:53 +00:00
|
|
|
ownerId: entity.ownerId,
|
2022-06-18 17:56:36 +02:00
|
|
|
deviceId: entity.deviceId,
|
|
|
|
|
type: entity.type,
|
|
|
|
|
originalPath: entity.originalPath,
|
2023-04-11 05:23:39 -05:00
|
|
|
originalFileName: entity.originalFileName,
|
2023-05-27 21:56:17 -04:00
|
|
|
resized: !!entity.resizePath,
|
2023-06-17 23:22:31 -04:00
|
|
|
thumbhash: entity.thumbhash?.toString('base64') ?? null,
|
2023-02-19 16:44:53 +00:00
|
|
|
fileCreatedAt: entity.fileCreatedAt,
|
|
|
|
|
fileModifiedAt: entity.fileModifiedAt,
|
2023-02-06 10:24:58 -06:00
|
|
|
updatedAt: entity.updatedAt,
|
2022-06-18 17:56:36 +02:00
|
|
|
isFavorite: entity.isFavorite,
|
2023-04-12 18:37:52 +03:00
|
|
|
isArchived: entity.isArchived,
|
2022-06-25 19:53:06 +02:00
|
|
|
duration: entity.duration ?? '0:00:00.00000',
|
2022-06-18 17:56:36 +02:00
|
|
|
exifInfo: entity.exifInfo ? mapExif(entity.exifInfo) : undefined,
|
|
|
|
|
smartInfo: entity.smartInfo ? mapSmartInfo(entity.smartInfo) : undefined,
|
2022-11-18 23:12:54 -06:00
|
|
|
livePhotoVideoId: entity.livePhotoVideoId,
|
2022-12-05 11:56:44 -06:00
|
|
|
tags: entity.tags?.map(mapTag),
|
2023-07-18 20:09:43 +02:00
|
|
|
people: entity.faces?.map(mapFace).filter((person) => !person.isHidden),
|
2023-05-27 21:56:17 -04:00
|
|
|
checksum: entity.checksum.toString('base64'),
|
2022-06-18 17:56:36 +02:00
|
|
|
};
|
|
|
|
|
}
|
2023-01-21 22:15:16 -06:00
|
|
|
|
|
|
|
|
export function mapAssetWithoutExif(entity: AssetEntity): AssetResponseDto {
|
|
|
|
|
return {
|
|
|
|
|
id: entity.id,
|
|
|
|
|
deviceAssetId: entity.deviceAssetId,
|
2023-02-19 16:44:53 +00:00
|
|
|
ownerId: entity.ownerId,
|
2023-01-21 22:15:16 -06:00
|
|
|
deviceId: entity.deviceId,
|
|
|
|
|
type: entity.type,
|
|
|
|
|
originalPath: entity.originalPath,
|
2023-04-11 05:23:39 -05:00
|
|
|
originalFileName: entity.originalFileName,
|
2023-05-27 21:56:17 -04:00
|
|
|
resized: !!entity.resizePath,
|
2023-06-17 23:22:31 -04:00
|
|
|
thumbhash: entity.thumbhash?.toString('base64') || null,
|
2023-02-19 16:44:53 +00:00
|
|
|
fileCreatedAt: entity.fileCreatedAt,
|
|
|
|
|
fileModifiedAt: entity.fileModifiedAt,
|
2023-02-06 10:24:58 -06:00
|
|
|
updatedAt: entity.updatedAt,
|
2023-01-21 22:15:16 -06:00
|
|
|
isFavorite: entity.isFavorite,
|
2023-04-12 18:37:52 +03:00
|
|
|
isArchived: entity.isArchived,
|
2023-01-21 22:15:16 -06:00
|
|
|
duration: entity.duration ?? '0:00:00.00000',
|
|
|
|
|
exifInfo: undefined,
|
|
|
|
|
smartInfo: entity.smartInfo ? mapSmartInfo(entity.smartInfo) : undefined,
|
|
|
|
|
livePhotoVideoId: entity.livePhotoVideoId,
|
|
|
|
|
tags: entity.tags?.map(mapTag),
|
2023-05-17 13:07:17 -04:00
|
|
|
people: entity.faces?.map(mapFace),
|
2023-05-27 21:56:17 -04:00
|
|
|
checksum: entity.checksum.toString('base64'),
|
2023-01-21 22:15:16 -06:00
|
|
|
};
|
|
|
|
|
}
|