From c564ac8b69ea6f0a20cac17b77d6272b26f2e413 Mon Sep 17 00:00:00 2001 From: skidoodle Date: Sat, 7 Mar 2026 00:53:21 +0100 Subject: [PATCH] clean geocache --- utils/storage.ts | 18 ++++++++++++++++++ wxt.config.ts | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/utils/storage.ts b/utils/storage.ts index 1fdc6ca..1189212 100644 --- a/utils/storage.ts +++ b/utils/storage.ts @@ -53,5 +53,23 @@ export const StorageService = { const key = `geo_${ip.replace(/:/g, '_')}`; const entry: CacheEntry = { data, timestamp: Date.now() }; await browser.storage.local.set({ [key]: entry }); + }, + + async cleanExpiredGeoCache(): Promise { + const res = await browser.storage.local.get(null); + const keysToRemove: string[] = []; + + for (const [key, value] of Object.entries(res)) { + if (key.startsWith('geo_')) { + const entry = value as CacheEntry; + if (Date.now() - entry.timestamp > CACHE_TTL) { + keysToRemove.push(key); + } + } + } + + if (keysToRemove.length > 0) { + await browser.storage.local.remove(keysToRemove); + } } }; diff --git a/wxt.config.ts b/wxt.config.ts index 433ed3f..6e4f5df 100644 --- a/wxt.config.ts +++ b/wxt.config.ts @@ -12,7 +12,8 @@ export default defineConfig({ 'tabs', 'webRequest', 'webNavigation', - 'storage' + 'storage', + 'alarms' ], host_permissions: [ '',