Fix authenticated media download (#1947)

* remove dead function

* fix media download in room timeline

* authenticate remaining media endpoints
This commit is contained in:
Ajay Bura 2024-09-11 17:07:02 +10:00 committed by GitHub
parent f2c31d29a2
commit 03cc25eec0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 284 additions and 207 deletions

View file

@ -273,3 +273,20 @@ export const mxcUrlToHttp = (
allowRedirects,
useAuthentication
);
export const downloadMedia = async (src: string): Promise<Blob> => {
// this request is authenticated by service worker
const res = await fetch(src, { method: 'GET' });
const blob = await res.blob();
return blob;
};
export const downloadEncryptedMedia = async (
src: string,
decryptContent: (buf: ArrayBuffer) => Promise<Blob>
): Promise<Blob> => {
const encryptedContent = await downloadMedia(src);
const decryptedContent = await decryptContent(await encryptedContent.arrayBuffer());
return decryptedContent;
};