From b813b204f362a0b198b21186d0d8371851b752b2 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 11 Apr 2024 16:07:16 -0700 Subject: [PATCH] some cleanup --- src/lib/media/manip.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/media/manip.ts b/src/lib/media/manip.ts index 1b4836b26e..7b5b97c4fb 100644 --- a/src/lib/media/manip.ts +++ b/src/lib/media/manip.ts @@ -164,11 +164,17 @@ async function doResize(localUri: string, opts: DoResizeOpts): Promise { }, ) - // @ts-ignore This is valid, `getInfoAsync` will always return a size. The type is wonky - const info: FileInfo & {size: number} = await getInfoAsync(resizeRes.uri, { + const info: FileInfo = await getInfoAsync(resizeRes.uri, { size: true, }) + // I'm not sure this can happen, but if we don't check `.exists`, then the `.size` type is undefined. + if (!info.exists) { + throw new Error( + 'The image manipulation library failed to create a new image.', + ) + } + // We want to clean up every resize _except_ the final result. We'll clean that one up later when we're finished // with it if (info.size < opts.maxSize) { @@ -204,8 +210,7 @@ async function moveToPermanentPath(path: string, ext = ''): Promise { }) // This is just to try and clean up whenever we can. We won't always be able to, so in cases where we can't - // we just catch the error. We can't simply move some files though such as image caches, so we will copy then - // and attempt to clean up the original file + // we just catch the error. // Paths that are image caches shouldn't be removed. com.hackemist.SDImageCache is used by SDWebImage and // image_manager_disk_cache is used by Glide if (