From d7d43fe6a37e20ba2182ca0c36e24bcde815e07f Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 11 Apr 2024 17:03:49 -0700 Subject: [PATCH] cleanup after ourselves --- src/lib/api/api-polyfill.ts | 11 ++++++++--- src/lib/media/manip.ts | 13 ++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lib/api/api-polyfill.ts b/src/lib/api/api-polyfill.ts index ea1d975985..8ac6511144 100644 --- a/src/lib/api/api-polyfill.ts +++ b/src/lib/api/api-polyfill.ts @@ -1,5 +1,5 @@ -import {BskyAgent, stringifyLex, jsonToLex} from '@atproto/api' import RNFS from 'react-native-fs' +import {BskyAgent, jsonToLex, stringifyLex} from '@atproto/api' const GET_TIMEOUT = 15e3 // 15s const POST_TIMEOUT = 60e3 // 60s @@ -34,8 +34,13 @@ async function fetchHandler( // see https://github.com/facebook/react-native/issues/27099 // -prf const newPath = reqBody.replace(/\.jpe?g$/, '.bin') - await RNFS.moveFile(reqBody, newPath) - reqBody = newPath + try { + await RNFS.moveFile(reqBody, newPath) + reqBody = newPath + } catch (e: any) { + await RNFS.copyFile(reqBody, newPath) + reqBody = newPath + } } // NOTE // React native treats bodies with {uri: string} as file uploads to pull from cache diff --git a/src/lib/media/manip.ts b/src/lib/media/manip.ts index a681627e67..569c03fb3a 100644 --- a/src/lib/media/manip.ts +++ b/src/lib/media/manip.ts @@ -1,13 +1,14 @@ -import RNFetchBlob from 'rn-fetch-blob' -import ImageResizer from '@bam.tech/react-native-image-resizer' import {Image as RNImage, Share as RNShare} from 'react-native' -import {Image} from 'react-native-image-crop-picker' import * as RNFS from 'react-native-fs' +import {Image} from 'react-native-image-crop-picker' import uuid from 'react-native-uuid' -import * as Sharing from 'expo-sharing' import * as MediaLibrary from 'expo-media-library' -import {Dimensions} from './types' +import * as Sharing from 'expo-sharing' +import ImageResizer from '@bam.tech/react-native-image-resizer' +import RNFetchBlob from 'rn-fetch-blob' + import {isAndroid, isIOS} from 'platform/detection' +import {Dimensions} from './types' export async function compressIfNeeded( img: Image, @@ -168,6 +169,8 @@ async function doResize(localUri: string, opts: DoResizeOpts): Promise { width: resizeRes.width, height: resizeRes.height, } + } else { + await RNFS.unlink(resizeRes.path) } } throw new Error(