Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32901303
D7225.1768188661.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7225.1768188661.diff
View Options
diff --git a/native/media/encrypted-image.react.js b/native/media/encrypted-image.react.js
new file mode 100644
--- /dev/null
+++ b/native/media/encrypted-image.react.js
@@ -0,0 +1,77 @@
+// @flow
+
+import * as React from 'react';
+
+import { decryptMedia } from './encryption-utils.js';
+import LoadableImage from './loadable-image.react.js';
+import { useSelector } from '../redux/redux-utils.js';
+import type { ImageStyle } from '../types/styles.js';
+
+type BaseProps = {
+ +holder: string,
+ +encryptionKey: string,
+ +onLoad: (uri: string) => void,
+ +spinnerColor: string,
+ +style: ImageStyle,
+ +invisibleLoad: boolean,
+};
+type Props = {
+ ...BaseProps,
+};
+
+function EncryptedImage(props: Props): React.Node {
+ const { holder, encryptionKey, onLoad: onLoadProp } = props;
+
+ const [source, setSource] = React.useState(null);
+
+ const connectionStatus = useSelector(state => state.connection.status);
+ const prevConnectionStatusRef = React.useRef(connectionStatus);
+ const [attempt, setAttempt] = React.useState(0);
+
+ if (prevConnectionStatusRef.current !== connectionStatus) {
+ if (!source && connectionStatus === 'connected') {
+ setAttempt(attempt + 1);
+ }
+ prevConnectionStatusRef.current = connectionStatus;
+ }
+
+ React.useEffect(() => {
+ let isMounted = true;
+ setSource(null);
+
+ const loadDecrypted = async () => {
+ const { result } = await decryptMedia(holder, encryptionKey, {
+ destination: 'data_uri',
+ });
+ // TODO: decide what to do if decryption fails
+ if (result.success && isMounted) {
+ setSource({ uri: result.uri });
+ }
+ };
+
+ loadDecrypted();
+
+ return () => {
+ isMounted = false;
+ };
+ }, [attempt, holder, encryptionKey]);
+
+ const onLoad = React.useCallback(() => {
+ onLoadProp && onLoadProp(holder);
+ }, [holder, onLoadProp]);
+
+ const { style, spinnerColor, invisibleLoad } = props;
+
+ return (
+ <LoadableImage
+ source={source}
+ onLoad={onLoad}
+ spinnerColor={spinnerColor}
+ style={style}
+ invisibleLoad={invisibleLoad}
+ key={attempt}
+ />
+ );
+}
+
+export default EncryptedImage;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 12, 3:31 AM (8 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5921510
Default Alt Text
D7225.1768188661.diff (2 KB)
Attached To
Mode
D7225: [native] Add component to display encrypted images
Attached
Detach File
Event Timeline
Log In to Comment