mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +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 () => {
|
const download = async () => {
|
||||||
try {
|
try {
|
||||||
const url = asset.encrypted ? `file://${asset.decrypted}` : asset.data;
|
const ext = asset.extension.toLowerCase();
|
||||||
await actions.download(asset.label, asset.extension, url);
|
const url = asset.encrypted ? asset.decrypted : asset.data;
|
||||||
|
await actions.download(asset.label, ext, asset.encrypted, url);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
|
@ -31,37 +31,33 @@ export function useBinaryAsset() {
|
|||||||
}, [dimensions]);
|
}, [dimensions]);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
download: async (label, extension, url) => {
|
download: async (label, extension, cached, url) => {
|
||||||
if (!state.downloading) {
|
if (!state.downloading) {
|
||||||
try {
|
try {
|
||||||
updateState({ downloading: true });
|
updateState({ downloading: true });
|
||||||
|
|
||||||
const blob = await RNFetchBlob.config({ fileCache: true }).fetch("GET", url);
|
let src;
|
||||||
const src = blob.path();
|
if (cached) {
|
||||||
if (Platform.OS === 'ios') {
|
src = url
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const path = `${RNFetchBlob.fs.dirs.DownloadDir}`
|
const blob = await RNFetchBlob.config({ fileCache: true }).fetch("GET", url);
|
||||||
const dst = `${path}/${label}.${extension.toLowerCase()}`
|
src = blob.path();
|
||||||
if (RNFetchBlob.fs.exists(dst)) {
|
}
|
||||||
RNFetchBlob.fs.unlink(dst);
|
|
||||||
}
|
const path = `${RNFetchBlob.fs.dirs.DocumentDir}`
|
||||||
await RNFetchBlob.fs.mv(src, dst);
|
const dst = `${path}/${label}.${extension.toLowerCase()}`
|
||||||
|
if (RNFetchBlob.fs.exists(dst)) {
|
||||||
RNFetchBlob.fs.unlink(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 });
|
updateState({ downloading: false });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user