From 00eb5363f11499e019803e2e9c03d6a9fcd2edca Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Thu, 16 Jan 2025 11:42:51 +0100 Subject: [PATCH] feat: Fallback to manually loading media on error This is needed for E2EE files that will error when loading them directly from the HTML element's src attribute. Signed-off-by: Louis Chemineau --- src/components/Audios.vue | 37 +++++++++++++++++++++++++++++++--- src/components/Images.vue | 10 +++++++-- src/components/Videos.vue | 33 +++++++++++++++++++++++++++--- src/services/mediaPreloader.ts | 19 +++++++++++++++++ 4 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 src/services/mediaPreloader.ts diff --git a/src/components/Audios.vue b/src/components/Audios.vue index 5c74fbb72..1c5772de9 100644 --- a/src/components/Audios.vue +++ b/src/components/Audios.vue @@ -6,13 +6,14 @@ - diff --git a/src/components/Images.vue b/src/components/Images.vue index e2655d728..a4a5e0f97 100644 --- a/src/components/Images.vue +++ b/src/components/Images.vue @@ -72,7 +72,7 @@ - diff --git a/src/services/mediaPreloader.ts b/src/services/mediaPreloader.ts new file mode 100644 index 000000000..0a6a89477 --- /dev/null +++ b/src/services/mediaPreloader.ts @@ -0,0 +1,19 @@ +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/* eslint-disable jsdoc/require-jsdoc */ + +import type { ResponseDataDetailed, WebDAVClient } from 'webdav' + +import { getClient, getRootPath } from '@nextcloud/files/dav' + +// Manually load a WebDAV media from its filename, then expose the received Blob as an object URL. +// This is needed for E2EE files that will error when loading them directly from the HTML element's src attribute. +// Can be removed if we ever move the E2EE proxy to a service worker. +export async function preloadMedia(filename: string): Promise { + const client = getClient() as WebDAVClient + const response = await client.getFileContents(`${getRootPath}${filename}`, { details: true }) as ResponseDataDetailed + return URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type'] })) +}