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: [ '',