mirror of
https://github.com/immich-app/immich.git
synced 2026-02-13 12:27:56 +03:00
* faces * add openapi descriptions * remove dto descriptions * gen openapi * dtos * fix dtos * fix more * fix build * more * complete dtos * descriptions on rebase * gen rebase * revert correct integer type conversion * gen after revert * revert correct nullables * regen after revert * actually incorrect adding default here * revert correct number type conversion * regen after revert * revert nullable usage * regen fully * readd some comments * one more * one more * use enum * add missing * add missing controllers * add missing dtos * complete it * more * describe global key and slug * add remaining body and param descriptions * lint and format * cleanup * response and schema descriptions * test patch according to suggestion * revert added api response objects * revert added api body objects * revert added api param object * revert added api query objects * revert reorganized http code objects * revert reorganize ApiOkResponse objects * revert added api response objects (2) * revert added api tag object * revert added api schema objects * migrate missing asset.dto.ts * regenerate openapi builds * delete generated mustache files * remove descriptions from properties that are schemas * lint * revert nullable type changes * revert int/num type changes * remove explicit default * readd comment * lint * pr fixes * last bits and pieces * lint and format * chore: remove rejected patches * fix: deleting asset from asset-viewer on search results (#25596) * fix: escape handling in search asset viewer (#25621) * fix: correctly show owner in album options modal (#25618) * fix: validation issues * fix: validation issues --------- Co-authored-by: Jason Rasmussen <jason@rasm.me> Co-authored-by: Min Idzelis <min123@gmail.com> Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Co-authored-by: Paul Makles <me@insrt.uk>
174 lines
5.7 KiB
TypeScript
174 lines
5.7 KiB
TypeScript
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
import { IsString } from 'class-validator';
|
|
import { SharedLink } from 'src/database';
|
|
import { HistoryBuilder } from 'src/decorators';
|
|
import { AlbumResponseDto, mapAlbumWithoutAssets } from 'src/dtos/album.dto';
|
|
import { AssetResponseDto, mapAsset } from 'src/dtos/asset-response.dto';
|
|
import { SharedLinkType } from 'src/enum';
|
|
import { Optional, ValidateBoolean, ValidateDate, ValidateEnum, ValidateUUID } from 'src/validation';
|
|
|
|
export class SharedLinkSearchDto {
|
|
@ValidateUUID({ optional: true, description: 'Filter by album ID' })
|
|
albumId?: string;
|
|
|
|
@ValidateUUID({
|
|
optional: true,
|
|
description: 'Filter by shared link ID',
|
|
history: new HistoryBuilder().added('v2.5.0'),
|
|
})
|
|
id?: string;
|
|
}
|
|
|
|
export class SharedLinkCreateDto {
|
|
@ValidateEnum({ enum: SharedLinkType, name: 'SharedLinkType', description: 'Shared link type' })
|
|
type!: SharedLinkType;
|
|
|
|
@ValidateUUID({ each: true, optional: true, description: 'Asset IDs (for individual assets)' })
|
|
assetIds?: string[];
|
|
|
|
@ValidateUUID({ optional: true, description: 'Album ID (for album sharing)' })
|
|
albumId?: string;
|
|
|
|
@ApiPropertyOptional({ description: 'Link description' })
|
|
@Optional({ nullable: true, emptyToNull: true })
|
|
@IsString()
|
|
description?: string | null;
|
|
|
|
@ApiPropertyOptional({ description: 'Link password' })
|
|
@Optional({ nullable: true, emptyToNull: true })
|
|
@IsString()
|
|
password?: string | null;
|
|
|
|
@ApiPropertyOptional({ description: 'Custom URL slug' })
|
|
@Optional({ nullable: true, emptyToNull: true })
|
|
@IsString()
|
|
slug?: string | null;
|
|
|
|
@ValidateDate({ optional: true, description: 'Expiration date' })
|
|
expiresAt?: Date | null = null;
|
|
|
|
@ValidateBoolean({ optional: true, description: 'Allow uploads' })
|
|
allowUpload?: boolean;
|
|
|
|
@ValidateBoolean({ optional: true, description: 'Allow downloads', default: true })
|
|
allowDownload?: boolean = true;
|
|
|
|
@ValidateBoolean({ optional: true, description: 'Show metadata', default: true })
|
|
showMetadata?: boolean = true;
|
|
}
|
|
|
|
export class SharedLinkEditDto {
|
|
@ApiPropertyOptional({ description: 'Link description' })
|
|
@Optional({ nullable: true, emptyToNull: true })
|
|
@IsString()
|
|
description?: string | null;
|
|
|
|
@ApiPropertyOptional({ description: 'Link password' })
|
|
@Optional({ nullable: true, emptyToNull: true })
|
|
@IsString()
|
|
password?: string | null;
|
|
|
|
@ApiPropertyOptional({ description: 'Custom URL slug' })
|
|
@Optional({ nullable: true, emptyToNull: true })
|
|
@IsString()
|
|
slug?: string | null;
|
|
|
|
@ApiPropertyOptional({ description: 'Expiration date' })
|
|
@Optional({ nullable: true })
|
|
expiresAt?: Date | null;
|
|
|
|
@ValidateBoolean({ optional: true, description: 'Allow uploads' })
|
|
allowUpload?: boolean;
|
|
|
|
@ValidateBoolean({ optional: true, description: 'Allow downloads' })
|
|
allowDownload?: boolean;
|
|
|
|
@ValidateBoolean({ optional: true, description: 'Show metadata' })
|
|
showMetadata?: boolean;
|
|
|
|
@ValidateBoolean({
|
|
optional: true,
|
|
description:
|
|
'Whether to change the expiry time. Few clients cannot send null to set the expiryTime to never. Setting this flag and not sending expiryAt is considered as null instead. Clients that can send null values can ignore this.',
|
|
})
|
|
changeExpiryTime?: boolean;
|
|
}
|
|
|
|
export class SharedLinkPasswordDto {
|
|
@ApiPropertyOptional({ example: 'password', description: 'Link password' })
|
|
@IsString()
|
|
@Optional()
|
|
password?: string;
|
|
|
|
@ApiPropertyOptional({ description: 'Access token' })
|
|
@IsString()
|
|
@Optional()
|
|
token?: string;
|
|
}
|
|
export class SharedLinkResponseDto {
|
|
@ApiProperty({ description: 'Shared link ID' })
|
|
id!: string;
|
|
@ApiProperty({ description: 'Link description' })
|
|
description!: string | null;
|
|
@ApiProperty({ description: 'Has password' })
|
|
password!: string | null;
|
|
@ApiPropertyOptional({ description: 'Access token' })
|
|
token?: string | null;
|
|
@ApiProperty({ description: 'Owner user ID' })
|
|
userId!: string;
|
|
@ApiProperty({ description: 'Encryption key (base64url)' })
|
|
key!: string;
|
|
|
|
@ValidateEnum({ enum: SharedLinkType, name: 'SharedLinkType', description: 'Shared link type' })
|
|
type!: SharedLinkType;
|
|
@ApiProperty({ description: 'Creation date' })
|
|
createdAt!: Date;
|
|
@ApiProperty({ description: 'Expiration date' })
|
|
expiresAt!: Date | null;
|
|
// Description lives on schema to avoid duplication
|
|
@ApiProperty({ description: undefined })
|
|
assets!: AssetResponseDto[];
|
|
// Description lives on schema to avoid duplication
|
|
@ApiPropertyOptional({ description: undefined })
|
|
album?: AlbumResponseDto;
|
|
@ApiProperty({ description: 'Allow uploads' })
|
|
allowUpload!: boolean;
|
|
|
|
@ApiProperty({ description: 'Allow downloads' })
|
|
allowDownload!: boolean;
|
|
@ApiProperty({ description: 'Show metadata' })
|
|
showMetadata!: boolean;
|
|
|
|
@ApiProperty({ description: 'Custom URL slug' })
|
|
slug!: string | null;
|
|
}
|
|
|
|
export function mapSharedLink(sharedLink: SharedLink, options: { stripAssetMetadata: boolean }): SharedLinkResponseDto {
|
|
const assets = sharedLink.assets || [];
|
|
|
|
const response = {
|
|
id: sharedLink.id,
|
|
description: sharedLink.description,
|
|
password: sharedLink.password,
|
|
userId: sharedLink.userId,
|
|
key: sharedLink.key.toString('base64url'),
|
|
type: sharedLink.type,
|
|
createdAt: sharedLink.createdAt,
|
|
expiresAt: sharedLink.expiresAt,
|
|
assets: assets.map((asset) => mapAsset(asset, { stripMetadata: options.stripAssetMetadata })),
|
|
album: sharedLink.album ? mapAlbumWithoutAssets(sharedLink.album) : undefined,
|
|
allowUpload: sharedLink.allowUpload,
|
|
allowDownload: sharedLink.allowDownload,
|
|
showMetadata: sharedLink.showExif,
|
|
slug: sharedLink.slug,
|
|
};
|
|
|
|
// unless we select sharedLink.album.sharedLinks this will be wrong
|
|
if (response.album) {
|
|
response.album.hasSharedLink = true;
|
|
response.album.shared = true;
|
|
}
|
|
|
|
return response;
|
|
}
|