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
This commit is contained in:
parent
a2df81416b
commit
410f155988
3 changed files with 31 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue