@@ -4,20 +4,19 @@ import { WebDavUtils } from '../../utils/webdav.utils';
44import { DriveFileService } from '../../services/drive/drive-file.service' ;
55import { DriveDatabaseManager } from '../../services/database/drive-database-manager.service' ;
66import { NetworkFacade } from '../../services/network/network-facade.service' ;
7- import { UploadService } from '../../services/network/upload.service' ;
87import { DownloadService } from '../../services/network/download.service' ;
98import { CryptoService } from '../../services/crypto.service' ;
109import { AuthService } from '../../services/auth.service' ;
11- import { NotFoundError , NotImplementedError } from '../../utils/errors.utils' ;
10+ import { NotFoundError } from '../../utils/errors.utils' ;
1211import { webdavLogger } from '../../utils/logger.utils' ;
1312import { DriveFileItem } from '../../types/drive.types' ;
13+ import { NetworkUtils } from '../../utils/network.utils' ;
1414
1515export class GETRequestHandler implements WebDavMethodHandler {
1616 constructor (
1717 private readonly dependencies : {
1818 driveFileService : DriveFileService ;
1919 driveDatabaseManager : DriveDatabaseManager ;
20- uploadService : UploadService ;
2120 downloadService : DownloadService ;
2221 cryptoService : CryptoService ;
2322 authService : AuthService ;
@@ -29,24 +28,20 @@ export class GETRequestHandler implements WebDavMethodHandler {
2928 const { driveDatabaseManager, driveFileService, authService, networkFacade } = this . dependencies ;
3029 const resource = await WebDavUtils . getRequestedResource ( req ) ;
3130
32- if ( req . headers [ 'content-range' ] || req . headers [ 'range' ] )
33- throw new NotImplementedError ( 'Range requests not supported' ) ;
3431 if ( resource . name . startsWith ( '._' ) ) throw new NotFoundError ( 'File not found' ) ;
32+ if ( resource . type === 'folder' ) throw new NotFoundError ( 'Folders cannot be listed with GET. Use PROPFIND instead.' ) ;
3533
36- webdavLogger . info ( `GET request received for file at ${ resource . url } ` ) ;
34+ webdavLogger . info ( `[ GET] Request received for ${ resource . type } at ${ resource . url } ` ) ;
3735 const driveFile = ( await WebDavUtils . getAndSearchItemFromResource ( {
3836 resource,
3937 driveDatabaseManager,
4038 driveFileService,
4139 } ) ) as DriveFileItem ;
4240
43- webdavLogger . info ( `✅ Found Drive File with uuid ${ driveFile . uuid } ` ) ;
44-
45- res . set ( 'Content-Type' , 'application/octet-stream' ) ;
46- res . set ( 'Content-length' , driveFile . size . toString ( ) ) ;
41+ webdavLogger . info ( `[GET] [${ driveFile . uuid } ] Found Drive File` ) ;
4742
4843 const { user } = await authService . getAuthDetails ( ) ;
49- webdavLogger . info ( '✅ Network ready for download' ) ;
44+ webdavLogger . info ( `[GET] [ ${ driveFile . uuid } ] Network ready for download` ) ;
5045
5146 const writable = new WritableStream ( {
5247 write ( chunk ) {
@@ -57,28 +52,32 @@ export class GETRequestHandler implements WebDavMethodHandler {
5752 } ,
5853 } ) ;
5954
60- let lastLoggedProgress = 0 ;
55+ const range = req . headers [ 'range' ] ;
56+ const rangeOptions = NetworkUtils . parseRangeHeader ( {
57+ range,
58+ totalFileSize : driveFile . size ,
59+ } ) ;
60+ let contentLength = driveFile . size ;
61+ if ( rangeOptions ) {
62+ webdavLogger . info ( `[GET] [${ driveFile . uuid } ] Range request received:` , { rangeOptions } ) ;
63+ contentLength = rangeOptions . rangeSize ;
64+ }
65+
66+ res . header ( 'Content-Type' , 'application/octet-stream' ) ;
67+ res . header ( 'Content-length' , contentLength . toString ( ) ) ;
68+
6169 const [ executeDownload ] = await networkFacade . downloadToStream (
6270 driveFile . bucket ,
6371 user . mnemonic ,
6472 driveFile . fileId ,
6573 writable ,
66- {
67- progressCallback : ( progress ) => {
68- const percentage = Math . floor ( 100 * progress ) ;
69-
70- if ( percentage >= lastLoggedProgress + 1 ) {
71- lastLoggedProgress = percentage ;
72- webdavLogger . info ( `Download progress for file ${ resource . name } : ${ percentage } %` ) ;
73- }
74- } ,
75- } ,
74+ rangeOptions ,
7675 ) ;
77- webdavLogger . info ( '✅ Download prepared, executing...' ) ;
76+ webdavLogger . info ( `[GET] [ ${ driveFile . uuid } ] Download prepared, executing...` ) ;
7877 res . status ( 200 ) ;
7978
8079 await executeDownload ;
8180
82- webdavLogger . info ( ' ✅ Download ready, replying to client' ) ;
81+ webdavLogger . info ( `[GET] [ ${ driveFile . uuid } ] ✅ Download ready, replying to client` ) ;
8382 } ;
8483}
0 commit comments