2023-03-30 15:38:55 -04:00
|
|
|
import { SharedLinkEntity, SharedLinkType } from '@app/infra/entities';
|
2023-01-09 14:16:08 -06:00
|
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
|
|
|
import _ from 'lodash';
|
2023-01-25 11:35:28 -05:00
|
|
|
import { AlbumResponseDto, mapAlbumExcludeAssetInfo } from '../../album';
|
|
|
|
|
import { AssetResponseDto, mapAsset, mapAssetWithoutExif } from '../../asset';
|
2023-01-09 14:16:08 -06:00
|
|
|
|
|
|
|
|
export class SharedLinkResponseDto {
|
|
|
|
|
id!: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
userId!: string;
|
|
|
|
|
key!: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ enumName: 'SharedLinkType', enum: SharedLinkType })
|
|
|
|
|
type!: SharedLinkType;
|
|
|
|
|
createdAt!: string;
|
|
|
|
|
expiresAt!: string | null;
|
|
|
|
|
assets!: AssetResponseDto[];
|
|
|
|
|
album?: AlbumResponseDto;
|
|
|
|
|
allowUpload!: boolean;
|
2023-01-21 22:15:16 -06:00
|
|
|
allowDownload!: boolean;
|
|
|
|
|
showExif!: boolean;
|
2023-01-09 14:16:08 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 22:15:16 -06:00
|
|
|
export function mapSharedLink(sharedLink: SharedLinkEntity): SharedLinkResponseDto {
|
2023-01-09 14:16:08 -06:00
|
|
|
const linkAssets = sharedLink.assets || [];
|
2023-02-18 20:58:55 +00:00
|
|
|
const albumAssets = (sharedLink?.album?.assets || []).map((asset) => asset);
|
2023-01-09 14:16:08 -06:00
|
|
|
|
|
|
|
|
const assets = _.uniqBy([...linkAssets, ...albumAssets], (asset) => asset.id);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: sharedLink.id,
|
|
|
|
|
description: sharedLink.description,
|
|
|
|
|
userId: sharedLink.userId,
|
|
|
|
|
key: sharedLink.key.toString('hex'),
|
|
|
|
|
type: sharedLink.type,
|
|
|
|
|
createdAt: sharedLink.createdAt,
|
|
|
|
|
expiresAt: sharedLink.expiresAt,
|
|
|
|
|
assets: assets.map(mapAsset),
|
|
|
|
|
album: sharedLink.album ? mapAlbumExcludeAssetInfo(sharedLink.album) : undefined,
|
|
|
|
|
allowUpload: sharedLink.allowUpload,
|
2023-01-21 22:15:16 -06:00
|
|
|
allowDownload: sharedLink.allowDownload,
|
|
|
|
|
showExif: sharedLink.showExif,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function mapSharedLinkWithNoExif(sharedLink: SharedLinkEntity): SharedLinkResponseDto {
|
|
|
|
|
const linkAssets = sharedLink.assets || [];
|
2023-02-18 20:58:55 +00:00
|
|
|
const albumAssets = (sharedLink?.album?.assets || []).map((asset) => asset);
|
2023-01-21 22:15:16 -06:00
|
|
|
|
|
|
|
|
const assets = _.uniqBy([...linkAssets, ...albumAssets], (asset) => asset.id);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: sharedLink.id,
|
|
|
|
|
description: sharedLink.description,
|
|
|
|
|
userId: sharedLink.userId,
|
|
|
|
|
key: sharedLink.key.toString('hex'),
|
|
|
|
|
type: sharedLink.type,
|
|
|
|
|
createdAt: sharedLink.createdAt,
|
|
|
|
|
expiresAt: sharedLink.expiresAt,
|
|
|
|
|
assets: assets.map(mapAssetWithoutExif),
|
|
|
|
|
album: sharedLink.album ? mapAlbumExcludeAssetInfo(sharedLink.album) : undefined,
|
|
|
|
|
allowUpload: sharedLink.allowUpload,
|
|
|
|
|
allowDownload: sharedLink.allowDownload,
|
|
|
|
|
showExif: sharedLink.showExif,
|
2023-01-09 14:16:08 -06:00
|
|
|
};
|
|
|
|
|
}
|