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({ const audio = await downloadMediaFile({
downloadUrl: getAudioUrlToCache({ token: user.token, userId: user.id, url: audioUrl }), downloadUrl: getAudioUrlToCache({ token: user.token, userId: user.id, url: audioUrl }),
type: 'audio', type: 'audio',
mimeType: file.audio_type mimeType: file.audio_type,
encryption: file.encryption
}); });
setFileUri(audio); setFileUri(audio);
setDownloadState('downloaded'); setDownloadState('downloaded');

View File

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

View File

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