mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
chunked upload controller
This commit is contained in:
parent
ea610760ee
commit
7f50f268a5
15 changed files with 734 additions and 17 deletions
133
server/src/dtos/upload.dto.ts
Normal file
133
server/src/dtos/upload.dto.ts
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
import { Type } from 'class-transformer';
|
||||
import { IsEnum, IsInt, IsNotEmpty, IsObject, IsString, IsUUID, ValidateNested } from 'class-validator';
|
||||
import { AssetMediaCreateDto } from 'src/dtos/asset-media.dto';
|
||||
|
||||
export enum TusdHookRequestType {
|
||||
PreCreate = 'pre-create',
|
||||
PreFinish = 'pre-finish',
|
||||
}
|
||||
|
||||
export enum TusdHookStorageType {
|
||||
FileStore = 'filestore',
|
||||
}
|
||||
|
||||
export class TusdStorageDto {
|
||||
@IsEnum(TusdHookStorageType)
|
||||
Type!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
Path!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
InfoPath!: string;
|
||||
}
|
||||
|
||||
export class UploadAssetDataDto extends AssetMediaCreateDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
declare filename: string;
|
||||
}
|
||||
|
||||
export class TusdMetaDataDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
declare AssetData: string; // base64-encoded JSON string of UploadAssetDataDto
|
||||
}
|
||||
|
||||
export class TusdPreCreateUploadDto {
|
||||
@IsInt()
|
||||
Size!: number;
|
||||
}
|
||||
|
||||
export class TusdPreFinishUploadDto {
|
||||
@IsUUID()
|
||||
ID!: string;
|
||||
|
||||
@IsInt()
|
||||
Size!: number;
|
||||
|
||||
@Type(() => TusdMetaDataDto)
|
||||
@ValidateNested()
|
||||
@IsObject()
|
||||
MetaData!: TusdMetaDataDto;
|
||||
|
||||
@Type(() => TusdStorageDto)
|
||||
@ValidateNested()
|
||||
@IsObject()
|
||||
Storage!: TusdStorageDto;
|
||||
}
|
||||
|
||||
export class TusdHttpRequestDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
Method!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
URI!: string;
|
||||
|
||||
@IsObject()
|
||||
Header!: Record<string, string[]>;
|
||||
}
|
||||
|
||||
export class TusdPreCreateEventDto {
|
||||
@Type(() => TusdPreCreateUploadDto)
|
||||
@ValidateNested()
|
||||
@IsObject()
|
||||
Upload!: TusdPreCreateUploadDto;
|
||||
|
||||
@Type(() => TusdHttpRequestDto)
|
||||
@ValidateNested()
|
||||
@IsObject()
|
||||
HTTPRequest!: TusdHttpRequestDto;
|
||||
}
|
||||
|
||||
export class TusdPreFinishEventDto {
|
||||
@Type(() => TusdPreFinishUploadDto)
|
||||
@ValidateNested()
|
||||
@IsObject()
|
||||
Upload!: TusdPreFinishUploadDto;
|
||||
|
||||
@Type(() => TusdHttpRequestDto)
|
||||
@ValidateNested()
|
||||
@IsObject()
|
||||
HTTPRequest!: TusdHttpRequestDto;
|
||||
}
|
||||
|
||||
export class TusdHookRequestDto {
|
||||
@IsEnum(TusdHookRequestType)
|
||||
Type!: TusdHookRequestType;
|
||||
|
||||
@IsObject()
|
||||
Event!: TusdPreCreateEventDto | TusdPreFinishEventDto;
|
||||
}
|
||||
|
||||
export class TusdHttpResponseDto {
|
||||
StatusCode!: number;
|
||||
|
||||
Body?: string;
|
||||
|
||||
Header?: Record<string, string>;
|
||||
}
|
||||
|
||||
export class TusdChangeFileInfoStorageDto {
|
||||
Path?: string;
|
||||
}
|
||||
|
||||
export class TusdChangeFileInfoDto {
|
||||
ID?: string;
|
||||
|
||||
MetaData?: TusdMetaDataDto;
|
||||
|
||||
Storage?: TusdChangeFileInfoStorageDto;
|
||||
}
|
||||
|
||||
export class TusdHookResponseDto {
|
||||
HTTPResponse?: TusdHttpResponseDto;
|
||||
|
||||
RejectUpload?: boolean;
|
||||
|
||||
ChangeFileInfo?: TusdChangeFileInfoDto;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue