Remove react-native-fs (#5463)
* remove rnfs * tweak e2e * log * use `safeDeleteAsync`
This commit is contained in:
@@ -175,7 +175,6 @@
|
|||||||
"react-native-compressor": "^1.8.24",
|
"react-native-compressor": "^1.8.24",
|
||||||
"react-native-date-picker": "^4.4.2",
|
"react-native-date-picker": "^4.4.2",
|
||||||
"react-native-drawer-layout": "^4.0.0-alpha.3",
|
"react-native-drawer-layout": "^4.0.0-alpha.3",
|
||||||
"react-native-fs": "^2.20.0",
|
|
||||||
"react-native-gesture-handler": "~2.16.2",
|
"react-native-gesture-handler": "~2.16.2",
|
||||||
"react-native-get-random-values": "~1.11.0",
|
"react-native-get-random-values": "~1.11.0",
|
||||||
"react-native-image-crop-picker": "0.41.2",
|
"react-native-image-crop-picker": "0.41.2",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import RNFS from 'react-native-fs'
|
import {copyAsync} from 'expo-file-system'
|
||||||
import {BskyAgent, ComAtprotoRepoUploadBlob} from '@atproto/api'
|
import {BskyAgent, ComAtprotoRepoUploadBlob} from '@atproto/api'
|
||||||
|
|
||||||
|
import {safeDeleteAsync} from '#/lib/media/manip'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param encoding Allows overriding the blob's type
|
* @param encoding Allows overriding the blob's type
|
||||||
*/
|
*/
|
||||||
@@ -65,7 +67,7 @@ async function withSafeFile<T>(
|
|||||||
// temporary file).
|
// temporary file).
|
||||||
const newPath = uri.replace(/\.jpe?g$/, '.bin')
|
const newPath = uri.replace(/\.jpe?g$/, '.bin')
|
||||||
try {
|
try {
|
||||||
await RNFS.copyFile(uri, newPath)
|
await copyAsync({from: uri, to: newPath})
|
||||||
} catch {
|
} catch {
|
||||||
// Failed to copy the file, just use the original
|
// Failed to copy the file, just use the original
|
||||||
return await fn(uri)
|
return await fn(uri)
|
||||||
@@ -74,7 +76,7 @@ async function withSafeFile<T>(
|
|||||||
return await fn(newPath)
|
return await fn(newPath)
|
||||||
} finally {
|
} finally {
|
||||||
// Remove the temporary file
|
// Remove the temporary file
|
||||||
await RNFS.unlink(newPath)
|
await safeDeleteAsync(newPath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return fn(uri)
|
return fn(uri)
|
||||||
|
|||||||
@@ -1,25 +1,37 @@
|
|||||||
import RNFS from 'react-native-fs'
|
|
||||||
import {
|
import {
|
||||||
Image as RNImage,
|
Image as RNImage,
|
||||||
openCropper as openCropperFn,
|
openCropper as openCropperFn,
|
||||||
} from 'react-native-image-crop-picker'
|
} from 'react-native-image-crop-picker'
|
||||||
|
import {
|
||||||
|
documentDirectory,
|
||||||
|
getInfoAsync,
|
||||||
|
readDirectoryAsync,
|
||||||
|
} from 'expo-file-system'
|
||||||
|
|
||||||
import {compressIfNeeded} from './manip'
|
import {compressIfNeeded} from './manip'
|
||||||
import {CropperOptions} from './types'
|
import {CropperOptions} from './types'
|
||||||
|
|
||||||
async function getFile() {
|
async function getFile() {
|
||||||
let files = await RNFS.readDir(
|
const imagesDir = documentDirectory!
|
||||||
RNFS.LibraryDirectoryPath.split('/')
|
.split('/')
|
||||||
.slice(0, -5)
|
.slice(0, -6)
|
||||||
.concat(['Media', 'DCIM', '100APPLE'])
|
.concat(['Media', 'DCIM', '100APPLE'])
|
||||||
.join('/'),
|
.join('/')
|
||||||
)
|
|
||||||
files = files.filter(file => file.path.endsWith('.JPG'))
|
let files = await readDirectoryAsync(imagesDir)
|
||||||
const file = files[0]
|
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({
|
return await compressIfNeeded({
|
||||||
path: file.path,
|
path: file,
|
||||||
mime: 'image/jpeg',
|
mime: 'image/jpeg',
|
||||||
size: file.size,
|
size: fileInfo.size,
|
||||||
width: 4288,
|
width: 4288,
|
||||||
height: 2848,
|
height: 2848,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9540,7 +9540,7 @@ balanced-match@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
|
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
|
||||||
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
|
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
|
||||||
|
|
||||||
base-64@0.1.0, base-64@^0.1.0:
|
base-64@0.1.0:
|
||||||
version "0.1.0"
|
version "0.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
|
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
|
||||||
integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==
|
integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==
|
||||||
@@ -19038,14 +19038,6 @@ react-native-drawer-layout@^4.0.0-alpha.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
use-latest-callback "^0.1.9"
|
use-latest-callback "^0.1.9"
|
||||||
|
|
||||||
react-native-fs@^2.20.0:
|
|
||||||
version "2.20.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.20.0.tgz#05a9362b473bfc0910772c0acbb73a78dbc810f6"
|
|
||||||
integrity sha512-VkTBzs7fIDUiy/XajOSNk0XazFE9l+QlMAce7lGuebZcag5CnjszB+u4BdqzwaQOdcYb5wsJIsqq4kxInIRpJQ==
|
|
||||||
dependencies:
|
|
||||||
base-64 "^0.1.0"
|
|
||||||
utf8 "^3.0.0"
|
|
||||||
|
|
||||||
react-native-gesture-handler@~2.16.2:
|
react-native-gesture-handler@~2.16.2:
|
||||||
version "2.16.2"
|
version "2.16.2"
|
||||||
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.16.2.tgz#032bd2a07334292d7f6cff1dc9d1ec928f72e26d"
|
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.16.2.tgz#032bd2a07334292d7f6cff1dc9d1ec928f72e26d"
|
||||||
@@ -21830,11 +21822,6 @@ use-sidecar@^1.1.2:
|
|||||||
detect-node-es "^1.1.0"
|
detect-node-es "^1.1.0"
|
||||||
tslib "^2.0.0"
|
tslib "^2.0.0"
|
||||||
|
|
||||||
utf8@^3.0.0:
|
|
||||||
version "3.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1"
|
|
||||||
integrity sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==
|
|
||||||
|
|
||||||
util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
|
util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
|
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
|
||||||
|
|||||||
Reference in New Issue
Block a user