diff options
author | Hailey <me@haileyok.com> | 2024-04-24 17:12:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-25 01:12:36 +0100 |
commit | c3fcd486b3af97a2493190f9ec35febf6675f1ce (patch) | |
tree | 60943e86feeb89ee11279acdb07aad2fc7351889 /src/lib/api | |
parent | 90c3ec87490497605dacb158668d3f8c07f4dcdc (diff) | |
download | voidsky-c3fcd486b3af97a2493190f9ec35febf6675f1ce.tar.zst |
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 <dan.abramov@gmail.com>
Diffstat (limited to 'src/lib/api')
-rw-r--r-- | src/lib/api/index.ts | 19 |
1 files changed, 4 insertions, 15 deletions
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) } } } |