From 7924dadcfba58d3e17e1bde2217d7964498b1434 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 7 Aug 2018 12:07:00 +0200 Subject: [PATCH] MOBILE-2523 media: Fix NOT_FOUND_ERR when opening big media files --- src/providers/file-helper.ts | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/providers/file-helper.ts b/src/providers/file-helper.ts index 94315a513..4bd5d3f37 100644 --- a/src/providers/file-helper.ts +++ b/src/providers/file-helper.ts @@ -62,29 +62,33 @@ export class CoreFileHelperProvider { return Promise.reject(error); } - // Get the state. - if (state) { - return state; - } else { - return this.filepoolProvider.getFileStateByUrl(siteId, fileUrl, timemodified); - } - }).then((state) => { - if (state == CoreConstants.DOWNLOADING) { - return Promise.reject(this.translate.instant('core.erroropenfiledownloading')); - } - let promise; - if (state === CoreConstants.NOT_DOWNLOADED) { - // File is not downloaded, download and then return the local URL. - promise = this.downloadFile(fileUrl, component, componentId, timemodified, onProgress, file, siteId); + // Get the state. + if (state) { + promise = Promise.resolve(state); } else { - // File is outdated and can't be opened in online, return the local URL. - promise = this.filepoolProvider.getInternalUrlByUrl(siteId, fileUrl); + promise = this.filepoolProvider.getFileStateByUrl(siteId, fileUrl, timemodified); } - return promise.then((url) => { - return this.utils.openFile(url); + return promise.then((state) => { + if (state == CoreConstants.DOWNLOADING) { + return Promise.reject(this.translate.instant('core.erroropenfiledownloading')); + } + + let promise; + + if (state === CoreConstants.NOT_DOWNLOADED) { + // File is not downloaded, download and then return the local URL. + promise = this.downloadFile(fileUrl, component, componentId, timemodified, onProgress, file, siteId); + } else { + // File is outdated and can't be opened in online, return the local URL. + promise = this.filepoolProvider.getInternalUrlByUrl(siteId, fileUrl); + } + + return promise.then((url) => { + return this.utils.openFile(url); + }); }); }); } else {