diff options
author | Hailey <me@haileyok.com> | 2024-04-17 12:49:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 12:49:22 -0700 |
commit | 410f155988285e621d4c3891848bcbe70b890f38 (patch) | |
tree | 61bca6a94da4063273a7e5538df65e51a6e4ad4b | |
parent | a2df81416b4a9e4538e3a6d44917e3914294ab1f (diff) | |
download | voidsky-410f155988285e621d4c3891848bcbe70b890f38.tar.zst |
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
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/lib/api/index.ts | 31 | ||||
-rw-r--r-- | yarn.lock | 5 |
3 files changed, 31 insertions, 6 deletions
diff --git a/package.json b/package.json index e2560b677..da0260a72 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "expo-constants": "~15.4.5", "expo-dev-client": "~3.3.8", "expo-device": "~5.9.3", + "expo-file-system": "^16.0.9", "expo-haptics": "^12.8.1", "expo-image": "~1.10.6", "expo-image-manipulator": "^11.8.0", diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 5fb7fe50e..cc86ce33c 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -1,6 +1,7 @@ +import {deleteAsync} from 'expo-file-system' import { - AppBskyEmbedImages, AppBskyEmbedExternal, + AppBskyEmbedImages, AppBskyEmbedRecord, AppBskyEmbedRecordWithMedia, AppBskyFeedThreadgate, @@ -11,13 +12,14 @@ import { RichText, } 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 {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 { uri: string @@ -117,6 +119,15 @@ export async function post(agent: BskyAgent, opts: PostOpts) { const {width, height} = image.compressed || image logger.debug(`Uploading image`) const res = await uploadBlob(agent, path, 'image/jpeg') + + if (isNative) { + try { + deleteAsync(path) + } catch (e) { + console.error(e) + } + } + images.push({ image: res.data.blob, alt: image.altText ?? '', @@ -171,6 +182,14 @@ export async function post(agent: BskyAgent, opts: PostOpts) { encoding, ) thumb = thumbUploadRes.data.blob + + try { + if (isNative) { + deleteAsync(opts.extLink.localThumb.path) + } + } catch (e) { + console.error(e) + } } } diff --git a/yarn.lock b/yarn.lock index a45d38b84..f866565a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" 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: version "16.0.1" resolved "https://registry.yarnpkg.com/expo-file-system/-/expo-file-system-16.0.1.tgz#326b7c2f6e53e1a0eaafc9769578aafb3f9c9f43" |