feat(server,web): libraries (#3124)

* feat: libraries

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
Jonathan Jogenfors 2023-09-20 13:16:33 +02:00 committed by GitHub
parent 816db700e1
commit acdc66413c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
143 changed files with 10941 additions and 386 deletions

View file

@ -0,0 +1,124 @@
import { LibraryEntity, LibraryType } from '@app/infra/entities';
import { ApiProperty } from '@nestjs/swagger';
import { 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 })
importPaths?: string[];
@IsOptional()
@IsString({ each: true })
@IsNotEmpty({ each: true })
exclusionPatterns?: string[];
}
export class UpdateLibraryDto {
@IsOptional()
@IsString()
@IsNotEmpty()
name?: string;
@IsOptional()
@IsBoolean()
isVisible?: boolean;
@IsOptional()
@IsString({ each: true })
@IsNotEmpty({ each: true })
importPaths?: string[];
@IsOptional()
@IsNotEmpty({ each: true })
@IsString({ each: true })
exclusionPatterns?: string[];
}
export class CrawlOptionsDto {
pathsToCrawl!: string[];
includeHidden? = false;
exclusionPatterns?: 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,
};
}