2023-01-09 14:16:08 -06:00
|
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
|
|
|
import _ from 'lodash';
|
2024-03-20 19:32:04 +01:00
|
|
|
import { AlbumResponseDto, mapAlbumWithoutAssets } from 'src/domain/album/album-response.dto';
|
|
|
|
|
import { AssetResponseDto, mapAsset } from 'src/domain/asset/response-dto/asset-response.dto';
|
2024-03-20 16:02:51 -05:00
|
|
|
import { SharedLinkEntity, SharedLinkType } from 'src/entities/shared-link.entity';
|
2023-01-09 14:16:08 -06:00
|
|
|
|
|
|
|
|
export class SharedLinkResponseDto {
|
|
|
|
|
id!: string;
|
2023-06-20 21:08:43 -04:00
|
|
|
description!: string | null;
|
2023-10-29 09:35:38 +08:00
|
|
|
password!: string | null;
|
|
|
|
|
token?: string | null;
|
2023-01-09 14:16:08 -06:00
|
|
|
userId!: string;
|
|
|
|
|
key!: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ enumName: 'SharedLinkType', enum: SharedLinkType })
|
|
|
|
|
type!: SharedLinkType;
|
2023-05-30 15:15:56 +02:00
|
|
|
createdAt!: Date;
|
|
|
|
|
expiresAt!: Date | null;
|
2023-01-09 14:16:08 -06:00
|
|
|
assets!: AssetResponseDto[];
|
|
|
|
|
album?: AlbumResponseDto;
|
|
|
|
|
allowUpload!: boolean;
|
2023-10-14 03:46:30 +02:00
|
|
|
|
2023-01-21 22:15:16 -06:00
|
|
|
allowDownload!: boolean;
|
2023-10-14 03:46:30 +02:00
|
|
|
showMetadata!: 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,
|
2023-10-29 09:35:38 +08:00
|
|
|
password: sharedLink.password,
|
2023-01-09 14:16:08 -06:00
|
|
|
userId: sharedLink.userId,
|
2023-06-01 16:56:37 -04:00
|
|
|
key: sharedLink.key.toString('base64url'),
|
2023-01-09 14:16:08 -06:00
|
|
|
type: sharedLink.type,
|
|
|
|
|
createdAt: sharedLink.createdAt,
|
|
|
|
|
expiresAt: sharedLink.expiresAt,
|
2023-10-14 03:46:30 +02:00
|
|
|
assets: assets.map((asset) => mapAsset(asset)),
|
2023-11-21 10:07:49 -06:00
|
|
|
album: sharedLink.album ? mapAlbumWithoutAssets(sharedLink.album) : undefined,
|
2023-01-09 14:16:08 -06:00
|
|
|
allowUpload: sharedLink.allowUpload,
|
2023-01-21 22:15:16 -06:00
|
|
|
allowDownload: sharedLink.allowDownload,
|
2023-10-14 03:46:30 +02:00
|
|
|
showMetadata: sharedLink.showExif,
|
2023-01-21 22:15:16 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 03:46:30 +02:00
|
|
|
export function mapSharedLinkWithoutMetadata(sharedLink: SharedLinkEntity): SharedLinkResponseDto {
|
2023-01-21 22:15:16 -06:00
|
|
|
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,
|
2023-10-29 09:35:38 +08:00
|
|
|
password: sharedLink.password,
|
2023-01-21 22:15:16 -06:00
|
|
|
userId: sharedLink.userId,
|
2023-06-01 16:56:37 -04:00
|
|
|
key: sharedLink.key.toString('base64url'),
|
2023-01-21 22:15:16 -06:00
|
|
|
type: sharedLink.type,
|
|
|
|
|
createdAt: sharedLink.createdAt,
|
|
|
|
|
expiresAt: sharedLink.expiresAt,
|
2023-10-22 02:38:07 +00:00
|
|
|
assets: assets.map((asset) => mapAsset(asset, { stripMetadata: true })) as AssetResponseDto[],
|
2023-08-11 12:00:51 -04:00
|
|
|
album: sharedLink.album ? mapAlbumWithoutAssets(sharedLink.album) : undefined,
|
2023-01-21 22:15:16 -06:00
|
|
|
allowUpload: sharedLink.allowUpload,
|
|
|
|
|
allowDownload: sharedLink.allowDownload,
|
2023-10-14 03:46:30 +02:00
|
|
|
showMetadata: sharedLink.showExif,
|
2023-01-09 14:16:08 -06:00
|
|
|
};
|
|
|
|
|
}
|