Cleanup files after upload on native (#3597)

* cleanup images after uploading from the composer

cleanup external embed images as well

cleanup files after upload

add `expo-file-system`

* remove test log

* await

* Revert "await"

This reverts commit 771814b40ce1395cac4f56853d8a9e793ca92c2f.

* just log an error if it throws
zio/stable
Hailey 2024-04-17 12:49:22 -07:00 committed by GitHub
parent a2df81416b
commit 410f155988
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 6 deletions

View File

@ -116,6 +116,7 @@
"expo-constants": "~15.4.5", "expo-constants": "~15.4.5",
"expo-dev-client": "~3.3.8", "expo-dev-client": "~3.3.8",
"expo-device": "~5.9.3", "expo-device": "~5.9.3",
"expo-file-system": "^16.0.9",
"expo-haptics": "^12.8.1", "expo-haptics": "^12.8.1",
"expo-image": "~1.10.6", "expo-image": "~1.10.6",
"expo-image-manipulator": "^11.8.0", "expo-image-manipulator": "^11.8.0",

View File

@ -1,6 +1,7 @@
import {deleteAsync} from 'expo-file-system'
import { import {
AppBskyEmbedImages,
AppBskyEmbedExternal, AppBskyEmbedExternal,
AppBskyEmbedImages,
AppBskyEmbedRecord, AppBskyEmbedRecord,
AppBskyEmbedRecordWithMedia, AppBskyEmbedRecordWithMedia,
AppBskyFeedThreadgate, AppBskyFeedThreadgate,
@ -11,13 +12,14 @@ import {
RichText, RichText,
} from '@atproto/api' } from '@atproto/api'
import {AtUri} from '@atproto/api' import {AtUri} from '@atproto/api'
import {isNetworkError} from 'lib/strings/errors'
import {LinkMeta} from '../link-meta/link-meta'
import {isWeb} from 'platform/detection'
import {ImageModel} from 'state/models/media/image'
import {shortenLinks} from 'lib/strings/rich-text-manip'
import {logger} from '#/logger' import {logger} from '#/logger'
import {ThreadgateSetting} from '#/state/queries/threadgate' import {ThreadgateSetting} from '#/state/queries/threadgate'
import {isNetworkError} from 'lib/strings/errors'
import {shortenLinks} from 'lib/strings/rich-text-manip'
import {isNative, isWeb} from 'platform/detection'
import {ImageModel} from 'state/models/media/image'
import {LinkMeta} from '../link-meta/link-meta'
export interface ExternalEmbedDraft { export interface ExternalEmbedDraft {
uri: string uri: string
@ -117,6 +119,15 @@ export async function post(agent: BskyAgent, opts: PostOpts) {
const {width, height} = image.compressed || image const {width, height} = image.compressed || image
logger.debug(`Uploading image`) logger.debug(`Uploading image`)
const res = await uploadBlob(agent, path, 'image/jpeg') const res = await uploadBlob(agent, path, 'image/jpeg')
if (isNative) {
try {
deleteAsync(path)
} catch (e) {
console.error(e)
}
}
images.push({ images.push({
image: res.data.blob, image: res.data.blob,
alt: image.altText ?? '', alt: image.altText ?? '',
@ -171,6 +182,14 @@ export async function post(agent: BskyAgent, opts: PostOpts) {
encoding, encoding,
) )
thumb = thumbUploadRes.data.blob thumb = thumbUploadRes.data.blob
try {
if (isNative) {
deleteAsync(opts.extLink.localThumb.path)
}
} catch (e) {
console.error(e)
}
} }
} }

View File

@ -11852,6 +11852,11 @@ expo-eas-client@~0.11.0:
resolved "https://registry.yarnpkg.com/expo-eas-client/-/expo-eas-client-0.11.0.tgz#0f25aa497849cade7ebef55c0631093a87e58b07" resolved "https://registry.yarnpkg.com/expo-eas-client/-/expo-eas-client-0.11.0.tgz#0f25aa497849cade7ebef55c0631093a87e58b07"
integrity sha512-99W0MUGe3U4/MY1E9UeJ4uKNI39mN8/sOGA0Le8XC47MTbwbLoVegHR3C5y2fXLwLn7EpfNxAn5nlxYjY3gD2A== integrity sha512-99W0MUGe3U4/MY1E9UeJ4uKNI39mN8/sOGA0Le8XC47MTbwbLoVegHR3C5y2fXLwLn7EpfNxAn5nlxYjY3gD2A==
expo-file-system@^16.0.9:
version "16.0.9"
resolved "https://registry.yarnpkg.com/expo-file-system/-/expo-file-system-16.0.9.tgz#cbd6c4b228b60a6b6c71fd1b91fe57299fb24da7"
integrity sha512-3gRPvKVv7/Y7AdD9eHMIdfg5YbUn2zbwKofjsloTI5sEC57SLUFJtbLvUCz9Pk63DaSQ7WIE1JM0EASyvuPbuw==
expo-file-system@~16.0.0: expo-file-system@~16.0.0:
version "16.0.1" version "16.0.1"
resolved "https://registry.yarnpkg.com/expo-file-system/-/expo-file-system-16.0.1.tgz#326b7c2f6e53e1a0eaafc9769578aafb3f9c9f43" resolved "https://registry.yarnpkg.com/expo-file-system/-/expo-file-system-16.0.1.tgz#326b7c2f6e53e1a0eaafc9769578aafb3f9c9f43"