From bfc5367a7c3224eb6936b9fd5cb3df26d80e646c Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 4 Jun 2024 13:12:21 +0200 Subject: [PATCH] MOBILE-4604 mod_url: Fix embedded URL if it uses pluginfile --- .../components/index/addon-mod-url-index.html | 6 ++--- src/addons/mod/url/components/index/index.ts | 25 +++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/addons/mod/url/components/index/addon-mod-url-index.html b/src/addons/mod/url/components/index/addon-mod-url-index.html index 70252ad61..a52ce9833 100644 --- a/src/addons/mod/url/components/index/addon-mod-url-index.html +++ b/src/addons/mod/url/components/index/addon-mod-url-index.html @@ -19,12 +19,12 @@ - + diff --git a/src/addons/mod/url/components/index/index.ts b/src/addons/mod/url/components/index/index.ts index edfb1194c..b6f70314c 100644 --- a/src/addons/mod/url/components/index/index.ts +++ b/src/addons/mod/url/components/index/index.ts @@ -23,6 +23,7 @@ import { CoreTextUtils } from '@services/utils/text'; import { AddonModUrl, AddonModUrlDisplayOptions, AddonModUrlUrl } from '../../services/url'; import { AddonModUrlHelper } from '../../services/url-helper'; import { ADDON_MOD_URL_COMPONENT } from '../../constants'; +import { CoreSites } from '@services/sites'; /** * Component that displays a url. @@ -38,6 +39,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo pluginName = 'url'; url?: string; + embeddedUrl?: string; name?: string; shouldEmbed = false; shouldIframe = false; @@ -137,15 +139,22 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo this.shouldEmbed = displayType == CoreConstants.RESOURCELIB_DISPLAY_EMBED; this.shouldIframe = displayType == CoreConstants.RESOURCELIB_DISPLAY_FRAME; - if (this.shouldEmbed) { - const extension = CoreMimetypeUtils.guessExtensionFromUrl(url.externalurl); - - this.mimetype = CoreMimetypeUtils.getMimeType(extension); - this.isImage = CoreMimetypeUtils.isExtensionInGroup(extension, ['web_image']); - this.isAudio = CoreMimetypeUtils.isExtensionInGroup(extension, ['web_audio']); - this.isVideo = CoreMimetypeUtils.isExtensionInGroup(extension, ['web_video']); - this.isOther = !this.isImage && !this.isAudio && !this.isVideo; + if (!this.shouldEmbed) { + return; } + + const extension = CoreMimetypeUtils.guessExtensionFromUrl(url.externalurl); + + this.mimetype = CoreMimetypeUtils.getMimeType(extension); + this.isImage = CoreMimetypeUtils.isExtensionInGroup(extension, ['web_image']); + this.isAudio = CoreMimetypeUtils.isExtensionInGroup(extension, ['web_audio']); + this.isVideo = CoreMimetypeUtils.isExtensionInGroup(extension, ['web_video']); + this.isOther = !this.isImage && !this.isAudio && !this.isVideo; + + // Fix the URL if it uses pluginfile endpoint. + const currentSite = CoreSites.getCurrentSite(); + this.embeddedUrl = currentSite && this.url ? + await currentSite.checkAndFixPluginfileURL(this.url) : ''; } /**