Merge pull request #1320 from dpalou/MOBILE-2376
MOBILE-2376 core: Fix issues with pluginfile.phpmain
commit
931c27551b
|
@ -931,7 +931,7 @@ export class CoreSite {
|
|||
* @return {string} Fixed URL.
|
||||
*/
|
||||
fixPluginfileURL(url: string): string {
|
||||
return this.urlUtils.fixPluginfileURL(url, this.token);
|
||||
return this.urlUtils.fixPluginfileURL(url, this.token, this.siteUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -607,7 +607,14 @@ export class CoreCourseHelperProvider {
|
|||
|
||||
if (status === CoreConstants.DOWNLOADED) {
|
||||
// Get the local file URL.
|
||||
return this.filepoolProvider.getInternalUrlByUrl(siteId, fileUrl);
|
||||
return this.filepoolProvider.getInternalUrlByUrl(siteId, fileUrl).catch((error) => {
|
||||
// File not found, mark the module as not downloaded and reject.
|
||||
return this.filepoolProvider.storePackageStatus(siteId, CoreConstants.NOT_DOWNLOADED, component,
|
||||
componentId).then(() => {
|
||||
|
||||
return Promise.reject(error);
|
||||
});
|
||||
});
|
||||
} else if (status === CoreConstants.DOWNLOADING && !this.appProvider.isDesktop()) {
|
||||
// Return the online URL.
|
||||
return fixedUrl;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreLangProvider } from '../lang';
|
||||
import { CoreTextUtilsProvider } from './text';
|
||||
|
||||
/*
|
||||
* "Utils" service with helper functions for URLs.
|
||||
|
@ -21,7 +22,7 @@ import { CoreLangProvider } from '../lang';
|
|||
@Injectable()
|
||||
export class CoreUrlUtilsProvider {
|
||||
|
||||
constructor(private langProvider: CoreLangProvider) { }
|
||||
constructor(private langProvider: CoreLangProvider, private textUtils: CoreTextUtilsProvider) { }
|
||||
|
||||
/**
|
||||
* Add or remove 'www' from a URL. The url needs to have http or https protocol.
|
||||
|
@ -69,13 +70,16 @@ export class CoreUrlUtilsProvider {
|
|||
*
|
||||
* @param {string} url The url to be fixed.
|
||||
* @param {string} token Token to use.
|
||||
* @param {string} siteUrl The URL of the site the URL belongs to.
|
||||
* @return {string} Fixed URL.
|
||||
*/
|
||||
fixPluginfileURL(url: string, token: string): string {
|
||||
fixPluginfileURL(url: string, token: string, siteUrl: string): string {
|
||||
if (!url || !token) {
|
||||
return '';
|
||||
}
|
||||
|
||||
url = url.replace(/&/g, '&');
|
||||
|
||||
// First check if we need to fix this url or is already fixed.
|
||||
if (url.indexOf('token=') != -1) {
|
||||
return url;
|
||||
|
@ -86,8 +90,8 @@ export class CoreUrlUtilsProvider {
|
|||
return url;
|
||||
}
|
||||
|
||||
// In which way the server is serving the files? Are we using slash parameters?
|
||||
if (url.indexOf('?file=') != -1 || url.indexOf('?forcedownload=') != -1 || url.indexOf('?rev=') != -1) {
|
||||
// Check if the URL already has params.
|
||||
if (url.match(/\?[^=]+=/)) {
|
||||
url += '&';
|
||||
} else {
|
||||
url += '?';
|
||||
|
@ -96,7 +100,7 @@ export class CoreUrlUtilsProvider {
|
|||
url += 'token=' + token + '&offline=1';
|
||||
|
||||
// Some webservices returns directly the correct download url, others not.
|
||||
if (url.indexOf('/webservice/pluginfile') == -1) {
|
||||
if (url.indexOf(this.textUtils.concatenatePaths(siteUrl, 'pluginfile.php')) === 0) {
|
||||
url = url.replace('/pluginfile', '/webservice/pluginfile');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue