From 9a93314118bdb78d5c92e47342f2d6d4d8a516bd Mon Sep 17 00:00:00 2001 From: Kuingsmile Date: Thu, 27 Feb 2025 16:47:07 +0800 Subject: [PATCH] :bug: Fix(custom): fix cache issues in gallery image ISSUES CLOSED: #288 --- src/main/events/rpc/routes/system/window.ts | 4 ++- src/renderer/pages/Gallery.vue | 37 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/events/rpc/routes/system/window.ts b/src/main/events/rpc/routes/system/window.ts index dd9cd3c..a2f8f81 100644 --- a/src/main/events/rpc/routes/system/window.ts +++ b/src/main/events/rpc/routes/system/window.ts @@ -142,7 +142,9 @@ export default [ action: IRPCActionType.REFRESH_SETTING_WINDOW, handler: async () => { const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)! - settingWindow.webContents.reloadIgnoringCache() + settingWindow.webContents.session.clearCache().then(() => { + settingWindow.webContents.reloadIgnoringCache() + }) } } ] diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index 0b9a5ee..969611b 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -165,7 +165,7 @@ @@ -432,6 +432,39 @@ const filterList = computed(() => { return res }) +const addCacheBustParam = (url: string | undefined) => { + if (!url) { + return '' + } + if (!(url.startsWith('http://') || url.startsWith('https://'))) { + return url + } + try { + const separator = url.includes('?') ? '&' : '?' + return `${url}${separator}cbplist=${new Date().getTime()}` + } catch (e) { + return url + } +} + +const filterListWithCacheBust = computed(() => { + const newList = filterList.value.map(item => { + const newItem = { ...item } + if (newItem.imgUrl) { + newItem.imgUrl = addCacheBustParam(newItem.imgUrl) + } + + if (newItem.galleryPath) { + newItem.galleryPath = addCacheBustParam(newItem.galleryPath) + } + + newItem.src = addCacheBustParam(newItem.src || newItem.galleryPath || newItem.imgUrl || '') + + return newItem + }) + return newList +}) + const isAllSelected = computed(() => { return Object.values(choosedList).length > 0 && filterList.value.every(item => choosedList[item.id!]) })