diff --git a/native/media/encrypted-image.react.js b/native/media/encrypted-image.react.js --- a/native/media/encrypted-image.react.js +++ b/native/media/encrypted-image.react.js @@ -10,7 +10,7 @@ import type { ImageStyle } from '../types/styles.js'; type BaseProps = { - +holder: string, + +blobURI: string, +encryptionKey: string, +onLoad?: (uri: string) => void, +spinnerColor: string, @@ -24,7 +24,7 @@ function EncryptedImage(props: Props): React.Node { const { - holder, + blobURI, encryptionKey, onLoad: onLoadProp, thumbHash: encryptedThumbHash, @@ -64,18 +64,18 @@ setSource(null); const loadDecrypted = async () => { - const cached = await mediaCache?.get(holder); + const cached = await mediaCache?.get(blobURI); if (cached && isMounted) { setSource({ uri: cached }); return; } - const { result } = await decryptMedia(holder, encryptionKey, { + const { result } = await decryptMedia(blobURI, encryptionKey, { destination: 'data_uri', }); // TODO: decide what to do if decryption fails if (result.success && isMounted) { - mediaCache?.set(holder, result.uri); + mediaCache?.set(blobURI, result.uri); setSource({ uri: result.uri }); } }; @@ -85,11 +85,11 @@ return () => { isMounted = false; }; - }, [attempt, holder, encryptionKey, mediaCache]); + }, [attempt, blobURI, encryptionKey, mediaCache]); const onLoad = React.useCallback(() => { - onLoadProp && onLoadProp(holder); - }, [holder, onLoadProp]); + onLoadProp && onLoadProp(blobURI); + }, [blobURI, onLoadProp]); const { style, spinnerColor, invisibleLoad } = props; diff --git a/native/media/encryption-utils.js b/native/media/encryption-utils.js --- a/native/media/encryption-utils.js +++ b/native/media/encryption-utils.js @@ -279,7 +279,7 @@ }; async function decryptMedia( - holder: string, + blobURI: string, encryptionKey: string, options: { +destination: 'file' | 'data_uri' }, ): Promise<{ @@ -294,7 +294,7 @@ const fetchStartTime = Date.now(); let data; try { - const response = await fetch(getFetchableURI(holder)); + const response = await fetch(getFetchableURI(blobURI)); if (!response.ok) { throw new Error(`HTTP error ${response.status}: ${response.statusText}`); } @@ -307,7 +307,7 @@ } steps.push({ step: 'fetch_file', - file: holder, + file: blobURI, time: Date.now() - fetchStartTime, success, exceptionMessage, @@ -367,9 +367,9 @@ }; } if (options.destination === 'file') { - // if holder is a URL, then we use the last part of the path as the filename - const holderSuffix = holder.substring(holder.lastIndexOf('/') + 1); - const filename = readableFilename(holderSuffix, mime) || holderSuffix; + // blobURI is a URL, we use the last part of the path as the filename + const uriSuffix = blobURI.substring(blobURI.lastIndexOf('/') + 1); + const filename = readableFilename(uriSuffix, mime) || uriSuffix; const targetPath = `${temporaryDirectoryPath}${Date.now()}-${filename}`; try { await commUtilsModule.writeBufferToFile(targetPath, decryptedData.buffer); diff --git a/native/media/multimedia.react.js b/native/media/multimedia.react.js --- a/native/media/multimedia.react.js +++ b/native/media/multimedia.react.js @@ -20,7 +20,7 @@ } | { +kind: 'encrypted', - +holder: string, + +blobURI: string, +encryptionKey: string, +thumbHash?: ?string, }; @@ -119,13 +119,13 @@ return ( ); } @@ -184,14 +184,14 @@ } else if (mediaInfo.type === 'encrypted_photo') { return { kind: 'encrypted', - holder: mediaInfo.holder, + blobURI: mediaInfo.holder, encryptionKey: mediaInfo.encryptionKey, thumbHash: mediaInfo.thumbHash, }; } else if (mediaInfo.type === 'encrypted_video') { return { kind: 'encrypted', - holder: mediaInfo.thumbnailHolder, + blobURI: mediaInfo.thumbnailHolder, encryptionKey: mediaInfo.thumbnailEncryptionKey, thumbHash: mediaInfo.thumbnailThumbHash, }; diff --git a/native/media/video-playback-modal.react.js b/native/media/video-playback-modal.react.js --- a/native/media/video-playback-modal.react.js +++ b/native/media/video-playback-modal.react.js @@ -79,7 +79,7 @@ function VideoPlaybackModal(props: Props): React.Node { const { mediaInfo } = props.route.params; - const { uri: videoUri, holder, encryptionKey } = mediaInfo; + const { uri: videoUri, holder: blobURI, encryptionKey } = mediaInfo; const [videoSource, setVideoSource] = React.useState( videoUri ? { uri: videoUri } : undefined, ); @@ -88,7 +88,7 @@ React.useEffect(() => { // skip for unencrypted videos - if (!holder || !encryptionKey) { + if (!blobURI || !encryptionKey) { return undefined; } @@ -97,18 +97,18 @@ setVideoSource(undefined); const loadDecrypted = async () => { - const cached = await mediaCache?.get(holder); + const cached = await mediaCache?.get(blobURI); if (cached && isMounted) { setVideoSource({ uri: cached }); return; } - const { result } = await decryptMedia(holder, encryptionKey, { + const { result } = await decryptMedia(blobURI, encryptionKey, { destination: 'file', }); if (result.success) { const { uri } = result; - const cacheSetPromise = mediaCache?.set(holder, uri); + const cacheSetPromise = mediaCache?.set(blobURI, uri); if (isMounted) { uriToDispose = uri; setVideoSource({ uri }); @@ -129,7 +129,7 @@ filesystem.unlink(uriToDispose); } }; - }, [holder, encryptionKey, mediaCache]); + }, [blobURI, encryptionKey, mediaCache]); const closeButtonX = useValue(-1); const closeButtonY = useValue(-1);