mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-24 14:37:44 +00:00
* add library validation api * chore: open api * show warning i UI * add flex row * fix e2e * tests * fix tests * enforce path validation * enforce validation on refresh * return 400 on bad import path * add limits to import paths * set response code to 200 * fix e2e * fix lint * fix test * restore e2e folder * fix import * use startsWith * icon color * notify user of failed validation * add parent div to validation * add docs to the import validation * improve library troubleshooting docs * fix button alignment --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
162 lines
3.3 KiB
TypeScript
162 lines
3.3 KiB
TypeScript
import { LibraryEntity, LibraryType } from '@app/infra/entities';
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
import { ArrayMaxSize, ArrayUnique, IsBoolean, IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
|
import { ValidateUUID } from '../domain.util';
|
|
|
|
export class CreateLibraryDto {
|
|
@IsEnum(LibraryType)
|
|
@ApiProperty({ enumName: 'LibraryType', enum: LibraryType })
|
|
type!: LibraryType;
|
|
|
|
@IsString()
|
|
@IsOptional()
|
|
@IsNotEmpty()
|
|
name?: string;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
isVisible?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsString({ each: true })
|
|
@IsNotEmpty({ each: true })
|
|
@ArrayUnique()
|
|
@ArrayMaxSize(128)
|
|
importPaths?: string[];
|
|
|
|
@IsOptional()
|
|
@IsString({ each: true })
|
|
@IsNotEmpty({ each: true })
|
|
@ArrayUnique()
|
|
@ArrayMaxSize(128)
|
|
exclusionPatterns?: string[];
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
isWatched?: boolean;
|
|
}
|
|
|
|
export class UpdateLibraryDto {
|
|
@IsOptional()
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
name?: string;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
isVisible?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsString({ each: true })
|
|
@IsNotEmpty({ each: true })
|
|
@ArrayUnique()
|
|
@ArrayMaxSize(128)
|
|
importPaths?: string[];
|
|
|
|
@IsOptional()
|
|
@IsNotEmpty({ each: true })
|
|
@IsString({ each: true })
|
|
@ArrayUnique()
|
|
@ArrayMaxSize(128)
|
|
exclusionPatterns?: string[];
|
|
}
|
|
|
|
export class CrawlOptionsDto {
|
|
pathsToCrawl!: string[];
|
|
includeHidden? = false;
|
|
exclusionPatterns?: string[];
|
|
}
|
|
|
|
export class ValidateLibraryDto {
|
|
@IsOptional()
|
|
@IsString({ each: true })
|
|
@IsNotEmpty({ each: true })
|
|
@ArrayUnique()
|
|
@ArrayMaxSize(128)
|
|
importPaths?: string[];
|
|
|
|
@IsOptional()
|
|
@IsNotEmpty({ each: true })
|
|
@IsString({ each: true })
|
|
@ArrayUnique()
|
|
@ArrayMaxSize(128)
|
|
exclusionPatterns?: string[];
|
|
}
|
|
|
|
export class ValidateLibraryResponseDto {
|
|
importPaths?: ValidateLibraryImportPathResponseDto[];
|
|
}
|
|
|
|
export class ValidateLibraryImportPathResponseDto {
|
|
importPath!: string;
|
|
isValid?: boolean = false;
|
|
message?: string;
|
|
}
|
|
|
|
export class LibrarySearchDto {
|
|
@ValidateUUID({ optional: true })
|
|
userId?: string;
|
|
}
|
|
|
|
export class ScanLibraryDto {
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
refreshModifiedFiles?: boolean;
|
|
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
refreshAllFiles?: boolean = false;
|
|
}
|
|
|
|
export class LibraryResponseDto {
|
|
id!: string;
|
|
ownerId!: string;
|
|
name!: string;
|
|
|
|
@ApiProperty({ enumName: 'LibraryType', enum: LibraryType })
|
|
type!: LibraryType;
|
|
|
|
@ApiProperty({ type: 'integer' })
|
|
assetCount!: number;
|
|
|
|
importPaths!: string[];
|
|
|
|
exclusionPatterns!: string[];
|
|
|
|
createdAt!: Date;
|
|
updatedAt!: Date;
|
|
refreshedAt!: Date | null;
|
|
}
|
|
|
|
export class LibraryStatsResponseDto {
|
|
@ApiProperty({ type: 'integer' })
|
|
photos = 0;
|
|
|
|
@ApiProperty({ type: 'integer' })
|
|
videos = 0;
|
|
|
|
@ApiProperty({ type: 'integer' })
|
|
total = 0;
|
|
|
|
@ApiProperty({ type: 'integer', format: 'int64' })
|
|
usage = 0;
|
|
}
|
|
|
|
export function mapLibrary(entity: LibraryEntity): LibraryResponseDto {
|
|
let assetCount = 0;
|
|
if (entity.assets) {
|
|
assetCount = entity.assets.length;
|
|
}
|
|
return {
|
|
id: entity.id,
|
|
ownerId: entity.ownerId,
|
|
type: entity.type,
|
|
name: entity.name,
|
|
createdAt: entity.createdAt,
|
|
updatedAt: entity.updatedAt,
|
|
refreshedAt: entity.refreshedAt,
|
|
assetCount,
|
|
importPaths: entity.importPaths,
|
|
exclusionPatterns: entity.exclusionPatterns,
|
|
};
|
|
}
|