-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
4 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> { | ||
const client = getClient() as WebDAVClient | ||
const response = await client.getFileContents(`${getRootPath}${filename}`, { details: true }) as ResponseDataDetailed<ArrayBuffer> | ||
return URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type'] })) | ||
} |