MOBILE-2376 core: Fix issues with pluginfile.php

- Improve how to detect if the URL has params.
- Replace & with &
- Only add webservice to the URL if it's the core pluginfile
main
Dani Palou 2018-05-22 16:32:56 +02:00
parent e668f0bf60
commit dccfb64e1f
3 changed files with 18 additions and 7 deletions

View File

@ -931,7 +931,7 @@ export class CoreSite {
* @return {string} Fixed URL. * @return {string} Fixed URL.
*/ */
fixPluginfileURL(url: string): string { fixPluginfileURL(url: string): string {
return this.urlUtils.fixPluginfileURL(url, this.token); return this.urlUtils.fixPluginfileURL(url, this.token, this.siteUrl);
} }
/** /**

View File

@ -607,7 +607,14 @@ export class CoreCourseHelperProvider {
if (status === CoreConstants.DOWNLOADED) { if (status === CoreConstants.DOWNLOADED) {
// Get the local file URL. // 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()) { } else if (status === CoreConstants.DOWNLOADING && !this.appProvider.isDesktop()) {
// Return the online URL. // Return the online URL.
return fixedUrl; return fixedUrl;

View File

@ -14,6 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreLangProvider } from '../lang'; import { CoreLangProvider } from '../lang';
import { CoreTextUtilsProvider } from './text';
/* /*
* "Utils" service with helper functions for URLs. * "Utils" service with helper functions for URLs.
@ -21,7 +22,7 @@ import { CoreLangProvider } from '../lang';
@Injectable() @Injectable()
export class CoreUrlUtilsProvider { 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. * 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} url The url to be fixed.
* @param {string} token Token to use. * @param {string} token Token to use.
* @param {string} siteUrl The URL of the site the URL belongs to.
* @return {string} Fixed URL. * @return {string} Fixed URL.
*/ */
fixPluginfileURL(url: string, token: string): string { fixPluginfileURL(url: string, token: string, siteUrl: string): string {
if (!url || !token) { if (!url || !token) {
return ''; return '';
} }
url = url.replace(/&/g, '&');
// First check if we need to fix this url or is already fixed. // First check if we need to fix this url or is already fixed.
if (url.indexOf('token=') != -1) { if (url.indexOf('token=') != -1) {
return url; return url;
@ -86,8 +90,8 @@ export class CoreUrlUtilsProvider {
return url; return url;
} }
// In which way the server is serving the files? Are we using slash parameters? // Check if the URL already has params.
if (url.indexOf('?file=') != -1 || url.indexOf('?forcedownload=') != -1 || url.indexOf('?rev=') != -1) { if (url.match(/\?[^=]+=/)) {
url += '&'; url += '&';
} else { } else {
url += '?'; url += '?';
@ -96,7 +100,7 @@ export class CoreUrlUtilsProvider {
url += 'token=' + token + '&offline=1'; url += 'token=' + token + '&offline=1';
// Some webservices returns directly the correct download url, others not. // 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'); url = url.replace('/pluginfile', '/webservice/pluginfile');
} }