2021-03-25 00:58:21 +01:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
2021-04-13 06:10:31 +02:00
|
|
|
import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsManager';
|
2021-03-26 03:07:42 +01:00
|
|
|
|
|
|
|
export const useEncryptedFileFetch = (url: string, contentType: string) => {
|
2021-03-25 00:58:21 +01:00
|
|
|
// tslint:disable-next-line: no-bitwise
|
2021-03-26 03:07:42 +01:00
|
|
|
const [urlToLoad, setUrlToLoad] = useState('');
|
2021-03-25 00:58:21 +01:00
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
|
|
async function fetchUrl() {
|
2021-04-13 06:10:31 +02:00
|
|
|
const decryptedUrl = await getDecryptedMediaUrl(url, contentType);
|
2021-03-26 05:24:56 +01:00
|
|
|
setUrlToLoad(decryptedUrl);
|
2021-03-26 03:07:42 +01:00
|
|
|
|
2021-03-25 00:58:21 +01:00
|
|
|
setLoading(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
void fetchUrl();
|
|
|
|
}, [url]);
|
2021-03-26 03:07:42 +01:00
|
|
|
|
|
|
|
return { urlToLoad, loading };
|
2021-03-25 00:58:21 +01:00
|
|
|
};
|