From 208be32d8a8b1e0588836b46efdecccb5e28ef6b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 1 Sep 2020 13:57:57 +0200 Subject: [PATCH] MOBILE-3508 core: Fix external repositories files download --- src/core/course/providers/helper.ts | 2 +- src/providers/utils/url.ts | 26 ++++++-------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index 1ba933eac..5cc4a8fe2 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -609,7 +609,7 @@ export class CoreCourseHelperProvider { // Not online, get the offline file. It will fail if not found. return this.filepoolProvider.getInternalUrlByUrl(siteId, fileUrl).then((path) => { return this.utils.openFile(path); - }).catch((error) => { + }, (error) => { return Promise.reject(this.translate.instant('core.networkerrormsg')); }); } diff --git a/src/providers/utils/url.ts b/src/providers/utils/url.ts index 1d3877eb9..18297a0d8 100644 --- a/src/providers/utils/url.ts +++ b/src/providers/utils/url.ts @@ -182,33 +182,19 @@ export class CoreUrlUtilsProvider { return url; } - // Check if is a valid URL (contains the pluginfile endpoint) and belongs to the site. - if (!this.isPluginFileUrl(url) || url.indexOf(this.textUtils.addEndingSlash(siteUrl)) !== 0) { - return url; - } - if (canUseTokenPluginFile) { // Use tokenpluginfile.php. url = url.replace(/(\/webservice)?\/pluginfile\.php/, '/tokenpluginfile.php/' + accessKey); - - return url; - } - - // No access key, use pluginfile.php. Check if the URL already has params. - if (url.match(/\?[^=]+=/)) { - url += '&'; } else { - url += '?'; - } - // Always send offline=1 (for external repositories). It shouldn't cause problems for local files or old Moodles. - url += 'token=' + token + '&offline=1'; + // Use pluginfile.php. Some webservices returns directly the correct download url, others not. + if (url.indexOf(this.textUtils.concatenatePaths(siteUrl, 'pluginfile.php')) === 0) { + url = url.replace('/pluginfile', '/webservice/pluginfile'); + } - // Some webservices returns directly the correct download url, others not. - if (url.indexOf(this.textUtils.concatenatePaths(siteUrl, 'pluginfile.php')) === 0) { - url = url.replace('/pluginfile', '/webservice/pluginfile'); + url = this.addParamsToUrl(url, {token: token}); } - return url; + return this.addParamsToUrl(url, {offline: 1}); // Always send offline=1 (it's for external repositories). } /**