mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
using share for download storage
This commit is contained in:
parent
f2919bface
commit
e59f025e5a
@ -13,8 +13,9 @@ export function BinaryAsset({ asset, dismiss }) {
|
||||
|
||||
const download = async () => {
|
||||
try {
|
||||
const url = asset.encrypted ? `file://${asset.decrypted}` : asset.data;
|
||||
await actions.download(asset.label, asset.extension, url);
|
||||
const ext = asset.extension.toLowerCase();
|
||||
const url = asset.encrypted ? asset.decrypted : asset.data;
|
||||
await actions.download(asset.label, ext, asset.encrypted, url);
|
||||
}
|
||||
catch (err) {
|
||||
Alert.alert(
|
||||
|
@ -31,37 +31,33 @@ export function useBinaryAsset() {
|
||||
}, [dimensions]);
|
||||
|
||||
const actions = {
|
||||
download: async (label, extension, url) => {
|
||||
download: async (label, extension, cached, url) => {
|
||||
if (!state.downloading) {
|
||||
try {
|
||||
updateState({ downloading: true });
|
||||
|
||||
const blob = await RNFetchBlob.config({ fileCache: true }).fetch("GET", url);
|
||||
const src = blob.path();
|
||||
if (Platform.OS === 'ios') {
|
||||
const path = `${RNFetchBlob.fs.dirs.DocumentDir}`
|
||||
const dst = `${path}/${label}.${extension.toLowerCase()}`
|
||||
if (RNFetchBlob.fs.exists(dst)) {
|
||||
RNFetchBlob.fs.unlink(dst);
|
||||
}
|
||||
await RNFetchBlob.fs.mv(src, dst);
|
||||
try {
|
||||
await Share.open({ url: dst, message: `${label}.${extension}`, subject: `${label}.${extension}` })
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
RNFetchBlob.fs.unlink(dst);
|
||||
let src;
|
||||
if (cached) {
|
||||
src = url
|
||||
}
|
||||
else {
|
||||
const path = `${RNFetchBlob.fs.dirs.DownloadDir}`
|
||||
const dst = `${path}/${label}.${extension.toLowerCase()}`
|
||||
if (RNFetchBlob.fs.exists(dst)) {
|
||||
RNFetchBlob.fs.unlink(dst);
|
||||
}
|
||||
await RNFetchBlob.fs.mv(src, dst);
|
||||
const blob = await RNFetchBlob.config({ fileCache: true }).fetch("GET", url);
|
||||
src = blob.path();
|
||||
}
|
||||
|
||||
const path = `${RNFetchBlob.fs.dirs.DocumentDir}`
|
||||
const dst = `${path}/${label}.${extension.toLowerCase()}`
|
||||
if (RNFetchBlob.fs.exists(dst)) {
|
||||
RNFetchBlob.fs.unlink(dst);
|
||||
}
|
||||
await RNFetchBlob.fs.mv(src, dst);
|
||||
try {
|
||||
await Share.open({ url: dst, message: `${label}.${extension}`, subject: `${label}.${extension}` })
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
RNFetchBlob.fs.unlink(dst);
|
||||
|
||||
updateState({ downloading: false });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user