From 32a48991946f755b9788982171175dc7986ada18 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 29 May 2023 11:49:14 -0700 Subject: [PATCH] ximg: get fileid only after regex match Signed-off-by: Varun Patil --- src/components/frame/XImgWorker.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/frame/XImgWorker.ts b/src/components/frame/XImgWorker.ts index c1c0e714..ab721ccc 100644 --- a/src/components/frame/XImgWorker.ts +++ b/src/components/frame/XImgWorker.ts @@ -214,9 +214,8 @@ async function fetchImage(url: string): Promise { const cache = await imageCache?.match(url); if (cache) return await cache.blob(); - // Get file id from URL + // Parse URL const urlObj = new URL(url, self.location.origin); - const fileid = Number(urlObj.pathname.split('/').pop()); // Just fetch if not a preview const regex = /^.*\/apps\/memories\/api\/image\/preview\/.*/; @@ -227,6 +226,9 @@ async function fetchImage(url: string): Promise { return await res.blob(); } + // Get file id from URL + const fileid = Number(urlObj.pathname.split('/').pop()); + return await new Promise((resolve, reject) => { if (pendingUrls.has(url)) { // Already in queue, just add callback