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>
This commit is contained in:
parent
90c3ec8749
commit
c3fcd486b3
2 changed files with 41 additions and 29 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue