feedkeeper 0.42.3 → 0.42.5
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 +1 -1
- package/server/dist/db/migrations/0046_drop_avatar_hero_images.sql +5 -0
- package/server/dist/feeds/archive.js +1 -1
- package/server/dist/feeds/batchSubscribe.js +7 -5
- package/server/dist/feeds/extractorParser.js +2 -4
- package/server/dist/feeds/feedParser.js +70 -14
- package/server/dist/feeds/repository.js +3 -1
- package/server/package.json +1 -1
- package/web/dist/assets/{index-DX6YOuhF.js → index-D1WpLIOR.js} +7 -7
- package/web/dist/assets/index-DzTYkw0D.css +2 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-C4E4b1Mp.css +0 -2
package/package.json
CHANGED
|
@@ -199,7 +199,7 @@ async function drain() {
|
|
|
199
199
|
try {
|
|
200
200
|
while (queue.length > 0) {
|
|
201
201
|
const itemId = queue.shift();
|
|
202
|
-
await archiveItem(itemId).catch((error) => console.warn(
|
|
202
|
+
await archiveItem(itemId).catch((error) => console.warn("[archive] item %d:", Number(itemId), error));
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
finally {
|
|
@@ -26,10 +26,11 @@ async function checkAddress(raw) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
async function checkAll(items) {
|
|
29
|
-
const
|
|
29
|
+
const total = Math.min(items.length, MAX_SUBSCRIPTION_BATCH);
|
|
30
|
+
const checked = new Array(total);
|
|
30
31
|
let next = 0;
|
|
31
|
-
await Promise.all(Array.from({ length: Math.min(CHECK_CONCURRENCY,
|
|
32
|
-
while (next <
|
|
32
|
+
await Promise.all(Array.from({ length: Math.min(CHECK_CONCURRENCY, total) }, async () => {
|
|
33
|
+
while (next < total) {
|
|
33
34
|
const index = next++;
|
|
34
35
|
checked[index] = await checkAddress(items[index].url);
|
|
35
36
|
}
|
|
@@ -43,11 +44,12 @@ async function checkAll(items) {
|
|
|
43
44
|
* usual schedule. Sending the same list again changes nothing (`exists`).
|
|
44
45
|
*/
|
|
45
46
|
export async function subscribeBatch(userId, items) {
|
|
46
|
-
const
|
|
47
|
+
const bounded = items.slice(0, MAX_SUBSCRIPTION_BATCH);
|
|
48
|
+
const checked = await checkAll(bounded);
|
|
47
49
|
const created = [];
|
|
48
50
|
const results = db.transaction(() => {
|
|
49
51
|
const folders = new Map();
|
|
50
|
-
return
|
|
52
|
+
return bounded.map((item, index) => {
|
|
51
53
|
const check = checked[index];
|
|
52
54
|
if ("reason" in check)
|
|
53
55
|
return { url: item.url, status: "invalid", reason: check.reason };
|
|
@@ -116,21 +116,19 @@ function paywallNotice(pageUrl) {
|
|
|
116
116
|
export function parseArticleHtml(html, url) {
|
|
117
117
|
const dom = new JSDOM(html, { url });
|
|
118
118
|
let parsed;
|
|
119
|
-
|
|
119
|
+
const paywalled = /"isAccessibleForFree"\s*:\s*(?:false|"false")/i.test(html);
|
|
120
120
|
try {
|
|
121
121
|
// The content rules run first: players and consent plugins keep the address of an embed in the very tags removed next.
|
|
122
122
|
cleanPage(dom.window.document);
|
|
123
123
|
dom.window.document.querySelectorAll("script, style, svg, iframe, noscript").forEach(element => element.remove());
|
|
124
|
-
const paywall = /"isAccessibleForFree"\s*:\s*(?:false|"false")/i.test(html);
|
|
125
124
|
cleanConsentDom(dom.window.document);
|
|
126
125
|
resolveLazyImages(dom.window.document);
|
|
127
126
|
parsed = new Readability(dom.window.document, { charThreshold: 60 }).parse();
|
|
128
|
-
paywalled = paywall;
|
|
129
127
|
if (isConsentContent(url, parsed?.content ?? html, parsed?.title, parsed?.textContent)) {
|
|
130
128
|
return { status: "consent_wall" };
|
|
131
129
|
}
|
|
132
130
|
// Publishers flag a whole article as not free although the page carries its text; enough of it is the article.
|
|
133
|
-
if ((
|
|
131
|
+
if ((paywalled && (parsed?.textContent?.length ?? 0) < PAYWALL_TEXT_MIN) ||
|
|
134
132
|
((parsed?.textContent?.length ?? 0) < PAYWALL_TEXT_MIN &&
|
|
135
133
|
/(?:subscribe to (?:continue|read)|sign in to (?:continue|read)|abonnieren und weiterlesen|nur für abonnenten|jetzt abonnieren.{0,40}weiterlesen)/i.test(parsed?.textContent ?? ""))) {
|
|
136
134
|
return { status: "paywall" };
|
|
@@ -19,6 +19,7 @@ function isRecord(value) {
|
|
|
19
19
|
function asNonEmptyString(value) {
|
|
20
20
|
return typeof value === "string" && value.trim() !== "" ? value : undefined;
|
|
21
21
|
}
|
|
22
|
+
const MIN_FEED_IMAGE_SIDE = 100;
|
|
22
23
|
function mediaAttribute(value, key) {
|
|
23
24
|
if (!isRecord(value))
|
|
24
25
|
return undefined;
|
|
@@ -26,9 +27,37 @@ function mediaAttribute(value, key) {
|
|
|
26
27
|
return value.$[key];
|
|
27
28
|
return value[key];
|
|
28
29
|
}
|
|
30
|
+
function asMediaEntries(value) {
|
|
31
|
+
return Array.isArray(value) ? value : [value];
|
|
32
|
+
}
|
|
33
|
+
function parseDimension(value) {
|
|
34
|
+
if (typeof value === "number")
|
|
35
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
36
|
+
if (typeof value !== "string")
|
|
37
|
+
return null;
|
|
38
|
+
const match = /^\s*(\d+(?:\.\d+)?)\s*(?:px)?\s*$/i.exec(value);
|
|
39
|
+
if (!match)
|
|
40
|
+
return null;
|
|
41
|
+
const parsed = Number(match[1]);
|
|
42
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
43
|
+
}
|
|
44
|
+
function isTooSmallMedia(widthRaw, heightRaw) {
|
|
45
|
+
const width = parseDimension(widthRaw);
|
|
46
|
+
const height = parseDimension(heightRaw);
|
|
47
|
+
return (width !== null && width < MIN_FEED_IMAGE_SIDE) || (height !== null && height < MIN_FEED_IMAGE_SIDE);
|
|
48
|
+
}
|
|
29
49
|
function cleanImageUrl(url) {
|
|
30
50
|
return url.trim().replace(/&(?:#038|amp);/g, "&");
|
|
31
51
|
}
|
|
52
|
+
export function isAvatarImageUrl(url) {
|
|
53
|
+
try {
|
|
54
|
+
const host = new URL(url.trim()).hostname.toLowerCase();
|
|
55
|
+
return host === "avatars.githubusercontent.com" || host.endsWith(".avatars.githubusercontent.com");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
32
61
|
function isValidImageUrl(url) {
|
|
33
62
|
if (typeof url !== "string")
|
|
34
63
|
return false;
|
|
@@ -44,39 +73,66 @@ function isValidImageUrl(url) {
|
|
|
44
73
|
const host = parsed.hostname.toLowerCase();
|
|
45
74
|
if (host === "pixel.wp.com" || host.endsWith(".pixel.wp.com"))
|
|
46
75
|
return false;
|
|
76
|
+
if (isAvatarImageUrl(url))
|
|
77
|
+
return false;
|
|
47
78
|
const pathAndQuery = (parsed.pathname + parsed.search).toLowerCase();
|
|
48
79
|
if (pathAndQuery.includes("/1x1") || pathAndQuery.includes("pixel") || pathAndQuery.includes("tracking") || pathAndQuery.includes("beacon")) {
|
|
49
80
|
return false;
|
|
50
81
|
}
|
|
51
82
|
return true;
|
|
52
83
|
}
|
|
84
|
+
function htmlAttribute(tag, name) {
|
|
85
|
+
const match = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i").exec(tag);
|
|
86
|
+
return match ? (match[1] ?? match[2] ?? match[3]) : undefined;
|
|
87
|
+
}
|
|
53
88
|
function firstHtmlImageUrl(html) {
|
|
54
89
|
if (typeof html !== "string" || !html.includes("<img"))
|
|
55
90
|
return null;
|
|
56
|
-
const
|
|
57
|
-
|
|
91
|
+
for (const [tag] of html.matchAll(/<img\b[^>]*>/gi)) {
|
|
92
|
+
const src = htmlAttribute(tag, "src");
|
|
93
|
+
if (!src)
|
|
94
|
+
continue;
|
|
95
|
+
const decodedSrc = decodeEntities(src);
|
|
96
|
+
if (!isValidImageUrl(decodedSrc))
|
|
97
|
+
continue;
|
|
98
|
+
if (isTooSmallMedia(htmlAttribute(tag, "width"), htmlAttribute(tag, "height")))
|
|
99
|
+
continue;
|
|
100
|
+
const classes = htmlAttribute(tag, "class") ?? "";
|
|
101
|
+
if (/\b(?:avatar|emoji|icon)\b/i.test(classes))
|
|
102
|
+
continue;
|
|
103
|
+
return cleanImageUrl(decodedSrc);
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
58
106
|
}
|
|
59
107
|
function extractXmlImageUrl(item) {
|
|
60
108
|
// 1. media:content (Media RSS)
|
|
61
109
|
const mediaContent = item.mediaContent ?? item["media:content"];
|
|
62
110
|
if (mediaContent) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
111
|
+
for (const entry of asMediaEntries(mediaContent)) {
|
|
112
|
+
if (isValidImageUrl(entry))
|
|
113
|
+
return cleanImageUrl(entry);
|
|
114
|
+
if (isTooSmallMedia(mediaAttribute(entry, "width"), mediaAttribute(entry, "height")))
|
|
115
|
+
continue;
|
|
116
|
+
const url = mediaAttribute(entry, "url");
|
|
117
|
+
const medium = mediaAttribute(entry, "medium");
|
|
118
|
+
const type = mediaAttribute(entry, "type");
|
|
119
|
+
if (isValidImageUrl(url) && (medium === "image" || !medium || (typeof type === "string" && type.startsWith("image/")))) {
|
|
120
|
+
return cleanImageUrl(url);
|
|
121
|
+
}
|
|
70
122
|
}
|
|
71
123
|
}
|
|
72
124
|
// 2. media:thumbnail
|
|
73
125
|
const mediaThumbnail = item.mediaThumbnail ?? item["media:thumbnail"];
|
|
74
126
|
if (mediaThumbnail) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
127
|
+
for (const entry of asMediaEntries(mediaThumbnail)) {
|
|
128
|
+
if (isValidImageUrl(entry))
|
|
129
|
+
return cleanImageUrl(entry);
|
|
130
|
+
if (isTooSmallMedia(mediaAttribute(entry, "width"), mediaAttribute(entry, "height")))
|
|
131
|
+
continue;
|
|
132
|
+
const url = mediaAttribute(entry, "url");
|
|
133
|
+
if (isValidImageUrl(url))
|
|
134
|
+
return cleanImageUrl(url);
|
|
135
|
+
}
|
|
80
136
|
}
|
|
81
137
|
// 3. enclosure
|
|
82
138
|
if (item.enclosure?.url) {
|
|
@@ -2,6 +2,7 @@ import { config } from "../config.js";
|
|
|
2
2
|
import { db } from "../db/index.js";
|
|
3
3
|
import { articleText } from "./articleContent.js";
|
|
4
4
|
import { LEAD_VERSION } from "./contentNoise.js";
|
|
5
|
+
import { isAvatarImageUrl } from "./feedParser.js";
|
|
5
6
|
import { largerHeroImage } from "./heroImage.js";
|
|
6
7
|
import { refreshGalleryClassification, refreshLead } from "./lead.js";
|
|
7
8
|
import { decodeEntities, plainTitle } from "./text.js";
|
|
@@ -206,7 +207,8 @@ export function upsertItems(feedId, items) {
|
|
|
206
207
|
// a feed that alternates between two variants would change the content on every poll.
|
|
207
208
|
const keptPrevious = retained !== null && next !== retained;
|
|
208
209
|
const nextSnippet = keptPrevious ? null : row.contentSnippet ?? null;
|
|
209
|
-
const
|
|
210
|
+
const reusablePreviousImage = previous?.image_url && !isAvatarImageUrl(previous.image_url) ? previous.image_url : null;
|
|
211
|
+
const nextImage = largerHeroImage(row.imageUrl, retained, row.link ?? previous?.link ?? null) ?? reusablePreviousImage ?? row.imageUrl ?? null;
|
|
210
212
|
if (previous) {
|
|
211
213
|
const changed = (row.title !== undefined && row.title !== previous.title) ||
|
|
212
214
|
(row.link !== undefined && row.link !== previous.link) ||
|