From 4b55774497e0553dd749189174f228db89b20ff4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 1 Mar 2022 15:04:54 +0100 Subject: [PATCH] MOBILE-4005 vimeo: Support privacy hash in vimeo URL --- src/core/directives/format-text.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/directives/format-text.ts b/src/core/directives/format-text.ts index 5171ae54b..5426588bc 100644 --- a/src/core/directives/format-text.ts +++ b/src/core/directives/format-text.ts @@ -786,11 +786,22 @@ export class CoreFormatTextDirective implements OnChanges { if (site && src) { // Check if it's a Vimeo video. If it is, use the wsplayer script instead to make restricted videos work. - const matches = iframe.src.match(/https?:\/\/player\.vimeo\.com\/video\/([0-9]+)/); + const matches = src.match(/https?:\/\/player\.vimeo\.com\/video\/([0-9]+)([?&]+h=([a-zA-Z0-9]*))?/); if (matches && matches[1]) { let newUrl = CoreTextUtils.concatenatePaths(site.getURL(), '/media/player/vimeo/wsplayer.php?video=') + matches[1] + '&token=' + site.getToken(); + let privacyHash: string | undefined | null = matches[3]; + if (!privacyHash) { + // No privacy hash using the new format. Check the legacy format. + const matches = src.match(/https?:\/\/player\.vimeo\.com\/video\/([0-9]+)(\/([a-zA-Z0-9]+))?/); + privacyHash = matches && matches[3]; + } + + if (privacyHash) { + newUrl += `&h=${privacyHash}`; + } + // Width and height are mandatory, we need to calculate them. let width: string | number; let height: string | number; @@ -818,7 +829,7 @@ export class CoreFormatTextDirective implements OnChanges { newUrl += '&width=' + width + '&height=' + height; } - await CoreIframeUtils.fixIframeCookies(src); + await CoreIframeUtils.fixIframeCookies(newUrl); iframe.src = newUrl;