You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			23 lines
		
	
	
		
			604 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			23 lines
		
	
	
		
			604 B
		
	
	
	
		
			TypeScript
		
	
| import { useEffect, useState } from 'react';
 | |
| 
 | |
| import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsManager';
 | |
| 
 | |
| export const useEncryptedFileFetch = (url: string, contentType: string) => {
 | |
|   // tslint:disable-next-line: no-bitwise
 | |
|   const [urlToLoad, setUrlToLoad] = useState('');
 | |
|   const [loading, setLoading] = useState(true);
 | |
| 
 | |
|   async function fetchUrl() {
 | |
|     const decryptedUrl = await getDecryptedMediaUrl(url, contentType);
 | |
|     setUrlToLoad(decryptedUrl);
 | |
| 
 | |
|     setLoading(false);
 | |
|   }
 | |
| 
 | |
|   useEffect(() => {
 | |
|     void fetchUrl();
 | |
|   }, [url]);
 | |
| 
 | |
|   return { urlToLoad, loading };
 | |
| };
 |