feedkeeper 0.47.0 → 0.47.2
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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Notify subscribers when feed media metadata (description, artwork_url, detected_kind) changes
|
|
2
|
+
DROP TRIGGER IF EXISTS trg_changes_feed_update;
|
|
3
|
+
CREATE TRIGGER trg_changes_feed_update
|
|
4
|
+
AFTER UPDATE OF url, title, site_url, poll_interval_minutes, last_error, description, artwork_url, detected_kind ON feeds
|
|
5
|
+
WHEN OLD.url IS NOT NEW.url
|
|
6
|
+
OR OLD.title IS NOT NEW.title
|
|
7
|
+
OR OLD.site_url IS NOT NEW.site_url
|
|
8
|
+
OR OLD.poll_interval_minutes IS NOT NEW.poll_interval_minutes
|
|
9
|
+
OR OLD.last_error IS NOT NEW.last_error
|
|
10
|
+
OR OLD.description IS NOT NEW.description
|
|
11
|
+
OR OLD.artwork_url IS NOT NEW.artwork_url
|
|
12
|
+
OR OLD.detected_kind IS NOT NEW.detected_kind
|
|
13
|
+
BEGIN
|
|
14
|
+
INSERT INTO changes (user_id, entity, entity_id, op, seq, changed_at)
|
|
15
|
+
SELECT s.user_id, 'subscription', NEW.id, 'upsert', (SELECT COALESCE(MAX(seq), 0) + 1 FROM changes WHERE user_id = s.user_id), strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
16
|
+
FROM subscriptions s
|
|
17
|
+
WHERE s.feed_id = NEW.id
|
|
18
|
+
ON CONFLICT (user_id, entity, entity_id) DO UPDATE SET op = excluded.op, seq = excluded.seq, changed_at = excluded.changed_at;
|
|
19
|
+
END;
|
|
20
|
+
|
|
21
|
+
-- Enqueue a sync upsert for subscriptions whose feed already received artwork_url or description before this trigger existed
|
|
22
|
+
INSERT INTO changes (user_id, entity, entity_id, op, seq, changed_at)
|
|
23
|
+
SELECT
|
|
24
|
+
s.user_id,
|
|
25
|
+
'subscription',
|
|
26
|
+
f.id,
|
|
27
|
+
'upsert',
|
|
28
|
+
(SELECT COALESCE(MAX(seq), 0) + 1 FROM changes WHERE user_id = s.user_id),
|
|
29
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
30
|
+
FROM subscriptions s
|
|
31
|
+
JOIN feeds f ON f.id = s.feed_id
|
|
32
|
+
WHERE f.artwork_url IS NOT NULL OR f.description IS NOT NULL
|
|
33
|
+
ON CONFLICT (user_id, entity, entity_id) DO UPDATE SET op = excluded.op, seq = excluded.seq, changed_at = excluded.changed_at;
|
|
@@ -234,7 +234,12 @@ function extractMediaImageUrl(source) {
|
|
|
234
234
|
const url = mediaAttribute(entry, "url");
|
|
235
235
|
const medium = mediaAttribute(entry, "medium");
|
|
236
236
|
const type = mediaAttribute(entry, "type");
|
|
237
|
-
|
|
237
|
+
const isImageType = typeof type === "string" && type.toLowerCase().startsWith("image/");
|
|
238
|
+
const isNonImageType = typeof type === "string" && type.trim() !== "" && !isImageType;
|
|
239
|
+
const isNonImageMedium = typeof medium === "string" && medium.trim() !== "" && medium.toLowerCase() !== "image";
|
|
240
|
+
if (isNonImageType || isNonImageMedium)
|
|
241
|
+
continue;
|
|
242
|
+
if (isValidImageUrl(url) && (medium === "image" || !medium || isImageType)) {
|
|
238
243
|
return cleanImageUrl(url);
|
|
239
244
|
}
|
|
240
245
|
}
|
|
@@ -423,6 +428,34 @@ function extractXmlArtworkUrl(parsed) {
|
|
|
423
428
|
return parsed.icon.trim();
|
|
424
429
|
return undefined;
|
|
425
430
|
}
|
|
431
|
+
function extractXmlMediaDescription(item) {
|
|
432
|
+
const direct = asNonEmptyString(item["media:description"]);
|
|
433
|
+
if (direct)
|
|
434
|
+
return direct;
|
|
435
|
+
const mediaGroup = item.mediaGroup ?? item["media:group"];
|
|
436
|
+
if (mediaGroup) {
|
|
437
|
+
for (const group of asMediaEntries(mediaGroup)) {
|
|
438
|
+
if (!isRecord(group))
|
|
439
|
+
continue;
|
|
440
|
+
const grouped = asNonEmptyString(group["media:description"] ?? group.mediaDescription);
|
|
441
|
+
if (grouped)
|
|
442
|
+
return grouped;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
function escapePlainDescriptionHtml(text) {
|
|
448
|
+
const escaped = text
|
|
449
|
+
.replace(/&/g, "&")
|
|
450
|
+
.replace(/</g, "<")
|
|
451
|
+
.replace(/>/g, ">")
|
|
452
|
+
.replace(/"/g, """);
|
|
453
|
+
return escaped
|
|
454
|
+
.split(/\n{2,}/)
|
|
455
|
+
.map((block) => `<p>${block.trim().replace(/\n/g, "<br>")}</p>`)
|
|
456
|
+
.filter((block) => block !== "<p></p>")
|
|
457
|
+
.join("");
|
|
458
|
+
}
|
|
426
459
|
export async function parseFeedBody(body) {
|
|
427
460
|
if (body.trimStart().startsWith("{")) {
|
|
428
461
|
return parseJsonFeed(body);
|
|
@@ -445,17 +478,22 @@ export async function parseFeedBody(body) {
|
|
|
445
478
|
icons,
|
|
446
479
|
logos,
|
|
447
480
|
artworkUrl,
|
|
448
|
-
items: parsed.items.map((item) =>
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
481
|
+
items: parsed.items.map((item) => {
|
|
482
|
+
const mediaDescription = extractXmlMediaDescription(item);
|
|
483
|
+
const rawSnippet = item.contentSnippet ?? item.content ?? mediaDescription;
|
|
484
|
+
const rawHtml = item.contentEncoded ?? item["content:encoded"] ?? item.content ?? null;
|
|
485
|
+
return {
|
|
486
|
+
guid: itemGuid(item),
|
|
487
|
+
title: plainTitle(item.title),
|
|
488
|
+
link: itemLink(item),
|
|
489
|
+
contentSnippet: decodeEntities(rawSnippet) ?? undefined,
|
|
490
|
+
contentHtml: rawHtml ?? (mediaDescription ? escapePlainDescriptionHtml(mediaDescription) : null),
|
|
491
|
+
publishedAt: normalizePublishedAt(item.isoDate ?? item.pubDate) ?? undefined,
|
|
492
|
+
imageUrl: extractXmlImageUrl(item),
|
|
493
|
+
authors: [item.creator, item.author],
|
|
494
|
+
...extractXmlMedia(item),
|
|
495
|
+
};
|
|
496
|
+
}),
|
|
459
497
|
};
|
|
460
498
|
}
|
|
461
499
|
function isYouTubeUrl(rawUrl) {
|
|
@@ -110,11 +110,13 @@ async function trySuggestReplacementForGoneFeed(feed) {
|
|
|
110
110
|
}
|
|
111
111
|
/** One attempt; the queue owns retries, admission, single-flight and the total deadline. */
|
|
112
112
|
async function pollAttempt(feed, signal, interactive) {
|
|
113
|
+
// Backfill show artwork and description once for feeds created before 0.47.0 even if the server returns 304 for cached validators.
|
|
114
|
+
const needsShowBackfill = !feed.artwork_url && !feed.description;
|
|
113
115
|
let fetched;
|
|
114
116
|
try {
|
|
115
117
|
fetched = await fetchFeed(feed.url, {
|
|
116
|
-
etag: feed.etag ?? undefined,
|
|
117
|
-
lastModified: feed.last_modified ?? undefined,
|
|
118
|
+
etag: needsShowBackfill ? undefined : feed.etag ?? undefined,
|
|
119
|
+
lastModified: needsShowBackfill ? undefined : feed.last_modified ?? undefined,
|
|
118
120
|
signal,
|
|
119
121
|
priority: interactive ? "interactive" : "background",
|
|
120
122
|
});
|