diff --git a/src/addons/remotethemes/services/remotethemes-handler.ts b/src/addons/remotethemes/services/remotethemes-handler.ts index 5cde27432..d04eb9cd3 100644 --- a/src/addons/remotethemes/services/remotethemes-handler.ts +++ b/src/addons/remotethemes/services/remotethemes-handler.ts @@ -90,7 +90,7 @@ export class AddonRemoteThemesHandlerService implements CoreStyleHandler { if (style != '') { // Treat the CSS. CoreUtils.ignoreErrors( - CoreFilepool.treatCSSCode(siteId, fileUrl, style, COMPONENT, 2), + CoreFilepool.treatCSSCode(siteId, fileUrl, style, COMPONENT, 1), ); } diff --git a/src/core/directives/external-content.ts b/src/core/directives/external-content.ts index 17635acd3..9d3afa58d 100644 --- a/src/core/directives/external-content.ts +++ b/src/core/directives/external-content.ts @@ -271,7 +271,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O urls = CoreUtils.uniqueArray(urls); // Remove duplicates. const promises = urls.map(async (url) => { - const finalUrl = await CoreFilepool.getUrlByUrl(siteId, url, this.component, this.componentId, 0, true, true); + const finalUrl = await CoreFilepool.getSrcByUrl(siteId, url, this.component, this.componentId, 0, true, true); this.logger.debug('Using URL ' + finalUrl + ' for ' + url + ' in inline styles'); inlineStyles = inlineStyles.replace(new RegExp(url, 'gi'), finalUrl); diff --git a/src/core/features/siteplugins/services/siteplugins-helper.ts b/src/core/features/siteplugins/services/siteplugins-helper.ts index 1c715bb6d..5de98ba3a 100644 --- a/src/core/features/siteplugins/services/siteplugins-helper.ts +++ b/src/core/features/siteplugins/services/siteplugins-helper.ts @@ -195,6 +195,11 @@ export class CoreSitePluginsHelperProvider { return ''; } + // Update the schema with the final CSS URL. + if (handlerSchema.styles) { + handlerSchema.styles.url = url; + } + // Download the file if not downloaded or the version changed. const path = await CoreFilepool.downloadUrl( site.getId(), diff --git a/src/core/services/filepool.ts b/src/core/services/filepool.ts index b3db06a44..55675f65f 100644 --- a/src/core/services/filepool.ts +++ b/src/core/services/filepool.ts @@ -2948,7 +2948,7 @@ export class CoreFilepoolProvider { * and store the result in the CSS file. * * @param siteId Site ID. - * @param fileUrl CSS file URL. + * @param fileUrl CSS file URL. If a local path is supplied the app will assume it's the path where to write the file. * @param cssCode CSS code. * @param component The component to link the file to. * @param componentId An ID to use in conjunction with the component. @@ -2966,29 +2966,33 @@ export class CoreFilepoolProvider { const urls = CoreDomUtils.extractUrlsFromCSS(cssCode); let updated = false; - // Get the path of the CSS file. - const filePath = await this.getFilePathByUrl(siteId, fileUrl); + // Get the path of the CSS file. If it's a local file, assume it's the path where to write the file. + const filePath = CoreUrlUtils.isLocalFileUrl(fileUrl) ? + fileUrl : + await this.getFilePathByUrl(siteId, fileUrl); // Download all files in the CSS. await Promise.all(urls.map(async (url) => { - // Download the file only if it's an online URL. - if (CoreUrlUtils.isLocalFileUrl(url)) { - return; - } - try { - const fileUrl = await this.downloadUrl( - siteId, - url, - false, - component, - componentId, - 0, - undefined, - undefined, - undefined, - revision, - ); + let fileUrl = url; + if (!CoreUrlUtils.isLocalFileUrl(url)) { + // Not a local file, download it. + fileUrl = await this.downloadUrl( + siteId, + url, + false, + component, + componentId, + 0, + undefined, + undefined, + undefined, + revision, + ); + } + + // Convert the URL so it works in mobile devices. + fileUrl = CoreFile.convertFileSrc(fileUrl); if (fileUrl != url) { cssCode = cssCode.replace(new RegExp(CoreTextUtils.escapeForRegex(url), 'g'), fileUrl);