diff options
author | Hailey <me@haileyok.com> | 2024-09-24 09:28:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-25 01:28:12 +0900 |
commit | d2fae81b33ae0a73d0b9f87700365d60bc51f094 (patch) | |
tree | 5b73740db03827238401e172ec84b0512a9fee3a /src | |
parent | b9516202fa17325a3d54e54372ddd56149be129c (diff) | |
download | voidsky-d2fae81b33ae0a73d0b9f87700365d60bc51f094.tar.zst |
Remove `react-native-fs` (#5463)
* remove rnfs * tweak e2e * log * use `safeDeleteAsync`
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/api/upload-blob.ts | 8 | ||||
-rw-r--r-- | src/lib/media/picker.e2e.tsx | 34 |
2 files changed, 28 insertions, 14 deletions
diff --git a/src/lib/api/upload-blob.ts b/src/lib/api/upload-blob.ts index 0814d5185..07aeaf1a7 100644 --- a/src/lib/api/upload-blob.ts +++ b/src/lib/api/upload-blob.ts @@ -1,6 +1,8 @@ -import RNFS from 'react-native-fs' +import {copyAsync} from 'expo-file-system' import {BskyAgent, ComAtprotoRepoUploadBlob} from '@atproto/api' +import {safeDeleteAsync} from '#/lib/media/manip' + /** * @param encoding Allows overriding the blob's type */ @@ -65,7 +67,7 @@ async function withSafeFile<T>( // temporary file). const newPath = uri.replace(/\.jpe?g$/, '.bin') try { - await RNFS.copyFile(uri, newPath) + await copyAsync({from: uri, to: newPath}) } catch { // Failed to copy the file, just use the original return await fn(uri) @@ -74,7 +76,7 @@ async function withSafeFile<T>( return await fn(newPath) } finally { // Remove the temporary file - await RNFS.unlink(newPath) + await safeDeleteAsync(newPath) } } else { return fn(uri) diff --git a/src/lib/media/picker.e2e.tsx b/src/lib/media/picker.e2e.tsx index e6b46ba77..fc6fcde45 100644 --- a/src/lib/media/picker.e2e.tsx +++ b/src/lib/media/picker.e2e.tsx @@ -1,25 +1,37 @@ -import RNFS from 'react-native-fs' import { Image as RNImage, openCropper as openCropperFn, } from 'react-native-image-crop-picker' +import { + documentDirectory, + getInfoAsync, + readDirectoryAsync, +} from 'expo-file-system' import {compressIfNeeded} from './manip' import {CropperOptions} from './types' async function getFile() { - let files = await RNFS.readDir( - RNFS.LibraryDirectoryPath.split('/') - .slice(0, -5) - .concat(['Media', 'DCIM', '100APPLE']) - .join('/'), - ) - files = files.filter(file => file.path.endsWith('.JPG')) - const file = files[0] + const imagesDir = documentDirectory! + .split('/') + .slice(0, -6) + .concat(['Media', 'DCIM', '100APPLE']) + .join('/') + + let files = await readDirectoryAsync(imagesDir) + files = files.filter(file => file.endsWith('.JPG')) + const file = `${imagesDir}/${files[0]}` + + const fileInfo = await getInfoAsync(file) + + if (!fileInfo.exists) { + throw new Error('Failed to get file info') + } + return await compressIfNeeded({ - path: file.path, + path: file, mime: 'image/jpeg', - size: file.size, + size: fileInfo.size, width: 4288, height: 2848, }) |