Skip to content

Commit 1245f26

Browse files
committed
fix(rss-reader): harden cache and CORS proxy handling
- Only apply CORS proxy to absolute http/https URLs - Use number type for cache_interval to avoid parseInt edge cases - Wrap saveCache in try/catch to prevent storage errors from breaking renders - Document legacy cache format behaviour in loadCache
1 parent cd44910 commit 1245f26

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

edge-apps/rss-reader/src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ async function fetchFeed(
2222
): Promise<RssEntry[]> {
2323
const bypassCors =
2424
getSettingWithDefault<string>('bypass_cors', 'true') === 'true'
25-
const url = bypassCors ? `${getCorsProxyUrl()}/${rssUrl}` : rssUrl
25+
const isAbsolute = /^https?:/.test(rssUrl)
26+
const url =
27+
bypassCors && isAbsolute ? `${getCorsProxyUrl()}/${rssUrl}` : rssUrl
2628

2729
const response = await fetch(url)
2830
if (!response.ok) {
@@ -93,7 +95,7 @@ document.addEventListener('DOMContentLoaded', async () => {
9395
)
9496
const rssTitle = getSettingWithDefault<string>('rss_title', 'RSS Feed')
9597
const cacheInterval =
96-
parseInt(getSettingWithDefault<string>('cache_interval', '1800')) * 1000
98+
getSettingWithDefault<number>('cache_interval', 1800) * 1000
9799

98100
const loadAndRender = async () => {
99101
try {

edge-apps/rss-reader/src/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ export function loadCache(): RssEntry[] {
2424
const raw = localStorage.getItem(CACHE_KEY)
2525
if (!raw) return []
2626
const parsed: AppCache = JSON.parse(raw)
27+
// parsed.entries is undefined if the stored value is a legacy plain array;
28+
// falling back to [] causes a fresh fetch on first run after upgrade.
2729
return parsed.entries ?? []
2830
} catch {
2931
return []
3032
}
3133
}
3234

3335
export function saveCache(entries: RssEntry[]) {
34-
const data: AppCache = { entries, timestamp: Date.now() }
35-
localStorage.setItem(CACHE_KEY, JSON.stringify(data))
36+
try {
37+
const data: AppCache = { entries, timestamp: Date.now() }
38+
localStorage.setItem(CACHE_KEY, JSON.stringify(data))
39+
} catch (err) {
40+
console.warn('Failed to save cache:', err)
41+
}
3642
}

0 commit comments

Comments
 (0)