refactor: asset v1, app.utils (#8152)

This commit is contained in:
Jason Rasmussen
2024-03-21 08:07:47 -05:00
committed by GitHub
parent 87ccba7f9d
commit 382b63954c
34 changed files with 518 additions and 548 deletions
+45
View File
@@ -0,0 +1,45 @@
export class AssetBulkUploadCheckResult {
id!: string;
action!: AssetUploadAction;
reason?: AssetRejectReason;
assetId?: string;
}
export class AssetBulkUploadCheckResponseDto {
results!: AssetBulkUploadCheckResult[];
}
export enum AssetUploadAction {
ACCEPT = 'accept',
REJECT = 'reject',
}
export enum AssetRejectReason {
DUPLICATE = 'duplicate',
UNSUPPORTED_FORMAT = 'unsupported-format',
}
export class AssetFileUploadResponseDto {
id!: string;
duplicate!: boolean;
}
export class CheckExistingAssetsResponseDto {
existingIds!: string[];
}
export class CuratedLocationsResponseDto {
id!: string;
city!: string;
resizePath!: string;
deviceAssetId!: string;
deviceId!: string;
}
export class CuratedObjectsResponseDto {
id!: string;
object!: string;
resizePath!: string;
deviceAssetId!: string;
deviceId!: string;
}
+154
View File
@@ -0,0 +1,154 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { ArrayNotEmpty, IsArray, IsEnum, IsInt, IsNotEmpty, IsString, IsUUID, ValidateNested } from 'class-validator';
import { UploadFieldName } from 'src/dtos/asset.dto';
import { Optional, ValidateBoolean, ValidateDate, ValidateUUID } from 'src/validation';
export class AssetBulkUploadCheckItem {
@IsString()
@IsNotEmpty()
id!: string;
/** base64 or hex encoded sha1 hash */
@IsString()
@IsNotEmpty()
checksum!: string;
}
export class AssetBulkUploadCheckDto {
@IsArray()
@ValidateNested({ each: true })
@Type(() => AssetBulkUploadCheckItem)
assets!: AssetBulkUploadCheckItem[];
}
export class AssetSearchDto {
@ValidateBoolean({ optional: true })
isFavorite?: boolean;
@ValidateBoolean({ optional: true })
isArchived?: boolean;
@Optional()
@IsInt()
@Type(() => Number)
@ApiProperty({ type: 'integer' })
skip?: number;
@Optional()
@IsInt()
@Type(() => Number)
@ApiProperty({ type: 'integer' })
take?: number;
@Optional()
@IsUUID('4')
@ApiProperty({ format: 'uuid' })
userId?: string;
@ValidateDate({ optional: true })
updatedAfter?: Date;
@ValidateDate({ optional: true })
updatedBefore?: Date;
}
export class CheckExistingAssetsDto {
@ArrayNotEmpty()
@IsString({ each: true })
@IsNotEmpty({ each: true })
deviceAssetIds!: string[];
@IsNotEmpty()
deviceId!: string;
}
export class CreateAssetDto {
@ValidateUUID({ optional: true })
libraryId?: string;
@IsNotEmpty()
@IsString()
deviceAssetId!: string;
@IsNotEmpty()
@IsString()
deviceId!: string;
@ValidateDate()
fileCreatedAt!: Date;
@ValidateDate()
fileModifiedAt!: Date;
@Optional()
@IsString()
duration?: string;
@ValidateBoolean({ optional: true })
isFavorite?: boolean;
@ValidateBoolean({ optional: true })
isArchived?: boolean;
@ValidateBoolean({ optional: true })
isVisible?: boolean;
@ValidateBoolean({ optional: true })
isOffline?: boolean;
@ValidateBoolean({ optional: true })
isReadOnly?: boolean;
// The properties below are added to correctly generate the API docs
// and client SDKs. Validation should be handled in the controller.
@ApiProperty({ type: 'string', format: 'binary' })
[UploadFieldName.ASSET_DATA]!: any;
@ApiProperty({ type: 'string', format: 'binary', required: false })
[UploadFieldName.LIVE_PHOTO_DATA]?: any;
@ApiProperty({ type: 'string', format: 'binary', required: false })
[UploadFieldName.SIDECAR_DATA]?: any;
}
export enum GetAssetThumbnailFormatEnum {
JPEG = 'JPEG',
WEBP = 'WEBP',
}
export class GetAssetThumbnailDto {
@Optional()
@IsEnum(GetAssetThumbnailFormatEnum)
@ApiProperty({
type: String,
enum: GetAssetThumbnailFormatEnum,
default: GetAssetThumbnailFormatEnum.WEBP,
required: false,
enumName: 'ThumbnailFormat',
})
format: GetAssetThumbnailFormatEnum = GetAssetThumbnailFormatEnum.WEBP;
}
export class SearchPropertiesDto {
tags?: string[];
objects?: string[];
assetType?: string;
orientation?: string;
lensModel?: string;
make?: string;
model?: string;
city?: string;
state?: string;
country?: string;
}
export class ServeFileDto {
@ValidateBoolean({ optional: true })
@ApiProperty({ title: 'Is serve thumbnail (resize) file' })
isThumb?: boolean;
@ValidateBoolean({ optional: true })
@ApiProperty({ title: 'Is request made from web' })
isWeb?: boolean;
}