MOBILE-3508 core: Fix external repositories files download
parent
b67ea14abb
commit
208be32d8a
|
@ -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'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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).
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue