2024-05-31 13:44:04 -04:00
import { Body , Controller , HttpCode , HttpStatus , Post , StreamableFile } from '@nestjs/common' ;
2025-11-11 17:01:14 -05:00
import { ApiOperation , ApiTags } from '@nestjs/swagger' ;
2024-03-20 23:53:07 +01:00
import { AssetIdsDto } from 'src/dtos/asset.dto' ;
import { AuthDto } from 'src/dtos/auth.dto' ;
import { DownloadInfoDto , DownloadResponseDto } from 'src/dtos/download.dto' ;
2025-11-11 17:01:14 -05:00
import { ApiTag , Permission } from 'src/enum' ;
2024-05-09 13:58:44 -04:00
import { Auth , Authenticated , FileResponse } from 'src/middleware/auth.guard' ;
2024-03-21 00:07:30 +01:00
import { DownloadService } from 'src/services/download.service' ;
2024-05-31 13:44:04 -04:00
import { asStreamableFile } from 'src/utils/file' ;
2024-01-26 09:19:13 -05:00
2025-11-11 17:01:14 -05:00
@ApiTags ( ApiTag . Download )
2024-01-26 09:19:13 -05:00
@Controller ( 'download' )
export class DownloadController {
2024-05-31 13:44:04 -04:00
constructor ( private service : DownloadService ) { }
2024-01-26 09:19:13 -05:00
@Post ( 'info' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetDownload , sharedLink : true } )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Retrieve download information' ,
description :
'Retrieve information about how to request a download for the specified assets or album. The response includes groups of assets that can be downloaded together.' ,
} )
2024-01-26 09:19:13 -05:00
getDownloadInfo ( @Auth ( ) auth : AuthDto , @Body ( ) dto : DownloadInfoDto ) : Promise < DownloadResponseDto > {
return this . service . getDownloadInfo ( auth , dto ) ;
}
@Post ( 'archive' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetDownload , sharedLink : true } )
2025-08-08 15:56:37 -04:00
@FileResponse ( )
@HttpCode ( HttpStatus . OK )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Download asset archive' ,
description :
'Download a ZIP archive containing the specified assets. The assets must have been previously requested via the "getDownloadInfo" endpoint.' ,
} )
2024-01-26 09:19:13 -05:00
downloadArchive ( @Auth ( ) auth : AuthDto , @Body ( ) dto : AssetIdsDto ) : Promise < StreamableFile > {
return this . service . downloadArchive ( auth , dto ) . then ( asStreamableFile ) ;
}
}