@@ -89,10 +89,8 @@ export class Downloader extends DownloaderCommon {
89
89
if ( ! this . handle . seekToEndReturningOffsetError ( written ) ) {
90
90
emit ( DownloaderCommon . DOWNLOAD_ERROR , { error : 'Error seeking end of file' } ) ;
91
91
return reject ( ) ;
92
- // throw new Error('Error seeking end of file');
93
92
}
94
93
if ( ! this . handle . writeDataError ( data ) ) {
95
- // throw new Error('Error writing data');
96
94
emit ( DownloaderCommon . DOWNLOAD_ERROR , { error : 'Error writing data' } ) ;
97
95
return reject ( ) ;
98
96
}
@@ -219,14 +217,13 @@ export class Downloader extends DownloaderCommon {
219
217
PHAssetChangeRequest . creationRequestForAssetFromVideoAtFileURL ( iosurl ) ;
220
218
} else if ( isImage ) {
221
219
PHAssetChangeRequest . creationRequestForAssetFromImageAtFileURL ( iosurl ) ;
222
- }
223
- // else console.log('neither a video or image, not saving to gallery');
220
+ } else console . warn ( 'not a recognized video or image file extension, not saving to gallery' ) ;
224
221
} ,
225
222
( success , err ) => {
226
223
if ( success ) {
227
224
// console.log('success');
228
225
} else {
229
- // console.log('failed' );
226
+ console . warn ( 'Unable to copy into Photos gallery' , err ) ;
230
227
}
231
228
resolve ( downloadedFile ) ;
232
229
}
@@ -298,7 +295,7 @@ class UIDocumentPickerDelegateImpl extends NSObject implements UIDocumentPickerD
298
295
return this . _owner . get ( ) ;
299
296
}
300
297
301
- //this shouldn't be called, but we'll have the same handler code just in case
298
+ //for a directory picker, this should never be called, but we'll include the code anyway
302
299
documentPickerDidPickDocumentAtURL ( controller : UIDocumentPickerViewController , url : NSURL ) : void {
303
300
const access = url . startAccessingSecurityScopedResource ( ) ;
304
301
let copypath = url . path + '/' + this . _downloadFilename ;
@@ -314,20 +311,16 @@ class UIDocumentPickerDelegateImpl extends NSObject implements UIDocumentPickerD
314
311
if ( ! NSFileManager . defaultManager . fileExistsAtPath ( copypath ) ) break ;
315
312
}
316
313
}
317
- const suc = NSFileManager . defaultManager . copyItemAtPathToPathError ( this . _downloadPath , copypath ) ;
314
+ NSFileManager . defaultManager . copyItemAtPathToPathError ( this . _downloadPath , copypath ) ;
318
315
if ( access ) url . stopAccessingSecurityScopedResource ( ) ;
319
316
const downloadedFile = File . fromPath ( this . _downloadPath ) ;
320
317
this . _resolve ( downloadedFile ) ;
321
318
controller . dismissViewControllerAnimatedCompletion ( true , null ) ;
322
319
this . deRegisterFromGlobal ( ) ;
323
320
}
324
321
325
- //if multiple selections allowed:
326
322
documentPickerDidPickDocumentsAtURLs ( controller : UIDocumentPickerViewController , urls : NSArray < NSURL > ) : void {
327
- const files : File [ ] = [ ] ;
328
- //This view can't display an UIActivityIndicatorView inside it using the usual ios spinner approach,
329
- // but picker shows a small spinner on the "Open" button while processing
330
- //Process picker results
323
+ //we should only get one folder, but will loop through just in case and just return the first one as destination
331
324
for ( let i = 0 ; i < urls . count ; i ++ ) {
332
325
const url = urls . objectAtIndex ( i ) ; //urls[0];
333
326
const access = url . startAccessingSecurityScopedResource ( ) ;
@@ -337,15 +330,14 @@ class UIDocumentPickerDelegateImpl extends NSObject implements UIDocumentPickerD
337
330
const fileName = fileParts [ fileParts . length - 1 ] ;
338
331
const filePrefix = fileName . split ( '.' , 2 ) . length > 0 ? fileName . split ( '.' , 2 ) [ 0 ] : null ;
339
332
const fileSuffix = fileName . split ( '.' , 2 ) . length > 0 ? '.' + fileName . split ( '.' , 2 ) [ 1 ] : null ;
340
- // let tempFileName = 'dl-' + generateId() + fileSuffix;
341
333
let tempFileName ;
342
334
for ( let i = 1 ; i < 999999999 ; i ++ ) {
343
335
tempFileName = filePrefix + '-' + i + fileSuffix ;
344
336
copypath = copypath . replace ( / \/ [ ^ / ] + $ / , `/${ tempFileName } ` ) ;
345
337
if ( ! NSFileManager . defaultManager . fileExistsAtPath ( copypath ) ) break ;
346
338
}
347
339
}
348
- const suc = NSFileManager . defaultManager . copyItemAtPathToPathError ( this . _downloadPath , copypath ) ;
340
+ NSFileManager . defaultManager . copyItemAtPathToPathError ( this . _downloadPath , copypath ) ;
349
341
if ( access ) url . stopAccessingSecurityScopedResource ( ) ;
350
342
const downloadedFile = File . fromPath ( this . _downloadPath ) ;
351
343
this . _resolve ( downloadedFile ) ;
@@ -357,5 +349,8 @@ class UIDocumentPickerDelegateImpl extends NSObject implements UIDocumentPickerD
357
349
documentPickerWasCancelled ( controller : UIDocumentPickerViewController ) : void {
358
350
controller . dismissViewControllerAnimatedCompletion ( true , null ) ;
359
351
this . deRegisterFromGlobal ( ) ;
352
+ //user canceled the extra copy, just resolve the downloaded file
353
+ const downloadedFile = File . fromPath ( this . _downloadPath ) ;
354
+ this . _resolve ( downloadedFile ) ;
360
355
}
361
356
}
0 commit comments