feedkeeper 0.46.1 → 0.47.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feedkeeper",
3
- "version": "0.46.1",
3
+ "version": "0.47.1",
4
4
  "description": "A lightweight, self-hosted RSS reader and remote MCP server for your news, blogs, and AI workflows.",
5
5
  "keywords": [
6
6
  "rss",
@@ -138,6 +138,7 @@ const updateSchema = z.object({
138
138
  folderId: z.number().int().positive().nullable().optional(),
139
139
  pollIntervalMinutes: z.number().int().positive().max(10080).optional(),
140
140
  fullTextMode: z.enum(["auto", "never"]).optional(),
141
+ kindOverride: z.enum(["article", "audio", "video"]).nullable().optional(),
141
142
  notify: z.boolean().optional(),
142
143
  badge: z.boolean().optional(),
143
144
  });
@@ -117,6 +117,7 @@ const updateSchema = z.object({
117
117
  folderId: z.number().int().positive().nullable().optional(),
118
118
  pollIntervalMinutes: z.number().int().positive().max(10080).optional(),
119
119
  fullTextMode: z.enum(["auto", "never"]).optional(),
120
+ kindOverride: z.enum(["article", "audio", "video"]).nullable().optional(),
120
121
  notify: z.boolean().optional(),
121
122
  badge: z.boolean().optional(),
122
123
  });
@@ -0,0 +1,5 @@
1
+ ALTER TABLE feeds ADD COLUMN description TEXT;
2
+ ALTER TABLE feeds ADD COLUMN artwork_url TEXT;
3
+ ALTER TABLE feeds ADD COLUMN detected_kind TEXT NOT NULL DEFAULT 'article';
4
+
5
+ ALTER TABLE subscriptions ADD COLUMN kind_override TEXT;
@@ -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;
@@ -5,13 +5,14 @@ import { unwrapRedirectLink } from "./redirectLinks.js";
5
5
  import { decodeEntities, plainTitle } from "./text.js";
6
6
  const xmlParser = new Parser({
7
7
  customFields: {
8
- feed: ["icon"],
8
+ feed: ["icon", "itunes:image"],
9
9
  item: [
10
10
  ["media:content", "mediaContent", { keepArray: false }],
11
11
  ["media:thumbnail", "mediaThumbnail", { keepArray: false }],
12
12
  ["media:group", "mediaGroup", { keepArray: false }],
13
13
  ["content:encoded", "contentEncoded", { keepArray: false }],
14
14
  ["itunes:duration", "itunesDuration", { keepArray: false }],
15
+ ["itunes:image", "itunesImage", { keepArray: false }],
15
16
  ["podcast:chapters", "podcastChapters", { keepArray: false }],
16
17
  ],
17
18
  },
@@ -267,7 +268,17 @@ function extractXmlImageUrl(item) {
267
268
  return grouped;
268
269
  }
269
270
  }
270
- // 3. enclosure
271
+ // 3. itunes:image on episode level
272
+ const itunesImage = item.itunesImage ?? item["itunes:image"];
273
+ const itunesHref = isRecord(itunesImage)
274
+ ? asNonEmptyString(isRecord(itunesImage.$) ? itunesImage.$.href : itunesImage.href)
275
+ : asNonEmptyString(itunesImage);
276
+ if (isValidImageUrl(itunesHref))
277
+ return cleanImageUrl(itunesHref);
278
+ if (isRecord(item.itunes) && isValidImageUrl(item.itunes.image)) {
279
+ return cleanImageUrl(item.itunes.image);
280
+ }
281
+ // 4. enclosure
271
282
  if (item.enclosure?.url) {
272
283
  const url = item.enclosure.url;
273
284
  const type = item.enclosure.type ?? "";
@@ -392,9 +403,26 @@ function parseJsonFeed(body) {
392
403
  link: asNonEmptyString(raw.home_page_url),
393
404
  icons,
394
405
  logos,
406
+ artworkUrl: logos[0] ?? icons[0],
395
407
  items,
396
408
  };
397
409
  }
410
+ function extractXmlArtworkUrl(parsed) {
411
+ const itunesImage = parsed["itunes:image"] ?? parsed.itunesImage;
412
+ const href = isRecord(itunesImage)
413
+ ? asNonEmptyString(isRecord(itunesImage.$) ? itunesImage.$.href : itunesImage.href)
414
+ : asNonEmptyString(itunesImage);
415
+ if (href && isValidImageUrl(href))
416
+ return href;
417
+ if (isRecord(parsed.itunes) && typeof parsed.itunes.image === "string" && isValidImageUrl(parsed.itunes.image)) {
418
+ return parsed.itunes.image.trim();
419
+ }
420
+ if (typeof parsed.image?.url === "string" && isValidImageUrl(parsed.image.url))
421
+ return parsed.image.url.trim();
422
+ if (typeof parsed.icon === "string" && isValidImageUrl(parsed.icon))
423
+ return parsed.icon.trim();
424
+ return undefined;
425
+ }
398
426
  export async function parseFeedBody(body) {
399
427
  if (body.trimStart().startsWith("{")) {
400
428
  return parseJsonFeed(body);
@@ -406,13 +434,17 @@ export async function parseFeedBody(body) {
406
434
  icons.push(parsed.icon.trim());
407
435
  if (typeof parsed.image?.url === "string" && parsed.image.url.trim())
408
436
  logos.push(parsed.image.url.trim());
437
+ const artworkUrl = extractXmlArtworkUrl(parsed);
438
+ if (artworkUrl && !logos.includes(artworkUrl))
439
+ logos.unshift(artworkUrl);
409
440
  return {
410
441
  mimeType: "application/rss+xml",
411
442
  title: plainTitle(parsed.title),
412
- description: asNonEmptyString(parsed.description),
443
+ description: decodeEntities(asNonEmptyString(parsed.description)) ?? undefined,
413
444
  link: asNonEmptyString(parsed.link),
414
445
  icons,
415
446
  logos,
447
+ artworkUrl,
416
448
  items: parsed.items.map((item) => ({
417
449
  guid: itemGuid(item),
418
450
  title: plainTitle(item.title),
@@ -426,6 +458,40 @@ export async function parseFeedBody(body) {
426
458
  })),
427
459
  };
428
460
  }
461
+ function isYouTubeUrl(rawUrl) {
462
+ if (!rawUrl)
463
+ return false;
464
+ try {
465
+ const host = new URL(rawUrl).hostname.toLowerCase();
466
+ return host === "youtube.com" || host.endsWith(".youtube.com") || host === "youtu.be";
467
+ }
468
+ catch {
469
+ return false;
470
+ }
471
+ }
472
+ /** Classifies a feed as `audio`, `video`, or `article` from its URL and recent items. */
473
+ export function detectFeedKind(feedUrl, items) {
474
+ if (isYouTubeUrl(feedUrl))
475
+ return "video";
476
+ const sample = items.slice(0, 20);
477
+ if (sample.length === 0)
478
+ return "article";
479
+ let audioCount = 0;
480
+ let videoCount = 0;
481
+ for (const item of sample) {
482
+ if (item.enclosureType?.toLowerCase().startsWith("video/") || isYouTubeUrl(item.link)) {
483
+ videoCount++;
484
+ }
485
+ else if (item.enclosureUrl) {
486
+ audioCount++;
487
+ }
488
+ }
489
+ if (videoCount > 0 && videoCount >= audioCount && videoCount * 2 >= sample.length)
490
+ return "video";
491
+ if (audioCount > 0 && audioCount * 2 >= sample.length)
492
+ return "audio";
493
+ return "article";
494
+ }
429
495
  export function formatFeedAuthor(authors, feedTitle, feedUrl) {
430
496
  return authorLine(authors, { title: feedTitle, url: feedUrl });
431
497
  }
@@ -10,25 +10,68 @@ import { db } from "../db/index.js";
10
10
  import { configurePollHostCooldowns, PollQueue } from "./pollQueue.js";
11
11
  import { feedRequests, PollDeferredError, sourceHost } from "./requestGate.js";
12
12
  import { readPollSettings } from "./pollSettings.js";
13
- import { formatFeedAuthor, itemGuid, itemLink, parseFeedBody, resolveFeedIconUrls } from "./feedParser.js";
13
+ import { detectFeedKind, formatFeedAuthor, itemGuid, itemLink, parseFeedBody, resolveFeedIconUrls } from "./feedParser.js";
14
+ import { decodeEntities } from "./text.js";
14
15
  export { itemGuid, itemLink };
15
16
  configurePollHostCooldowns();
17
+ function isYouTubeChannelUrl(rawUrl) {
18
+ if (!rawUrl)
19
+ return false;
20
+ try {
21
+ const host = new URL(rawUrl).hostname.toLowerCase();
22
+ return host === "youtube.com" || host.endsWith(".youtube.com");
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
28
+ function extractHtmlMeta(html, nameOrProp) {
29
+ const metaTags = html.match(/<meta\b[^>]{1,600}>/gi) ?? [];
30
+ const target = nameOrProp.toLowerCase();
31
+ for (const tag of metaTags) {
32
+ const propMatch = /\b(?:property|name)\s*=\s*["']([^"']+)["']/i.exec(tag);
33
+ if (!propMatch || propMatch[1]?.toLowerCase() !== target)
34
+ continue;
35
+ const contentMatch = /\bcontent\s*=\s*["']([^"']*)["']/i.exec(tag);
36
+ if (contentMatch?.[1])
37
+ return decodeEntities(contentMatch[1]) ?? undefined;
38
+ }
39
+ return undefined;
40
+ }
41
+ async function refreshYouTubeShowMetadata(feedId, siteUrl, signal) {
42
+ const fetched = await fetchFeed(siteUrl, { signal, priority: "background" });
43
+ if (fetched.notModified || !fetched.body)
44
+ return;
45
+ const artworkUrl = extractHtmlMeta(fetched.body, "og:image");
46
+ const description = extractHtmlMeta(fetched.body, "og:description") ?? extractHtmlMeta(fetched.body, "description");
47
+ if (!artworkUrl && !description)
48
+ return;
49
+ db.prepare("UPDATE feeds SET artwork_url = COALESCE(?, artwork_url), description = COALESCE(?, description) WHERE id = ?").run(artworkUrl ?? null, description ?? null, feedId);
50
+ }
16
51
  /**
17
52
  * Checks the feed's icon when it is due. The check starts right away but is not awaited, has its own deadline, and cannot retry or
18
53
  * fail a committed feed; downloads join the shared request limit as background work.
19
54
  */
20
55
  function scheduleIconMaintenance(feed, parsed) {
21
- if (!iconCheckDue(feed.icon_checked_at))
56
+ const siteUrl = parsed?.link || feed.site_url;
57
+ const needsYouTubeShowMeta = isYouTubeChannelUrl(siteUrl) && (!feed.artwork_url || !feed.description);
58
+ const iconDue = iconCheckDue(feed.icon_checked_at);
59
+ if (!iconDue && !needsYouTubeShowMeta)
22
60
  return;
23
- updateFeedIcon(feed.id, feed.icon_url);
61
+ if (iconDue)
62
+ updateFeedIcon(feed.id, feed.icon_url);
24
63
  const signal = AbortSignal.timeout(readPollSettings().attemptTimeoutMs);
25
64
  const task = (async () => {
26
65
  try {
27
- const siteUrl = parsed?.link || feed.site_url;
28
- const htmlUrls = siteUrl ? await discoverIconUrls(siteUrl, signal) : [];
29
- const feedUrls = parsed ? resolveFeedIconUrls(parsed, siteUrl || feed.url) : { icons: [], logos: [] };
30
- signal.throwIfAborted();
31
- await refreshFeedIcon(feed.id, siteUrl, [...htmlUrls, ...feedUrls.icons], signal, feedUrls.logos);
66
+ if (needsYouTubeShowMeta && siteUrl) {
67
+ await refreshYouTubeShowMetadata(feed.id, siteUrl, signal).catch(() => { });
68
+ }
69
+ if (iconDue) {
70
+ const htmlUrls = siteUrl ? await discoverIconUrls(siteUrl, signal) : [];
71
+ const feedUrls = parsed ? resolveFeedIconUrls(parsed, siteUrl || feed.url) : { icons: [], logos: [] };
72
+ signal.throwIfAborted();
73
+ await refreshFeedIcon(feed.id, siteUrl, [...htmlUrls, ...feedUrls.icons], signal, feedUrls.logos);
74
+ }
32
75
  }
33
76
  catch { /* Keep the successful poll; icon failures are best effort. */ }
34
77
  })();
@@ -67,11 +110,13 @@ async function trySuggestReplacementForGoneFeed(feed) {
67
110
  }
68
111
  /** One attempt; the queue owns retries, admission, single-flight and the total deadline. */
69
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;
70
115
  let fetched;
71
116
  try {
72
117
  fetched = await fetchFeed(feed.url, {
73
- etag: feed.etag ?? undefined,
74
- lastModified: feed.last_modified ?? undefined,
118
+ etag: needsShowBackfill ? undefined : feed.etag ?? undefined,
119
+ lastModified: needsShowBackfill ? undefined : feed.last_modified ?? undefined,
75
120
  signal,
76
121
  priority: interactive ? "interactive" : "background",
77
122
  });
@@ -121,8 +166,17 @@ async function pollAttempt(feed, signal, interactive) {
121
166
  }
122
167
  }
123
168
  const count = items ? upsertItems(feed.id, items) : 0;
169
+ const detectedKind = parsed ? detectFeedKind(effectiveFeed.url, parsed.items) : undefined;
124
170
  updateFeedAfterPoll(feed.id, {
125
- ...(parsed ? { title: parsed.title, siteUrl: parsed.link, etag: fetched.etag, lastModified: fetched.lastModified } : {}),
171
+ ...(parsed ? {
172
+ title: parsed.title,
173
+ siteUrl: parsed.link,
174
+ description: parsed.description,
175
+ artworkUrl: parsed.artworkUrl,
176
+ detectedKind,
177
+ etag: fetched.etag,
178
+ lastModified: fetched.lastModified,
179
+ } : {}),
126
180
  error: null,
127
181
  });
128
182
  if (count > 0 && feed.last_success_at)
@@ -98,6 +98,7 @@ export function listSubscriptionsForUser(userId) {
98
98
  s.full_text_mode AS full_text_mode,
99
99
  s.notify AS notify,
100
100
  s.badge AS badge,
101
+ s.kind_override AS kind_override,
101
102
  COALESCE(s.poll_interval_minutes, f.poll_interval_minutes) AS poll_interval_minutes,
102
103
  (
103
104
  SELECT COUNT(*) FROM items i
@@ -145,13 +146,16 @@ export function updateFeedAfterPoll(feedId, data) {
145
146
  db.prepare(`UPDATE feeds SET
146
147
  title = COALESCE(?, title),
147
148
  site_url = COALESCE(?, site_url),
149
+ description = COALESCE(?, description),
150
+ artwork_url = COALESCE(?, artwork_url),
151
+ detected_kind = COALESCE(?, detected_kind),
148
152
  etag = COALESCE(?, etag),
149
153
  last_modified = COALESCE(?, last_modified),
150
154
  last_error = NULL,
151
155
  consecutive_errors = 0,
152
156
  last_success_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
153
157
  last_polled_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
154
- WHERE id = ?`).run(data.title ?? null, data.siteUrl ?? null, data.etag ?? null, data.lastModified ?? null, feedId);
158
+ WHERE id = ?`).run(data.title ?? null, data.siteUrl ?? null, data.description ?? null, data.artworkUrl ?? null, data.detectedKind ?? null, data.etag ?? null, data.lastModified ?? null, feedId);
155
159
  }
156
160
  }
157
161
  /** A tombstone records that its feed still lists the article; once a day is enough for its 90-day expiry. */
@@ -404,6 +408,7 @@ export function findSubscriptionForUser(userId, feedId) {
404
408
  s.full_text_mode AS full_text_mode,
405
409
  s.notify AS notify,
406
410
  s.badge AS badge,
411
+ s.kind_override AS kind_override,
407
412
  COALESCE(s.poll_interval_minutes, f.poll_interval_minutes) AS poll_interval_minutes,
408
413
  (
409
414
  SELECT COUNT(*) FROM items i
@@ -425,6 +430,9 @@ export function updateSubscriptionLabel(userId, feedId, label) {
425
430
  export function updateSubscriptionFolder(userId, feedId, folderId) {
426
431
  db.prepare("UPDATE subscriptions SET folder_id = ? WHERE user_id = ? AND feed_id = ?").run(folderId, userId, feedId);
427
432
  }
433
+ export function updateSubscriptionKindOverride(userId, feedId, kindOverride) {
434
+ db.prepare("UPDATE subscriptions SET kind_override = ? WHERE user_id = ? AND feed_id = ?").run(kindOverride, userId, feedId);
435
+ }
428
436
  export function listFoldersForUser(userId) {
429
437
  return db
430
438
  .prepare(`SELECT
@@ -1,6 +1,6 @@
1
1
  import { config } from "../config.js";
2
2
  import { db } from "../db/index.js";
3
- import { createFeed, findFeedByUrl, isUserSubscribed, subscribe, unsubscribe as unsubscribeRepo, findSubscriptionForUser, updateSubscriptionLabel, updateSubscriptionFolder, updateSubscriptionPollInterval, updateSubscriptionFullTextMode, updateSubscriptionNotify, updateSubscriptionBadge, findFolderById, findFeedById, countFeedSubscribers, replaceFeedUrl, moveSubscription, } from "./repository.js";
3
+ import { createFeed, findFeedByUrl, isUserSubscribed, subscribe, unsubscribe as unsubscribeRepo, findSubscriptionForUser, updateSubscriptionLabel, updateSubscriptionFolder, updateSubscriptionPollInterval, updateSubscriptionFullTextMode, updateSubscriptionKindOverride, updateSubscriptionNotify, updateSubscriptionBadge, findFolderById, findFeedById, countFeedSubscribers, replaceFeedUrl, moveSubscription, } from "./repository.js";
4
4
  import { pollFeed, probeFeed } from "./poller.js";
5
5
  import { assertPublicFeedUrl } from "./blockedHosts.js";
6
6
  import { discoverFeeds } from "./discovery.js";
@@ -109,6 +109,9 @@ export function updateFeedSettings(userId, feedId, settings) {
109
109
  if (settings.fullTextMode !== undefined) {
110
110
  updateSubscriptionFullTextMode(userId, feedId, settings.fullTextMode);
111
111
  }
112
+ if (settings.kindOverride !== undefined) {
113
+ updateSubscriptionKindOverride(userId, feedId, settings.kindOverride);
114
+ }
112
115
  if (settings.notify !== undefined) {
113
116
  updateSubscriptionNotify(userId, feedId, settings.notify);
114
117
  }
@@ -21,6 +21,11 @@ export function serializeSubscription(subscription) {
21
21
  badge: Boolean(subscription.badge),
22
22
  isInbox: Boolean(subscription.is_system_inbox),
23
23
  lastError: subscription.last_error,
24
+ kind: subscription.kind_override ?? subscription.detected_kind ?? "article",
25
+ detectedKind: subscription.detected_kind ?? "article",
26
+ kindOverride: subscription.kind_override ?? null,
27
+ description: subscription.description ?? null,
28
+ artworkUrl: subscription.artwork_url ?? null,
24
29
  iconHash: subscription.icon_hash ?? null,
25
30
  iconUrl: subscription.icon_hash
26
31
  ? `/api/v1/subscriptions/${subscription.id}/icon?v=${subscription.icon_hash}`
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.46.1",
3
+ "version": "0.47.1",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }