mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	fix(web,server): use POST request to get download info (#3694)
* fix(web,server): use POST request to get download info * chore: open api
This commit is contained in:
		| @@ -1026,84 +1026,7 @@ | ||||
|         ] | ||||
|       } | ||||
|     }, | ||||
|     "/asset/download": { | ||||
|       "get": { | ||||
|         "operationId": "getDownloadInfo", | ||||
|         "parameters": [ | ||||
|           { | ||||
|             "name": "assetIds", | ||||
|             "required": false, | ||||
|             "in": "query", | ||||
|             "schema": { | ||||
|               "format": "uuid", | ||||
|               "type": "array", | ||||
|               "items": { | ||||
|                 "type": "string" | ||||
|               } | ||||
|             } | ||||
|           }, | ||||
|           { | ||||
|             "name": "albumId", | ||||
|             "required": false, | ||||
|             "in": "query", | ||||
|             "schema": { | ||||
|               "format": "uuid", | ||||
|               "type": "string" | ||||
|             } | ||||
|           }, | ||||
|           { | ||||
|             "name": "userId", | ||||
|             "required": false, | ||||
|             "in": "query", | ||||
|             "schema": { | ||||
|               "format": "uuid", | ||||
|               "type": "string" | ||||
|             } | ||||
|           }, | ||||
|           { | ||||
|             "name": "archiveSize", | ||||
|             "required": false, | ||||
|             "in": "query", | ||||
|             "schema": { | ||||
|               "type": "number" | ||||
|             } | ||||
|           }, | ||||
|           { | ||||
|             "name": "key", | ||||
|             "required": false, | ||||
|             "in": "query", | ||||
|             "schema": { | ||||
|               "type": "string" | ||||
|             } | ||||
|           } | ||||
|         ], | ||||
|         "responses": { | ||||
|           "200": { | ||||
|             "content": { | ||||
|               "application/json": { | ||||
|                 "schema": { | ||||
|                   "$ref": "#/components/schemas/DownloadResponseDto" | ||||
|                 } | ||||
|               } | ||||
|             }, | ||||
|             "description": "" | ||||
|           } | ||||
|         }, | ||||
|         "security": [ | ||||
|           { | ||||
|             "bearer": [] | ||||
|           }, | ||||
|           { | ||||
|             "cookie": [] | ||||
|           }, | ||||
|           { | ||||
|             "api_key": [] | ||||
|           } | ||||
|         ], | ||||
|         "tags": [ | ||||
|           "Asset" | ||||
|         ] | ||||
|       }, | ||||
|     "/asset/download/archive": { | ||||
|       "post": { | ||||
|         "operationId": "downloadArchive", | ||||
|         "parameters": [ | ||||
| @@ -1155,6 +1078,57 @@ | ||||
|         ] | ||||
|       } | ||||
|     }, | ||||
|     "/asset/download/info": { | ||||
|       "post": { | ||||
|         "operationId": "getDownloadInfo", | ||||
|         "parameters": [ | ||||
|           { | ||||
|             "name": "key", | ||||
|             "required": false, | ||||
|             "in": "query", | ||||
|             "schema": { | ||||
|               "type": "string" | ||||
|             } | ||||
|           } | ||||
|         ], | ||||
|         "requestBody": { | ||||
|           "content": { | ||||
|             "application/json": { | ||||
|               "schema": { | ||||
|                 "$ref": "#/components/schemas/DownloadInfoDto" | ||||
|               } | ||||
|             } | ||||
|           }, | ||||
|           "required": true | ||||
|         }, | ||||
|         "responses": { | ||||
|           "201": { | ||||
|             "content": { | ||||
|               "application/json": { | ||||
|                 "schema": { | ||||
|                   "$ref": "#/components/schemas/DownloadResponseDto" | ||||
|                 } | ||||
|               } | ||||
|             }, | ||||
|             "description": "" | ||||
|           } | ||||
|         }, | ||||
|         "security": [ | ||||
|           { | ||||
|             "bearer": [] | ||||
|           }, | ||||
|           { | ||||
|             "cookie": [] | ||||
|           }, | ||||
|           { | ||||
|             "api_key": [] | ||||
|           } | ||||
|         ], | ||||
|         "tags": [ | ||||
|           "Asset" | ||||
|         ] | ||||
|       } | ||||
|     }, | ||||
|     "/asset/download/{id}": { | ||||
|       "post": { | ||||
|         "operationId": "downloadFile", | ||||
| @@ -5549,6 +5523,29 @@ | ||||
|         ], | ||||
|         "type": "object" | ||||
|       }, | ||||
|       "DownloadInfoDto": { | ||||
|         "properties": { | ||||
|           "albumId": { | ||||
|             "format": "uuid", | ||||
|             "type": "string" | ||||
|           }, | ||||
|           "archiveSize": { | ||||
|             "type": "integer" | ||||
|           }, | ||||
|           "assetIds": { | ||||
|             "items": { | ||||
|               "format": "uuid", | ||||
|               "type": "string" | ||||
|             }, | ||||
|             "type": "array" | ||||
|           }, | ||||
|           "userId": { | ||||
|             "format": "uuid", | ||||
|             "type": "string" | ||||
|           } | ||||
|         }, | ||||
|         "type": "object" | ||||
|       }, | ||||
|       "DownloadResponseDto": { | ||||
|         "properties": { | ||||
|           "archives": { | ||||
|   | ||||
| @@ -13,7 +13,7 @@ import { IAssetRepository } from './asset.repository'; | ||||
| import { | ||||
|   AssetIdsDto, | ||||
|   DownloadArchiveInfo, | ||||
|   DownloadDto, | ||||
|   DownloadInfoDto, | ||||
|   DownloadResponseDto, | ||||
|   MemoryLaneDto, | ||||
|   TimeBucketAssetDto, | ||||
| @@ -176,7 +176,7 @@ export class AssetService { | ||||
|     return this.storageRepository.createReadStream(asset.originalPath, mimeTypes.lookup(asset.originalPath)); | ||||
|   } | ||||
|  | ||||
|   async getDownloadInfo(authUser: AuthUserDto, dto: DownloadDto): Promise<DownloadResponseDto> { | ||||
|   async getDownloadInfo(authUser: AuthUserDto, dto: DownloadInfoDto): Promise<DownloadResponseDto> { | ||||
|     const targetSize = dto.archiveSize || HumanReadableSize.GiB * 4; | ||||
|     const archives: DownloadArchiveInfo[] = []; | ||||
|     let archive: DownloadArchiveInfo = { size: 0, assetIds: [] }; | ||||
| @@ -234,7 +234,7 @@ export class AssetService { | ||||
|     return { stream: zip.stream }; | ||||
|   } | ||||
|  | ||||
|   private async getDownloadAssets(authUser: AuthUserDto, dto: DownloadDto): Promise<AsyncGenerator<AssetEntity[]>> { | ||||
|   private async getDownloadAssets(authUser: AuthUserDto, dto: DownloadInfoDto): Promise<AsyncGenerator<AssetEntity[]>> { | ||||
|     const PAGINATION_SIZE = 2500; | ||||
|  | ||||
|     if (dto.assetIds) { | ||||
|   | ||||
| @@ -2,7 +2,7 @@ import { ApiProperty } from '@nestjs/swagger'; | ||||
| import { IsInt, IsOptional, IsPositive } from 'class-validator'; | ||||
| import { ValidateUUID } from '../../domain.util'; | ||||
|  | ||||
| export class DownloadDto { | ||||
| export class DownloadInfoDto { | ||||
|   @ValidateUUID({ each: true, optional: true }) | ||||
|   assetIds?: string[]; | ||||
|  | ||||
| @@ -15,6 +15,7 @@ export class DownloadDto { | ||||
|   @IsInt() | ||||
|   @IsPositive() | ||||
|   @IsOptional() | ||||
|   @ApiProperty({ type: 'integer' }) | ||||
|   archiveSize?: number; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import { | ||||
|   AssetStatsDto, | ||||
|   AssetStatsResponseDto, | ||||
|   AuthUserDto, | ||||
|   DownloadDto, | ||||
|   DownloadInfoDto, | ||||
|   DownloadResponseDto, | ||||
|   MapMarkerResponseDto, | ||||
|   MemoryLaneDto, | ||||
| @@ -39,13 +39,13 @@ export class AssetController { | ||||
|   } | ||||
|  | ||||
|   @SharedLinkRoute() | ||||
|   @Get('download') | ||||
|   getDownloadInfo(@AuthUser() authUser: AuthUserDto, @Query() dto: DownloadDto): Promise<DownloadResponseDto> { | ||||
|   @Post('download/info') | ||||
|   getDownloadInfo(@AuthUser() authUser: AuthUserDto, @Body() dto: DownloadInfoDto): Promise<DownloadResponseDto> { | ||||
|     return this.service.getDownloadInfo(authUser, dto); | ||||
|   } | ||||
|  | ||||
|   @SharedLinkRoute() | ||||
|   @Post('download') | ||||
|   @Post('download/archive') | ||||
|   @HttpCode(HttpStatus.OK) | ||||
|   @ApiOkResponse({ content: { 'application/octet-stream': { schema: { type: 'string', format: 'binary' } } } }) | ||||
|   downloadArchive(@AuthUser() authUser: AuthUserDto, @Body() dto: AssetIdsDto): Promise<StreamableFile> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user