mirror of
https://github.com/KevinMidboe/immich.git
synced 2026-01-26 02:55:49 +00:00
* feat: server changes for album timeline * feat(web): album timeline view * chore: open api * chore: remove archive action * fix: favorite for non-owners
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { AlbumEntity } from '@app/infra/entities';
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
import { AssetResponseDto, mapAsset } from '../asset';
|
|
import { mapUser, UserResponseDto } from '../user';
|
|
|
|
export class AlbumResponseDto {
|
|
id!: string;
|
|
ownerId!: string;
|
|
albumName!: string;
|
|
description!: string;
|
|
createdAt!: Date;
|
|
updatedAt!: Date;
|
|
albumThumbnailAssetId!: string | null;
|
|
shared!: boolean;
|
|
sharedUsers!: UserResponseDto[];
|
|
hasSharedLink!: boolean;
|
|
assets!: AssetResponseDto[];
|
|
owner!: UserResponseDto;
|
|
@ApiProperty({ type: 'integer' })
|
|
assetCount!: number;
|
|
lastModifiedAssetTimestamp?: Date;
|
|
startDate?: Date;
|
|
endDate?: Date;
|
|
}
|
|
|
|
export const mapAlbum = (entity: AlbumEntity, withAssets: boolean): AlbumResponseDto => {
|
|
const sharedUsers: UserResponseDto[] = [];
|
|
|
|
entity.sharedUsers?.forEach((user) => {
|
|
const userDto = mapUser(user);
|
|
sharedUsers.push(userDto);
|
|
});
|
|
|
|
const assets = entity.assets || [];
|
|
|
|
const hasSharedLink = entity.sharedLinks?.length > 0;
|
|
const hasSharedUser = sharedUsers.length > 0;
|
|
|
|
return {
|
|
albumName: entity.albumName,
|
|
description: entity.description,
|
|
albumThumbnailAssetId: entity.albumThumbnailAssetId,
|
|
createdAt: entity.createdAt,
|
|
updatedAt: entity.updatedAt,
|
|
id: entity.id,
|
|
ownerId: entity.ownerId,
|
|
owner: mapUser(entity.owner),
|
|
sharedUsers,
|
|
shared: hasSharedUser || hasSharedLink,
|
|
hasSharedLink,
|
|
startDate: assets.at(0)?.fileCreatedAt || undefined,
|
|
endDate: assets.at(-1)?.fileCreatedAt || undefined,
|
|
assets: (withAssets ? assets : []).map((asset) => mapAsset(asset)),
|
|
assetCount: entity.assets?.length || 0,
|
|
};
|
|
};
|
|
|
|
export const mapAlbumWithAssets = (entity: AlbumEntity) => mapAlbum(entity, true);
|
|
export const mapAlbumWithoutAssets = (entity: AlbumEntity) => mapAlbum(entity, false);
|
|
|
|
export class AlbumCountResponseDto {
|
|
@ApiProperty({ type: 'integer' })
|
|
owned!: number;
|
|
|
|
@ApiProperty({ type: 'integer' })
|
|
shared!: number;
|
|
|
|
@ApiProperty({ type: 'integer' })
|
|
notShared!: number;
|
|
}
|