using local fs for share sheet

This commit is contained in:
balzack 2023-04-21 17:28:02 -07:00
parent 6bcdef60e8
commit 3ee8016918
2 changed files with 33 additions and 19 deletions

View File

@ -516,7 +516,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.11; MARKETING_VERSION = 1.12;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
"-ObjC", "-ObjC",
@ -549,7 +549,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.11; MARKETING_VERSION = 1.12;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
"-ObjC", "-ObjC",

View File

@ -115,28 +115,42 @@ export function TopicItem({ item, focused, focus, hosting, remove, update, block
const assets = data.assets || [] const assets = data.assets || []
for (let i = 0; i < assets.length; i++) { for (let i = 0; i < assets.length; i++) {
let asset
if (assets[i].image) { if (assets[i].image) {
const url = actions.getTopicAssetUrl(item.topicId, assets[i].image.full); asset = assets[i].image.full;
}
else if (assets[i].video?.lq) {
asset = assets[i].video.lq;
}
else if (assets[i].video?.hd) {
asset = assets[i].video.hd;
}
else if (assets[i].audio?.full) {
asset = assets[i].audio.full;
}
if (asset) {
const url = actions.getTopicAssetUrl(item.topicId, asset);
const blob = await RNFetchBlob.config({ fileCache: true }).fetch("GET", url); const blob = await RNFetchBlob.config({ fileCache: true }).fetch("GET", url);
const type = blob.respInfo.headers["Content-Type"] || blob.respInfo.headers["content-type"] const type = blob.respInfo.headers["Content-Type"] || blob.respInfo.headers["content-type"]
if (Platform.OS === 'ios') { const src = blob.path();
const file = await blob.readFile("base64"); const dir = src.split('/').slice(0,-1).join('/')
files.push(`data:${type};base64,${file}`) const dst = dir + '/' + asset + '.' + getExtension(type);
unlink.push(blob.path()); await fs.unlink(dst);
} await RNFetchBlob.fs.mv(src, dst);
else { files.push(`file://${dst}`);
const src = blob.path(); unlink.push(dst);
const dir = src.split('/').slice(0,-1).join('/')
const dst = dir + '/' + assets[i].image.full + '.' + getExtension(type);
await RNFetchBlob.fs.mv(src, dst);
files.push(`file://${dst}`);
unlink.push(dst);
}
} }
} }
await Share.open({ urls: files, message: data.text, title: 'Databag', subject: 'Shared from Databag' }) try {
await Share.open({ urls: files, message: data.text, title: 'Databag', subject: 'Shared from Databag' })
}
catch(err) {
console.log(err);
}
try { try {
for (let i = 0; i < unlink.length; i++) { for (let i = 0; i < unlink.length; i++) {
@ -151,7 +165,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update, block
console.log(err); console.log(err);
Alert.alert( Alert.alert(
'Failed to Share Message', 'Failed to Share Message',
err.toSring() 'Please try again.'
) )
} }
} }