mirror of
https://github.com/balzack/databag.git
synced 2025-03-13 00:50:03 +00:00
finess download of images for android, seems very brittle
This commit is contained in:
parent
15ab5cb2e9
commit
0430403e01
@ -26,7 +26,12 @@ export function ImageAsset({ asset, dismiss }) {
|
||||
)}
|
||||
{ state.loaded && state.controls && Platform.OS !== 'ios' && (
|
||||
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||
{ state.downloaded && (
|
||||
<MatIcons name="download-outline" size={32} color={Colors.white} />
|
||||
)}
|
||||
{ !state.downloaded && (
|
||||
<MatIcons name="download" size={32} color={Colors.white} />
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
{ state.loaded && state.controls && (
|
||||
|
@ -4,6 +4,7 @@ import { Image, Platform } from 'react-native';
|
||||
import { useWindowDimensions } from 'react-native';
|
||||
import Share from 'react-native-share';
|
||||
import RNFetchBlob from "rn-fetch-blob";
|
||||
import RNFS from "react-native-fs";
|
||||
|
||||
export function useImageAsset(asset) {
|
||||
|
||||
@ -17,6 +18,7 @@ export function useImageAsset(asset) {
|
||||
loaded: false,
|
||||
failed: false,
|
||||
controls: false,
|
||||
downloaded: false,
|
||||
});
|
||||
|
||||
const conversation = useContext(ConversationContext);
|
||||
@ -73,9 +75,22 @@ export function useImageAsset(asset) {
|
||||
Share.open({ url: state.url })
|
||||
},
|
||||
download: async () => {
|
||||
if (!state.downloaded) {
|
||||
updateState({ downloaded: true });
|
||||
const epoch = Math.ceil(Date.now() / 1000);
|
||||
const dir = Platform.OS === 'ios' ? RNFetchBlob.fs.dirs.DocumentDir : RNFetchBlob.fs.dirs.PictureDir;
|
||||
const res = await RNFetchBlob.config({path: `${dir}/databag_${epoch}.jpg`}).fetch("GET", state.url, {});
|
||||
const path = `${dir}/databag_${epoch}.jpg`
|
||||
if (state.url.substring(0, 7) === 'file://') {
|
||||
await RNFS.copyFile(state.url.substring(7).split('?')[0], path);
|
||||
}
|
||||
else {
|
||||
const res = await RNFetchBlob.config({path: path}).fetch("GET", state.url, {});
|
||||
}
|
||||
const block = await RNFS.read(path, 8, 0, 'base64');
|
||||
if (block === '/9j/4AAQSkY=') {
|
||||
await RNFS.scanFile(jpg);
|
||||
}
|
||||
}
|
||||
},
|
||||
loaded: () => {
|
||||
updateState({ loaded: true });
|
||||
|
Loading…
Reference in New Issue
Block a user