@@ -6,7 +6,7 @@ import Portal from '@burstware/react-native-portal';
6
6
import { useDrive } from '@internxt-mobile/hooks/drive' ;
7
7
import AuthService from '@internxt-mobile/services/AuthService' ;
8
8
import errorService from '@internxt-mobile/services/ErrorService' ;
9
- import { fs } from '@internxt-mobile/services/FileSystemService' ;
9
+ import fileSystemService , { fs } from '@internxt-mobile/services/FileSystemService' ;
10
10
import notificationsService , { notifications } from '@internxt-mobile/services/NotificationsService' ;
11
11
import { logger } from '@internxt-mobile/services/common' ;
12
12
import { time } from '@internxt-mobile/services/common/time' ;
@@ -69,7 +69,7 @@ function DriveItemInfoModal(): JSX.Element {
69
69
} ;
70
70
71
71
const isFileDownloadable = ( ) : boolean => {
72
- if ( parseInt ( item . size ?. toString ( ) ?? '0' ) > MAX_SIZE_TO_DOWNLOAD [ '3GB ' ] ) {
72
+ if ( parseInt ( item . size ?. toString ( ) ?? '0' ) > MAX_SIZE_TO_DOWNLOAD [ '5GB ' ] ) {
73
73
notificationsService . info ( strings . messages . downloadLimit ) ;
74
74
return false ;
75
75
}
@@ -125,21 +125,38 @@ function DriveItemInfoModal(): JSX.Element {
125
125
return ;
126
126
} ;
127
127
128
- const downloadItem = async ( fileId : string , bucketId : string , decryptedFilePath : string ) => {
128
+ const downloadItem = async ( fileId : string , bucketId : string , decryptedFilePath : string , fileSize : number ) => {
129
129
const { credentials } = await AuthService . getAuthCredentials ( ) ;
130
- const { downloadPath } = await drive . file . downloadFile ( credentials . user , bucketId , fileId , {
131
- downloadPath : decryptedFilePath ,
132
- downloadProgressCallback ( progress , bytesReceived , totalBytes ) {
133
- setDownloadProgress ( {
134
- progress,
135
- bytesReceived,
136
- totalBytes,
137
- } ) ;
138
- } ,
139
- onAbortableReady ( abortable ) {
140
- downloadAbortableRef . current = abortable ;
130
+ try {
131
+ const hasEnoughSpace = await fileSystemService . checkAvailableStorage ( fileSize ) ;
132
+ if ( ! hasEnoughSpace ) {
133
+ notifications . error ( strings . errors . notEnoughSpaceOnDevice ) ;
134
+ throw new Error ( strings . errors . notEnoughSpaceOnDevice ) ;
135
+ }
136
+ } catch ( error ) {
137
+ logger . error ( 'Error on downloadItem function:' , JSON . stringify ( error ) ) ;
138
+ errorService . reportError ( error ) ;
139
+ }
140
+
141
+ const { downloadPath } = await drive . file . downloadFile (
142
+ credentials . user ,
143
+ bucketId ,
144
+ fileId ,
145
+ {
146
+ downloadPath : decryptedFilePath ,
147
+ downloadProgressCallback ( progress , bytesReceived , totalBytes ) {
148
+ setDownloadProgress ( {
149
+ progress,
150
+ bytesReceived,
151
+ totalBytes,
152
+ } ) ;
153
+ } ,
154
+ onAbortableReady ( abortable ) {
155
+ downloadAbortableRef . current = abortable ;
156
+ } ,
141
157
} ,
142
- } ) ;
158
+ fileSize ,
159
+ ) ;
143
160
144
161
return downloadPath ;
145
162
} ;
@@ -168,7 +185,12 @@ function DriveItemInfoModal(): JSX.Element {
168
185
169
186
setDownloadProgress ( { totalBytes : 0 , progress : 0 , bytesReceived : 0 } ) ;
170
187
setExporting ( true ) ;
171
- const downloadPath = await downloadItem ( item . fileId , item . bucket as string , decryptedFilePath ) ;
188
+ const downloadPath = await downloadItem (
189
+ item . fileId ,
190
+ item . bucket as string ,
191
+ decryptedFilePath ,
192
+ parseInt ( item . size ?. toString ( ) ?? '0' ) ,
193
+ ) ;
172
194
setExporting ( false ) ;
173
195
await fs . shareFile ( {
174
196
title : item . name ,
@@ -210,7 +232,12 @@ function DriveItemInfoModal(): JSX.Element {
210
232
// 2. If the file doesn't exists, download it
211
233
if ( ! existsDecrypted ) {
212
234
setExporting ( true ) ;
213
- await downloadItem ( item . fileId , item . bucket as string , decryptedFilePath ) ;
235
+ await downloadItem (
236
+ item . fileId ,
237
+ item . bucket as string ,
238
+ decryptedFilePath ,
239
+ parseInt ( item . size ?. toString ( ) ?? '0' ) ,
240
+ ) ;
214
241
setExporting ( false ) ;
215
242
}
216
243
@@ -249,7 +276,12 @@ function DriveItemInfoModal(): JSX.Element {
249
276
// 2. If the file doesn't exists, download it
250
277
if ( ! existsDecrypted ) {
251
278
setExporting ( true ) ;
252
- await downloadItem ( item . fileId , item . bucket as string , decryptedFilePath ) ;
279
+ await downloadItem (
280
+ item . fileId ,
281
+ item . bucket as string ,
282
+ decryptedFilePath ,
283
+ parseInt ( item . size ?. toString ( ) ?? '0' ) ,
284
+ ) ;
253
285
setExporting ( false ) ;
254
286
}
255
287
@@ -327,6 +359,15 @@ function DriveItemInfoModal(): JSX.Element {
327
359
if ( ! downloadProgress . totalBytes ) {
328
360
return strings . generic . calculating + '...' ;
329
361
}
362
+
363
+ if (
364
+ item ?. size &&
365
+ downloadProgress ?. bytesReceived &&
366
+ downloadProgress ?. bytesReceived >= parseInt ( item ?. size ?. toString ( ) )
367
+ ) {
368
+ return strings . generic . decrypting + '...' ;
369
+ }
370
+
330
371
const bytesReceivedStr = prettysize ( downloadProgress . bytesReceived ) ;
331
372
const totalBytesStr = prettysize ( downloadProgress . totalBytes ) ;
332
373
return `${ bytesReceivedStr } ${ strings . modals . downloadingFile . of } ${ totalBytesStr } ` ;
0 commit comments