MOBILE-3508 core: Fix external repositories files download

main
Dani Palou 2020-09-01 13:57:57 +02:00
parent b67ea14abb
commit 208be32d8a
2 changed files with 7 additions and 21 deletions

View File

@ -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'));
});
}

View File

@ -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).
}
/**