@@ -16,7 +16,6 @@ import { UploadService } from './upload.service';
1616import { DownloadService } from './download.service' ;
1717import { ValidationService } from '../validation.service' ;
1818import { HashStream } from '../../utils/hash.utils' ;
19- import { ProgressTransform } from '../../utils/stream.utils' ;
2019import { RangeOptions } from '../../utils/network.utils' ;
2120
2221export class NetworkFacade {
@@ -54,6 +53,7 @@ export class NetworkFacade {
5453 bucketId : string ,
5554 mnemonic : string ,
5655 fileId : string ,
56+ size : number ,
5757 to : WritableStream ,
5858 rangeOptions ?: RangeOptions ,
5959 options ?: DownloadOptions ,
@@ -67,10 +67,6 @@ export class NetworkFacade {
6767 options . progressCallback ( progress ) ;
6868 } ;
6969
70- const onDownloadProgress = ( progress : number ) => {
71- onProgress ( progress ) ;
72- } ;
73-
7470 const decryptFile : DecryptFileFunction = async ( _ , key , iv ) => {
7571 let startOffsetByte ;
7672 if ( rangeOptions ) {
@@ -96,8 +92,8 @@ export class NetworkFacade {
9692 throw new Error ( 'Download aborted' ) ;
9793 }
9894
99- const encryptedContentStream = await this . downloadService . downloadFile ( downloadable . url , {
100- progressCallback : onDownloadProgress ,
95+ const encryptedContentStream = await this . downloadService . downloadFile ( downloadable . url , size , {
96+ progressCallback : onProgress ,
10197 abortController : options ?. abortController ,
10298 rangeHeader : rangeOptions ?. range ,
10399 } ) ;
@@ -142,11 +138,7 @@ export class NetworkFacade {
142138 const hashStream = new HashStream ( ) ;
143139 const abortable = options ?. abortController ?? new AbortController ( ) ;
144140 let encryptionTransform : Transform ;
145- const progressTransform = new ProgressTransform ( { totalBytes : size } , ( progress ) => {
146- if ( options ?. progressCallback ) {
147- options . progressCallback ( progress * 0.95 ) ;
148- }
149- } ) ;
141+ let hash : Buffer ;
150142
151143 const onProgress : UploadProgressCallback = ( progress : number ) => {
152144 if ( ! options ?. progressCallback ) return ;
@@ -165,15 +157,14 @@ export class NetworkFacade {
165157 } ;
166158
167159 const uploadFile : UploadFileFunction = async ( url ) => {
168- await this . uploadService . uploadFile ( url , encryptionTransform . pipe ( progressTransform ) , {
160+ await this . uploadService . uploadFile ( url , size , encryptionTransform , {
169161 abortController : abortable ,
170- progressCallback : ( ) => {
171- // No progress here, we are using the progressTransform
172- } ,
162+ progressCallback : onProgress ,
173163 } ) ;
174-
175- return hashStream . getHash ( ) . toString ( 'hex' ) ;
164+ hash = hashStream . getHash ( ) ;
165+ return hash . toString ( 'hex' ) ;
176166 } ;
167+
177168 const uploadOperation = async ( ) => {
178169 const uploadResult = await NetworkUpload . uploadFile (
179170 this . network ,
@@ -184,12 +175,10 @@ export class NetworkFacade {
184175 encryptFile ,
185176 uploadFile ,
186177 ) ;
187- const fileHash : Buffer = Buffer . from ( '' ) ;
188178
189- onProgress ( 1 ) ;
190179 return {
191180 fileId : uploadResult ,
192- hash : fileHash ,
181+ hash : hash ,
193182 } ;
194183 } ;
195184
0 commit comments