@@ -28,7 +28,7 @@ import AppText from 'src/components/AppText';
2828import { SLEEP_BECAUSE_MAYBE_BACKEND_IS_NOT_RETURNING_FRESHLY_MODIFIED_OR_CREATED_ITEMS_YET } from 'src/helpers/services' ;
2929import { useTailwind } from 'tailwind-rn' ;
3030import strings from '../../../../assets/lang/strings' ;
31- import { FolderIcon , getFileTypeIcon } from '../../../helpers' ;
31+ import { checkIsFolder , FolderIcon , getFileSize , getFileTypeIcon , isEmptyFile } from '../../../helpers' ;
3232import useGetColor from '../../../hooks/useColor' ;
3333import { MAX_SIZE_TO_DOWNLOAD } from '../../../services/drive/constants' ;
3434import { useAppDispatch , useAppSelector } from '../../../store/hooks' ;
@@ -56,7 +56,7 @@ function DriveItemInfoModal(): JSX.Element {
5656 return < > </ > ;
5757 }
5858
59- const isFolder = ! item . fileId ;
59+ const isFolder = checkIsFolder ( item ) ;
6060
6161 const handleRenameItem = ( ) => {
6262 dispatch ( uiActions . setShowItemModal ( false ) ) ;
@@ -165,7 +165,8 @@ function DriveItemInfoModal(): JSX.Element {
165165
166166 const handleExportFile = async ( ) => {
167167 try {
168- if ( ! item . fileId ) {
168+ const fileSize = getFileSize ( item ) ;
169+ if ( ! item . fileId && fileSize !== 0 ) {
169170 throw new Error ( 'Item fileID not found' ) ;
170171 }
171172 const canDownloadFile = isFileDownloadable ( ) ;
@@ -187,12 +188,19 @@ function DriveItemInfoModal(): JSX.Element {
187188
188189 setDownloadProgress ( { totalBytes : 0 , progress : 0 , bytesReceived : 0 } ) ;
189190 setExporting ( true ) ;
190- const downloadPath = await downloadItem (
191- item . fileId ,
192- item . bucket as string ,
193- decryptedFilePath ,
194- parseInt ( item . size ?. toString ( ) ?? '0' ) ,
195- ) ;
191+
192+ let downloadPath : string ;
193+
194+ if ( isEmptyFile ( item ) ) {
195+ await drive . file . createEmptyDownloadedFile ( decryptedFilePath ) ;
196+ downloadPath = decryptedFilePath ;
197+ } else {
198+ if ( ! item . fileId ) {
199+ throw new Error ( 'Item fileID not found for non-empty file' ) ;
200+ }
201+ downloadPath = await downloadItem ( item . fileId , item . bucket as string , decryptedFilePath , fileSize ) ;
202+ }
203+
196204 setExporting ( false ) ;
197205 await fs . shareFile ( {
198206 title : item . name ,
@@ -204,18 +212,24 @@ function DriveItemInfoModal(): JSX.Element {
204212 errorService . reportError ( error ) ;
205213 } finally {
206214 setExporting ( false ) ;
215+ dispatch ( uiActions . setShowItemModal ( false ) ) ;
207216 }
208217 } ;
218+
209219 const handleAbortDownload = ( ) => {
210220 setExporting ( false ) ;
221+ dispatch ( uiActions . setShowItemModal ( false ) ) ;
222+
211223 if ( ! downloadAbortableRef . current ) return ;
212224
213225 downloadAbortableRef . current ( 'User requested abort' ) ;
214226 } ;
227+
215228 const handleAndroidDownloadFile = async ( ) => {
216229 try {
217230 setDownloadProgress ( { totalBytes : 0 , progress : 0 , bytesReceived : 0 } ) ;
218- if ( ! item . fileId ) {
231+ const fileSize = getFileSize ( item ) ;
232+ if ( ! item . fileId && fileSize !== 0 ) {
219233 throw new Error ( 'Item fileID not found' ) ;
220234 }
221235 const canDownloadFile = isFileDownloadable ( ) ;
@@ -234,12 +248,14 @@ function DriveItemInfoModal(): JSX.Element {
234248 // 2. If the file doesn't exists, download it
235249 if ( ! existsDecrypted ) {
236250 setExporting ( true ) ;
237- await downloadItem (
238- item . fileId ,
239- item . bucket as string ,
240- decryptedFilePath ,
241- parseInt ( item . size ?. toString ( ) ?? '0' ) ,
242- ) ;
251+ if ( isEmptyFile ( item ) ) {
252+ await drive . file . createEmptyDownloadedFile ( decryptedFilePath ) ;
253+ } else {
254+ if ( ! item . fileId ) {
255+ throw new Error ( 'Item fileID not found for non-empty file' ) ;
256+ }
257+ await downloadItem ( item . fileId , item . bucket as string , decryptedFilePath , fileSize ) ;
258+ }
243259 setExporting ( false ) ;
244260 }
245261
@@ -259,7 +275,8 @@ function DriveItemInfoModal(): JSX.Element {
259275 const handleiOSSaveToFiles = async ( ) => {
260276 try {
261277 setDownloadProgress ( { totalBytes : 0 , progress : 0 , bytesReceived : 0 } ) ;
262- if ( ! item . fileId ) {
278+ const fileSize = getFileSize ( item ) ;
279+ if ( ! item . fileId && fileSize !== 0 ) {
263280 throw new Error ( 'Item fileID not found' ) ;
264281 }
265282 const canDownloadFile = isFileDownloadable ( ) ;
@@ -277,14 +294,16 @@ function DriveItemInfoModal(): JSX.Element {
277294
278295 // 2. If the file doesn't exists, download it
279296 if ( ! existsDecrypted ) {
280- setExporting ( true ) ;
281- await downloadItem (
282- item . fileId ,
283- item . bucket as string ,
284- decryptedFilePath ,
285- parseInt ( item . size ?. toString ( ) ?? '0' ) ,
286- ) ;
287- setExporting ( false ) ;
297+ if ( isEmptyFile ( item ) ) {
298+ await drive . file . createEmptyDownloadedFile ( decryptedFilePath ) ;
299+ } else {
300+ setExporting ( true ) ;
301+ if ( ! item . fileId ) {
302+ throw new Error ( 'Item fileID not found for non-empty file' ) ;
303+ }
304+ await downloadItem ( item . fileId , item . bucket as string , decryptedFilePath , fileSize ) ;
305+ setExporting ( false ) ;
306+ }
288307 }
289308
290309 // 3. Share to iOS files app
@@ -364,7 +383,7 @@ function DriveItemInfoModal(): JSX.Element {
364383 }
365384
366385 if (
367- item ?. size &&
386+ ( item ?. size || item ?. size === 0 ) &&
368387 downloadProgress ?. bytesReceived &&
369388 downloadProgress ?. bytesReceived >= parseInt ( item ?. size ?. toString ( ) )
370389 ) {
0 commit comments