From c3fcd486b3af97a2493190f9ec35febf6675f1ce Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 24 Apr 2024 17:12:36 -0700 Subject: Cleanup files after each iteration of compression and downloading (#3599) * delete image on each iteration of compression * replace a few other instances of `unlink()` * ensure that moving to the permanent path will succeed * use `cacheDirectory` * missing file extension? * assert * Remove extra . * Extract safeDeleteAsync, fix normalization * Normalize everywhere * Use safeDeleteAsync in more places * Delete .bin too --------- Co-authored-by: Dan Abramov --- src/lib/api/index.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'src/lib/api/index.ts') diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index cc86ce33c..bc50f9cb3 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -1,4 +1,3 @@ -import {deleteAsync} from 'expo-file-system' import { AppBskyEmbedExternal, AppBskyEmbedImages, @@ -20,6 +19,7 @@ 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' +import {safeDeleteAsync} from '../media/manip' export interface ExternalEmbedDraft { uri: string @@ -119,15 +119,9 @@ 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) - } + safeDeleteAsync(path) } - images.push({ image: res.data.blob, alt: image.altText ?? '', @@ -182,13 +176,8 @@ 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) + if (isNative) { + safeDeleteAsync(opts.extLink.localThumb.path) } } } -- cgit 1.4.1