Decrypt audio and video

This commit is contained in:
Diego Mello 2024-05-15 17:35:45 -03:00
parent fd7d0a8955
commit c67cb0deb4
3 changed files with 7 additions and 6 deletions

View File

@ -51,7 +51,8 @@ const MessageAudio = ({ file, getCustomEmoji, author, isReply, style, msg }: IMe
const audio = await downloadMediaFile({
downloadUrl: getAudioUrlToCache({ token: user.token, userId: user.id, url: audioUrl }),
type: 'audio',
mimeType: file.audio_type
mimeType: file.audio_type,
encryption: file.encryption
});
setFileUri(audio);
setDownloadState('downloaded');

View File

@ -161,7 +161,8 @@ const Video = ({ file, showAttachment, getCustomEmoji, style, isReply, msg }: IM
const videoUri = await downloadMediaFile({
downloadUrl: video,
type: 'video',
mimeType: file.video_type
mimeType: file.video_type,
encryption: file.encryption
});
updateVideoCached(videoUri);
} catch {

View File

@ -108,13 +108,11 @@ const ensureDirAsync = async (dir: string, intermediates = true): Promise<void>
export const getFilePath = ({
type,
mimeType,
urlToCache,
encrypted = false
urlToCache
}: {
type: MediaTypes;
mimeType?: string;
urlToCache?: string;
encrypted?: boolean;
}): string | null => {
if (!urlToCache) {
return null;
@ -212,7 +210,7 @@ export function downloadMediaFile({
return new Promise(async (resolve, reject) => {
let downloadKey = '';
try {
const path = getFilePath({ type, mimeType, urlToCache: downloadUrl, encrypted: !!encryption });
const path = getFilePath({ type, mimeType, urlToCache: downloadUrl });
if (!path) {
return reject();
}
@ -225,6 +223,7 @@ export function downloadMediaFile({
}
const decryptedFile = await decryptAESCTR(result.uri, encryption.key.k, encryption.iv);
console.log('🚀 ~ returnnewPromise ~ decryptedFile:', decryptedFile);
if (decryptedFile) {
return resolve(decryptedFile);
}