mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
5cd13227ad
* feat: server changes for album timeline * feat(web): album timeline view * chore: open api * chore: remove archive action * fix: favorite for non-owners
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { SharedLinkEntity, SharedLinkType } from '@app/infra/entities';
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
import _ from 'lodash';
|
|
import { AlbumResponseDto, mapAlbumWithoutAssets } from '../album';
|
|
import { AssetResponseDto, mapAsset, mapAssetWithoutExif } from '../asset';
|
|
|
|
export class SharedLinkResponseDto {
|
|
id!: string;
|
|
description!: string | null;
|
|
userId!: string;
|
|
key!: string;
|
|
|
|
@ApiProperty({ enumName: 'SharedLinkType', enum: SharedLinkType })
|
|
type!: SharedLinkType;
|
|
createdAt!: Date;
|
|
expiresAt!: Date | null;
|
|
assets!: AssetResponseDto[];
|
|
album?: AlbumResponseDto;
|
|
allowUpload!: boolean;
|
|
allowDownload!: boolean;
|
|
showExif!: boolean;
|
|
}
|
|
|
|
export function mapSharedLink(sharedLink: SharedLinkEntity): SharedLinkResponseDto {
|
|
const linkAssets = sharedLink.assets || [];
|
|
const albumAssets = (sharedLink?.album?.assets || []).map((asset) => asset);
|
|
|
|
const assets = _.uniqBy([...linkAssets, ...albumAssets], (asset) => asset.id);
|
|
|
|
return {
|
|
id: sharedLink.id,
|
|
description: sharedLink.description,
|
|
userId: sharedLink.userId,
|
|
key: sharedLink.key.toString('base64url'),
|
|
type: sharedLink.type,
|
|
createdAt: sharedLink.createdAt,
|
|
expiresAt: sharedLink.expiresAt,
|
|
assets: assets.map(mapAsset),
|
|
album: sharedLink.album ? mapAlbumWithoutAssets(sharedLink.album) : undefined,
|
|
allowUpload: sharedLink.allowUpload,
|
|
allowDownload: sharedLink.allowDownload,
|
|
showExif: sharedLink.showExif,
|
|
};
|
|
}
|
|
|
|
export function mapSharedLinkWithNoExif(sharedLink: SharedLinkEntity): SharedLinkResponseDto {
|
|
const linkAssets = sharedLink.assets || [];
|
|
const albumAssets = (sharedLink?.album?.assets || []).map((asset) => asset);
|
|
|
|
const assets = _.uniqBy([...linkAssets, ...albumAssets], (asset) => asset.id);
|
|
|
|
return {
|
|
id: sharedLink.id,
|
|
description: sharedLink.description,
|
|
userId: sharedLink.userId,
|
|
key: sharedLink.key.toString('base64url'),
|
|
type: sharedLink.type,
|
|
createdAt: sharedLink.createdAt,
|
|
expiresAt: sharedLink.expiresAt,
|
|
assets: assets.map(mapAssetWithoutExif),
|
|
album: sharedLink.album ? mapAlbumWithoutAssets(sharedLink.album) : undefined,
|
|
allowUpload: sharedLink.allowUpload,
|
|
allowDownload: sharedLink.allowDownload,
|
|
showExif: sharedLink.showExif,
|
|
};
|
|
}
|