feedkeeper 0.28.2 → 0.28.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -644,6 +644,7 @@ resourcesRouter.get("/items/:id/image", imageLimiter, async (req, res) => {
|
|
|
644
644
|
res.status(503).json({ error: "image_busy" });
|
|
645
645
|
return;
|
|
646
646
|
}
|
|
647
|
+
console.error(`[image_proxy] Failed to fetch image for item ${req.params.id} (${src}):`, error instanceof Error ? error.message : error);
|
|
647
648
|
res.status(502).json({ error: "image_unavailable" });
|
|
648
649
|
}
|
|
649
650
|
});
|
|
@@ -11,7 +11,7 @@ const FEED_MIME_TYPES = [
|
|
|
11
11
|
"application/xml",
|
|
12
12
|
];
|
|
13
13
|
const MAX_PROBES = 15;
|
|
14
|
-
const COMMON_PATHS = ["/feed", "/rss.xml", "/atom.xml", "/feed.xml", "/index.xml", "/rss", "/rss.php?feed=RSS2.0", "/rss.php?feed=ATOM1.0"];
|
|
14
|
+
const COMMON_PATHS = ["/feed/", "/feed", "/rss.xml", "/atom.xml", "/feed.xml", "/index.xml", "/rss/", "/rss", "/rss.php?feed=RSS2.0", "/rss.php?feed=ATOM1.0"];
|
|
15
15
|
// Feed-looking URLs anywhere in a page, including JSON embedded in attributes.
|
|
16
16
|
const FEED_URL_IN_TEXT = /https?:\/\/[^\s"'<>\\]+?(?:\.rss|\.atom|\/feed\/?|\/(?:rss|atom|feed)\.xml)(?=["'\s<>\\]|$)/gi;
|
|
17
17
|
function sameUrl(a, b) {
|
|
@@ -28,18 +28,23 @@ function sameUrl(a, b) {
|
|
|
28
28
|
return normalize(a) === normalize(b);
|
|
29
29
|
}
|
|
30
30
|
async function parseFeedAt(url) {
|
|
31
|
-
const fetched = await fetchFeed(url);
|
|
32
|
-
const finalUrl = fetched.finalUrl || url;
|
|
33
31
|
try {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const fetched = await fetchFeed(url);
|
|
33
|
+
const finalUrl = fetched.finalUrl || url;
|
|
34
|
+
try {
|
|
35
|
+
const parsed = await rssParser.parseString(fetched.body);
|
|
36
|
+
if (parsed.items && (parsed.title || parsed.description || parsed.items.length > 0)) {
|
|
37
|
+
return { feed: { url: finalUrl, title: plainTitle(parsed.title) ?? null, type: "application/rss+xml" }, html: null, finalUrl };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Not a feed; the caller may look for feed links in the HTML instead.
|
|
37
42
|
}
|
|
43
|
+
return { feed: null, html: fetched.body, finalUrl };
|
|
38
44
|
}
|
|
39
45
|
catch {
|
|
40
|
-
|
|
46
|
+
return { feed: null, html: null, finalUrl: url };
|
|
41
47
|
}
|
|
42
|
-
return { feed: null, html: fetched.body, finalUrl };
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
45
50
|
* Keep only candidates that really are feeds. Sites sometimes announce their own
|
|
@@ -75,22 +80,29 @@ export async function discoverFeeds(inputUrl) {
|
|
|
75
80
|
const page = await parseFeedAt(targetUrl);
|
|
76
81
|
if (page.feed)
|
|
77
82
|
return [page.feed];
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
// 1b. If the URL did not end in a slash, try with a trailing slash (e.g. /feed -> /feed/)
|
|
84
|
+
if (!targetUrl.endsWith("/")) {
|
|
85
|
+
const slashCandidate = await parseFeedAt(targetUrl + "/");
|
|
86
|
+
if (slashCandidate.feed)
|
|
87
|
+
return [slashCandidate.feed];
|
|
88
|
+
}
|
|
80
89
|
// 2. Feeds announced or linked on the page.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
if (page.html) {
|
|
91
|
+
const fromPage = await keepRealFeeds(extractFeedsFromHtml(page.html, page.finalUrl), page.finalUrl);
|
|
92
|
+
if (fromPage.length > 0)
|
|
93
|
+
return fromPage;
|
|
94
|
+
}
|
|
84
95
|
// 3. Common feed paths; some lead to an overview page that lists the site's feeds.
|
|
96
|
+
const probeBase = page.finalUrl || targetUrl;
|
|
85
97
|
for (const path of COMMON_PATHS) {
|
|
86
98
|
try {
|
|
87
|
-
const candidateUrl = new URL(path,
|
|
99
|
+
const candidateUrl = new URL(path, probeBase).toString();
|
|
88
100
|
if (sameUrl(candidateUrl, targetUrl))
|
|
89
101
|
continue;
|
|
90
102
|
const candidate = await parseFeedAt(candidateUrl);
|
|
91
103
|
if (candidate.feed)
|
|
92
104
|
return [candidate.feed];
|
|
93
|
-
if (candidate.html && !sameUrl(candidate.finalUrl,
|
|
105
|
+
if (candidate.html && !sameUrl(candidate.finalUrl, probeBase)) {
|
|
94
106
|
const listed = await keepRealFeeds(extractFeedsFromHtml(candidate.html, candidate.finalUrl), candidate.finalUrl);
|
|
95
107
|
if (listed.length > 0)
|
|
96
108
|
return listed;
|
|
@@ -34,6 +34,31 @@ function cleanConsentDom(doc) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
function resolveLazyImages(doc) {
|
|
38
|
+
const images = doc.querySelectorAll("img");
|
|
39
|
+
for (const img of images) {
|
|
40
|
+
const lazySrc = img.getAttribute("data-lazy-src") ||
|
|
41
|
+
img.getAttribute("data-src") ||
|
|
42
|
+
img.getAttribute("data-original") ||
|
|
43
|
+
img.getAttribute("data-actualsrc");
|
|
44
|
+
const src = img.getAttribute("src");
|
|
45
|
+
if (lazySrc && (!src || src.startsWith("data:") || src.length < 10)) {
|
|
46
|
+
img.setAttribute("src", lazySrc);
|
|
47
|
+
}
|
|
48
|
+
const lazySrcset = img.getAttribute("data-lazy-srcset") || img.getAttribute("data-srcset");
|
|
49
|
+
const srcset = img.getAttribute("srcset");
|
|
50
|
+
if (lazySrcset && (!srcset || srcset.startsWith("data:"))) {
|
|
51
|
+
img.setAttribute("srcset", lazySrcset);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const sources = doc.querySelectorAll("source");
|
|
55
|
+
for (const source of sources) {
|
|
56
|
+
const lazySrcset = source.getAttribute("data-lazy-srcset") || source.getAttribute("data-srcset");
|
|
57
|
+
if (lazySrcset) {
|
|
58
|
+
source.setAttribute("srcset", lazySrcset);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
37
62
|
/**
|
|
38
63
|
* Checks if a given URL or extracted HTML/text is a cookie / consent wall rather than article content.
|
|
39
64
|
*/
|
|
@@ -183,6 +208,7 @@ async function extractArticleContent(rawUrl, fetchImpl, signal) {
|
|
|
183
208
|
try {
|
|
184
209
|
const paywall = /"isAccessibleForFree"\s*:\s*(?:false|"false")/i.test(fetched.html);
|
|
185
210
|
cleanConsentDom(dom.window.document);
|
|
211
|
+
resolveLazyImages(dom.window.document);
|
|
186
212
|
parsed = new Readability(dom.window.document, { charThreshold: 60 }).parse();
|
|
187
213
|
if (isConsentContent(fetched.url, parsed?.content ?? fetched.html, parsed?.title, parsed?.textContent)) {
|
|
188
214
|
return { status: "consent_wall" };
|
|
@@ -64,7 +64,10 @@ export async function subscribeToFeed(userId, inputUrl, label = null, folderId =
|
|
|
64
64
|
// (e.g. a homepage that announces itself as RSS); don't keep the subscription.
|
|
65
65
|
if (pollResult.error && !pollResult.deferred && !findFeedById(feed.id)?.last_success_at) {
|
|
66
66
|
unsubscribeRepo(userId, feed.id);
|
|
67
|
-
|
|
67
|
+
if (pollResult.error === "feed_invalid_or_unavailable") {
|
|
68
|
+
throw new NoFeedsFoundError();
|
|
69
|
+
}
|
|
70
|
+
throw new FeedError(pollResult.error);
|
|
68
71
|
}
|
|
69
72
|
const subscription = findSubscriptionForUser(userId, feed.id);
|
|
70
73
|
if (!subscription)
|