From a7f761319a6caf3023e1729581f3068092535bf8 Mon Sep 17 00:00:00 2001 From: Ilya Titov Date: Sat, 24 Jan 2026 09:03:08 +0000 Subject: [PATCH 1/3] Fix http/https feeds mismatch --- core/feed.ts | 2 +- core/popups/feed.ts | 24 +++++++++++++++++++++++- core/test/pages/add.test.ts | 5 +++-- core/test/popups/feed.test.ts | 31 +++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/core/feed.ts b/core/feed.ts index f97dd0b8..f65528e5 100644 --- a/core/feed.ts +++ b/core/feed.ts @@ -91,7 +91,7 @@ export async function addCandidate( loader: candidate.name, reading: 'slow', title: candidate.title, - url: candidate.url, + url: candidate.url.replace('https://', 'http://'), ...fields }) } diff --git a/core/popups/feed.ts b/core/popups/feed.ts index a25d433c..e40faf57 100644 --- a/core/popups/feed.ts +++ b/core/popups/feed.ts @@ -1,3 +1,4 @@ +import type { FilterStore } from '@logux/client' import { atom } from 'nanostores' import { getCategories } from '../category.ts' @@ -31,9 +32,30 @@ async function loadFeedFromURL( } } +function swapHttpProtocol(url: string): string { + let u = new URL(url) + u.protocol = u.protocol === 'https:' ? 'http:' : 'https:' + return u.toString() +} + +async function getFeedFilter(url: string): Promise> { + let exactFilter = getFeeds({ url }) + let feeds = await waitSyncLoading(exactFilter) + + if (feeds.get().list.length === 0) { + let fallbackFilter = getFeeds({ url: swapHttpProtocol(url) }) + feeds = await waitSyncLoading(fallbackFilter) + if (feeds.get().list.length > 0) { + return fallbackFilter + } + } + + return exactFilter +} + export const feed = definePopup('feed', async url => { let task = createDownloadTask({ cache: 'read' }) - let feedsFilter = getFeeds({ url }) + let feedsFilter = await getFeedFilter(url) let error: string | undefined let [responseOrError, categoriesFilter, feeds] = await Promise.all([ loadFeedFromURL(task, url), diff --git a/core/test/pages/add.test.ts b/core/test/pages/add.test.ts index ccd9cd66..72620b85 100644 --- a/core/test/pages/add.test.ts +++ b/core/test/pages/add.test.ts @@ -620,8 +620,6 @@ test('deduplicates feed links differing only by protocol', async () => { route: 'add' }) - keepMount(page.candidates) - expectRequest('http://example.com').andRespond( 200, ` @@ -642,6 +640,9 @@ test('deduplicates feed links differing only by protocol', async () => { page.params.url.set('http://example.com') await waitLoading(page.searching) + let popup = getPopup('feed') + await waitLoading(popup.loading) + equal(page.candidates.get().length, 1) equalWithText(page.candidates.get(), [ { diff --git a/core/test/popups/feed.test.ts b/core/test/popups/feed.test.ts index 725870e3..3b2c156e 100644 --- a/core/test/popups/feed.test.ts +++ b/core/test/popups/feed.test.ts @@ -188,3 +188,34 @@ test('has helpers to generate popup ID', () => { getPopupId('feed', 'http://example.com/') ) }) + +test('ignores url protocol while checking for existing feeds', async () => { + keepMount(openedPopups) + expectRequest('http://a.com/atom').andRespond( + 200, + 'Atom' + + '22023-07-01T00:00:00Z' + + '12023-06-01T00:00:00Z' + + '', + 'text/xml' + ) + let popup = openTestPopup('feed', 'http://a.com/atom') + await waitLoading(popup.loading) + + let addedId = await checkLoadedPopup(popup).add() + let feedId = checkLoadedPopup(popup).feed.get()!.id + equal(addedId, feedId) + equal((await loadValue(getFeed(feedId)))!.url, 'http://a.com/atom') + + expectRequest('https://a.com/atom').andRespond( + 200, + 'Atom' + + '22023-07-01T00:00:00Z' + + '12023-06-01T00:00:00Z' + + '', + 'text/xml' + ) + let popup2 = openTestPopup('feed', 'https://a.com/atom') + await waitLoading(popup2.loading) + equal(checkLoadedPopup(popup2).feed.get()!.url, 'http://a.com/atom') +}) From 68334992cd0da8332516b645d2be197aa90ab838 Mon Sep 17 00:00:00 2001 From: Ilya Titov Date: Sat, 24 Jan 2026 09:08:07 +0000 Subject: [PATCH 2/3] Remove unnecessary url mutation --- core/feed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/feed.ts b/core/feed.ts index f65528e5..f97dd0b8 100644 --- a/core/feed.ts +++ b/core/feed.ts @@ -91,7 +91,7 @@ export async function addCandidate( loader: candidate.name, reading: 'slow', title: candidate.title, - url: candidate.url.replace('https://', 'http://'), + url: candidate.url, ...fields }) } From a8142ba64fda02ad21196761c3b7fd8ee3a30473 Mon Sep 17 00:00:00 2001 From: Ilya Titov Date: Sat, 24 Jan 2026 09:12:54 +0000 Subject: [PATCH 3/3] Rename getFeedFilter to getFeedsFilter for consistency --- core/popups/feed.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/popups/feed.ts b/core/popups/feed.ts index e40faf57..7415c497 100644 --- a/core/popups/feed.ts +++ b/core/popups/feed.ts @@ -38,7 +38,7 @@ function swapHttpProtocol(url: string): string { return u.toString() } -async function getFeedFilter(url: string): Promise> { +async function getFeedsFilter(url: string): Promise> { let exactFilter = getFeeds({ url }) let feeds = await waitSyncLoading(exactFilter) @@ -55,7 +55,7 @@ async function getFeedFilter(url: string): Promise> { export const feed = definePopup('feed', async url => { let task = createDownloadTask({ cache: 'read' }) - let feedsFilter = await getFeedFilter(url) + let feedsFilter = await getFeedsFilter(url) let error: string | undefined let [responseOrError, categoriesFilter, feeds] = await Promise.all([ loadFeedFromURL(task, url),