feedkeeper 0.43.0 → 0.44.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.43.0",
3
+ "version": "0.44.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",
@@ -35,16 +35,16 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@humanwhocodes/ico-to-png": "^1.1.0",
38
- "@modelcontextprotocol/sdk": "^1.30.0",
38
+ "@modelcontextprotocol/sdk": "^1.32.2",
39
39
  "@mozilla/readability": "^0.6.0",
40
40
  "@resvg/resvg-js": "^2.6.2",
41
41
  "@simplewebauthn/server": "^14.0.3",
42
42
  "bcryptjs": "^3.0.3",
43
- "better-sqlite3": "^13.0.3",
43
+ "better-sqlite3": "^13.2.0",
44
44
  "cookie-session": "^2.1.1",
45
45
  "cors": "^2.8.6",
46
46
  "dotenv": "^18.0.8",
47
- "express": "^5.2.1",
47
+ "express": "^5.3.0",
48
48
  "express-rate-limit": "^8.7.2",
49
49
  "fast-xml-parser": "^5.12.0",
50
50
  "helmet": "^8.3.0",
@@ -5,6 +5,7 @@ import { z } from "zod";
5
5
  import { requireSession } from "../auth/middleware.js";
6
6
  import { listItemsForUser, markAllRead, markItemRead, markItemUnread, bookmarkItem, unbookmarkItem, findItemById, } from "../feeds/repository.js";
7
7
  import { loadFullText } from "../feeds/fullText.js";
8
+ import { loadItemChapters } from "../feeds/chapters.js";
8
9
  import { readerHtml } from "../feeds/articleContent.js";
9
10
  import { cleanSnippet } from "../feeds/contentNoise.js";
10
11
  import { fetchItemImage, pruneArchive, scheduleArchive, withArchivedImages, withProxiedImages } from "../feeds/archive.js";
@@ -132,4 +133,21 @@ itemsRouter.post("/:itemId/extract-content", async (req, res) => {
132
133
  cached: result.cached,
133
134
  });
134
135
  });
136
+ itemsRouter.get("/:itemId/chapters", async (req, res) => {
137
+ const itemId = Number(req.params.itemId);
138
+ if (!Number.isInteger(itemId) || itemId <= 0) {
139
+ res.status(400).json({ error: "invalid_item_id" });
140
+ return;
141
+ }
142
+ const result = await loadItemChapters(req.user.id, itemId);
143
+ if (result.status === "not_found") {
144
+ res.status(404).json({ error: "item_not_found" });
145
+ return;
146
+ }
147
+ if (result.status === "unavailable") {
148
+ res.status(502).json({ error: "chapters_unavailable" });
149
+ return;
150
+ }
151
+ res.json({ chapters: result.chapters });
152
+ });
135
153
  //# sourceMappingURL=items.js.map
@@ -8,6 +8,7 @@ import { findArchivedImage, fetchItemImage, withArchivedImages, withProxiedImage
8
8
  import { ImageCacheBusyError } from "../../feeds/imageCache.js";
9
9
  import { discoverFeeds } from "../../feeds/discovery.js";
10
10
  import { loadFullText } from "../../feeds/fullText.js";
11
+ import { loadItemChapters } from "../../feeds/chapters.js";
11
12
  import { generateOpml, importOpmlFeeds } from "../../feeds/opml.js";
12
13
  import { pickFeedListLanguage, resolveFeedLists } from "../../feeds/feedLists.js";
13
14
  import { pollFeed, pollFeeds } from "../../feeds/poller.js";
@@ -446,6 +447,17 @@ resourcesRouter.get("/items/:id", (req, res) => {
446
447
  const hasNotes = itemsWithNotes(req.user.id, [row.id]);
447
448
  res.json(serializeItem(prepare([row], req, parsed.data.images)[0], progress, true, hasNotes.has(row.id)));
448
449
  });
450
+ resourcesRouter.get("/items/:id/chapters", async (req, res) => {
451
+ const id = Number(req.params.id);
452
+ if (!Number.isInteger(id) || id <= 0)
453
+ return invalid(res);
454
+ const result = await loadItemChapters(req.user.id, id);
455
+ if (result.status === "not_found")
456
+ return void res.status(404).json({ error: "item_not_found" });
457
+ if (result.status === "unavailable")
458
+ return void res.status(502).json({ error: "chapters_unavailable" });
459
+ res.json({ chapters: result.chapters });
460
+ });
449
461
  resourcesRouter.post("/items/:id/full-text", requireCapability("fulltext"), async (req, res) => {
450
462
  const id = Number(req.params.id);
451
463
  const result = await loadFullText(req.user.id, id, { force: req.query.force === "true" });
@@ -36,6 +36,12 @@ export function serializeItem(row, progress, withContent, hasNote = false) {
36
36
  snippet: cleanSnippet(row.content_snippet, row.title),
37
37
  lead: leadOf(row),
38
38
  imageUrl: row.image_url,
39
+ media: row.enclosure_url ? {
40
+ url: row.enclosure_url,
41
+ type: row.enclosure_type,
42
+ durationSeconds: row.enclosure_duration_seconds,
43
+ chaptersUrl: row.chapters_url,
44
+ } : null,
39
45
  hasFullText: Boolean(row.full_content_html),
40
46
  content: contentMetadata(row),
41
47
  ...(withContent ? { contentHtml: readerHtml(row.content_html, row.title, row.author, row.link), fullTextHtml: readerHtml(row.full_content_html, row.title, row.author, row.link) } : {}),
@@ -0,0 +1,4 @@
1
+ ALTER TABLE items ADD COLUMN enclosure_url TEXT;
2
+ ALTER TABLE items ADD COLUMN enclosure_type TEXT;
3
+ ALTER TABLE items ADD COLUMN enclosure_duration_seconds INTEGER;
4
+ ALTER TABLE items ADD COLUMN chapters_url TEXT;
@@ -0,0 +1,72 @@
1
+ import { fetchFeed } from "./fetcher.js";
2
+ import { findItemForUser } from "./repository.js";
3
+ const CACHE_TTL_MS = 60 * 60 * 1000;
4
+ const CACHE_LIMIT = 200;
5
+ const chaptersCache = new Map();
6
+ function asHttpUrl(raw) {
7
+ if (typeof raw !== "string")
8
+ return undefined;
9
+ try {
10
+ const parsed = new URL(raw.trim());
11
+ return parsed.protocol === "http:" || parsed.protocol === "https:" ? parsed.toString() : undefined;
12
+ }
13
+ catch {
14
+ return undefined;
15
+ }
16
+ }
17
+ export function parsePodcastChapters(body) {
18
+ const parsed = JSON.parse(body);
19
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
20
+ return [];
21
+ const rawChapters = parsed.chapters;
22
+ if (!Array.isArray(rawChapters))
23
+ return [];
24
+ const chapters = [];
25
+ for (const entry of rawChapters) {
26
+ if (typeof entry !== "object" || entry === null)
27
+ continue;
28
+ const record = entry;
29
+ if (record.toc === false)
30
+ continue;
31
+ const startTime = typeof record.startTime === "number" && Number.isFinite(record.startTime) && record.startTime >= 0 ? record.startTime : null;
32
+ const title = typeof record.title === "string" ? record.title.trim() : "";
33
+ if (startTime === null || !title)
34
+ continue;
35
+ const url = asHttpUrl(record.url);
36
+ const img = asHttpUrl(record.img);
37
+ chapters.push({
38
+ startTime,
39
+ title,
40
+ ...(url ? { url } : {}),
41
+ ...(img ? { img } : {}),
42
+ });
43
+ }
44
+ chapters.sort((a, b) => a.startTime - b.startTime);
45
+ return chapters;
46
+ }
47
+ export async function loadItemChapters(userId, itemId) {
48
+ const item = findItemForUser(userId, itemId);
49
+ if (!item)
50
+ return { status: "not_found" };
51
+ if (!item.chapters_url)
52
+ return { status: "ok", chapters: [] };
53
+ const cached = chaptersCache.get(item.chapters_url);
54
+ if (cached && cached.expiresAt > Date.now()) {
55
+ return { status: "ok", chapters: cached.chapters };
56
+ }
57
+ try {
58
+ const fetched = await fetchFeed(item.chapters_url, { priority: "interactive" });
59
+ const chapters = parsePodcastChapters(fetched.body);
60
+ if (chaptersCache.size >= CACHE_LIMIT) {
61
+ const oldest = chaptersCache.keys().next().value;
62
+ if (oldest)
63
+ chaptersCache.delete(oldest);
64
+ }
65
+ chaptersCache.set(item.chapters_url, { expiresAt: Date.now() + CACHE_TTL_MS, chapters });
66
+ return { status: "ok", chapters };
67
+ }
68
+ catch {
69
+ return { status: "unavailable" };
70
+ }
71
+ }
72
+ //# sourceMappingURL=chapters.js.map
@@ -11,6 +11,8 @@ const xmlParser = new Parser({
11
11
  ["media:thumbnail", "mediaThumbnail", { keepArray: false }],
12
12
  ["media:group", "mediaGroup", { keepArray: false }],
13
13
  ["content:encoded", "contentEncoded", { keepArray: false }],
14
+ ["itunes:duration", "itunesDuration", { keepArray: false }],
15
+ ["podcast:chapters", "podcastChapters", { keepArray: false }],
14
16
  ],
15
17
  },
16
18
  });
@@ -28,6 +30,120 @@ function mediaAttribute(value, key) {
28
30
  return value.$[key];
29
31
  return value[key];
30
32
  }
33
+ function asHttpUrl(raw) {
34
+ if (typeof raw !== "string")
35
+ return null;
36
+ const trimmed = raw.trim();
37
+ if (!trimmed)
38
+ return null;
39
+ try {
40
+ const parsed = new URL(trimmed);
41
+ return parsed.protocol === "http:" || parsed.protocol === "https:" ? parsed.toString() : null;
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ }
47
+ const EXTENSION_MIME = [
48
+ [/\.mp3(\?.*)?$/i, "audio/mpeg"],
49
+ [/\.m4a(\?.*)?$/i, "audio/mp4"],
50
+ [/\.aac(\?.*)?$/i, "audio/aac"],
51
+ [/\.(?:ogg|oga)(\?.*)?$/i, "audio/ogg"],
52
+ [/\.opus(\?.*)?$/i, "audio/opus"],
53
+ [/\.wav(\?.*)?$/i, "audio/wav"],
54
+ [/\.mp4(\?.*)?$/i, "video/mp4"],
55
+ [/\.m4v(\?.*)?$/i, "video/x-m4v"],
56
+ [/\.webm(\?.*)?$/i, "video/webm"],
57
+ [/\.mov(\?.*)?$/i, "video/quicktime"],
58
+ ];
59
+ function resolveMediaMime(rawType, url) {
60
+ if (typeof rawType === "string") {
61
+ const normalized = rawType.toLowerCase().split(";")[0].trim();
62
+ if (normalized.startsWith("audio/") || normalized.startsWith("video/"))
63
+ return normalized;
64
+ }
65
+ for (const [pattern, mime] of EXTENSION_MIME) {
66
+ if (pattern.test(url))
67
+ return mime;
68
+ }
69
+ return null;
70
+ }
71
+ export function parseDurationSeconds(raw) {
72
+ if (typeof raw === "number") {
73
+ return Number.isFinite(raw) && raw > 0 ? Math.round(raw) : null;
74
+ }
75
+ if (typeof raw !== "string")
76
+ return null;
77
+ const trimmed = raw.trim();
78
+ if (!trimmed)
79
+ return null;
80
+ if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
81
+ const value = Math.round(Number(trimmed));
82
+ return Number.isFinite(value) && value > 0 ? value : null;
83
+ }
84
+ const parts = trimmed.split(":");
85
+ if (parts.length >= 2 && parts.length <= 3 && parts.every((part) => /^\d+$/.test(part))) {
86
+ let total = 0;
87
+ for (const part of parts) {
88
+ total = total * 60 + Number(part);
89
+ }
90
+ return total > 0 ? total : null;
91
+ }
92
+ return null;
93
+ }
94
+ function extractXmlMedia(item) {
95
+ let enclosureUrl = null;
96
+ let enclosureType = null;
97
+ if (item.enclosure?.url) {
98
+ const url = asHttpUrl(item.enclosure.url);
99
+ const type = url ? resolveMediaMime(item.enclosure.type, url) : null;
100
+ if (url && type) {
101
+ enclosureUrl = url;
102
+ enclosureType = type;
103
+ }
104
+ }
105
+ const mediaContent = item.mediaContent ?? item["media:content"];
106
+ if (!enclosureUrl && mediaContent) {
107
+ const url = asHttpUrl(mediaAttribute(mediaContent, "url"));
108
+ const type = url ? resolveMediaMime(mediaAttribute(mediaContent, "type"), url) : null;
109
+ if (url && type) {
110
+ enclosureUrl = url;
111
+ enclosureType = type;
112
+ }
113
+ }
114
+ const duration = parseDurationSeconds(item.itunesDuration ?? mediaAttribute(mediaContent, "duration"));
115
+ const rawChaptersUrl = mediaAttribute(item.podcastChapters, "url");
116
+ const rawChaptersType = mediaAttribute(item.podcastChapters, "type");
117
+ const chaptersMime = typeof rawChaptersType === "string" ? rawChaptersType.toLowerCase().split(";")[0].trim() : "";
118
+ const chaptersUrl = !chaptersMime || chaptersMime === "application/json+chapters" || chaptersMime === "application/json"
119
+ ? asHttpUrl(rawChaptersUrl)
120
+ : null;
121
+ return {
122
+ enclosureUrl,
123
+ enclosureType,
124
+ enclosureDurationSeconds: enclosureUrl ? duration : null,
125
+ chaptersUrl: enclosureUrl ? chaptersUrl : null,
126
+ };
127
+ }
128
+ function extractJsonFeedMedia(item) {
129
+ if (Array.isArray(item.attachments)) {
130
+ for (const attachment of item.attachments) {
131
+ if (!isRecord(attachment))
132
+ continue;
133
+ const url = asHttpUrl(attachment.url);
134
+ const type = url ? resolveMediaMime(attachment.mime_type, url) : null;
135
+ if (url && type) {
136
+ return {
137
+ enclosureUrl: url,
138
+ enclosureType: type,
139
+ enclosureDurationSeconds: parseDurationSeconds(attachment.duration_in_seconds),
140
+ chaptersUrl: null,
141
+ };
142
+ }
143
+ }
144
+ }
145
+ return { enclosureUrl: null, enclosureType: null, enclosureDurationSeconds: null, chaptersUrl: null };
146
+ }
31
147
  function asMediaEntries(value) {
32
148
  return Array.isArray(value) ? value : [value];
33
149
  }
@@ -256,6 +372,7 @@ function parseJsonFeed(body) {
256
372
  const itemTitle = plainTitle(asNonEmptyString(entry.title));
257
373
  const contentHtml = asNonEmptyString(entry.content_html) ?? null;
258
374
  const snippetSource = asNonEmptyString(entry.summary) ?? asNonEmptyString(entry.content_text) ?? contentHtml ?? undefined;
375
+ const media = extractJsonFeedMedia(entry);
259
376
  items.push({
260
377
  guid: itemGuid({ guid: rawId, link, title: itemTitle }),
261
378
  title: itemTitle,
@@ -265,6 +382,7 @@ function parseJsonFeed(body) {
265
382
  publishedAt: normalizePublishedAt(asNonEmptyString(entry.date_published) ?? asNonEmptyString(entry.date_modified)) ?? undefined,
266
383
  imageUrl: extractJsonFeedImageUrl(entry, contentHtml),
267
384
  authors: extractJsonFeedAuthors(entry),
385
+ ...media,
268
386
  });
269
387
  }
270
388
  return {
@@ -304,6 +422,7 @@ export async function parseFeedBody(body) {
304
422
  publishedAt: normalizePublishedAt(item.isoDate ?? item.pubDate) ?? undefined,
305
423
  imageUrl: extractXmlImageUrl(item),
306
424
  authors: [item.creator, item.author],
425
+ ...extractXmlMedia(item),
307
426
  })),
308
427
  };
309
428
  }
@@ -64,6 +64,10 @@ async function pollAttempt(feed, signal, interactive) {
64
64
  publishedAt: item.publishedAt,
65
65
  imageUrl: item.imageUrl,
66
66
  author: formatFeedAuthor(item.authors, current.title, current.site_url ?? current.url),
67
+ enclosureUrl: item.enclosureUrl,
68
+ enclosureType: item.enclosureType,
69
+ enclosureDurationSeconds: item.enclosureDurationSeconds,
70
+ chaptersUrl: item.chaptersUrl,
67
71
  }));
68
72
  // No await in this transaction. Items, health/validators and job completion become visible together.
69
73
  const newItems = db.transaction(() => {
@@ -156,8 +156,8 @@ export function updateFeedAfterPoll(feedId, data) {
156
156
  /** A tombstone records that its feed still lists the article; once a day is enough for its 90-day expiry. */
157
157
  const TOMBSTONE_TOUCH_INTERVAL_MS = 24 * 60 * 60 * 1000;
158
158
  export function upsertItems(feedId, items) {
159
- const insert = db.prepare(`INSERT INTO items (feed_id, guid, title, link, content_snippet, content_html, published_at, image_url, author)
160
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
159
+ const insert = db.prepare(`INSERT INTO items (feed_id, guid, title, link, content_snippet, content_html, published_at, image_url, author, enclosure_url, enclosure_type, enclosure_duration_seconds, chapters_url)
160
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
161
161
  ON CONFLICT (feed_id, guid) DO NOTHING`);
162
162
  const update = db.prepare(`UPDATE items SET
163
163
  title = COALESCE(?, title),
@@ -166,7 +166,11 @@ export function upsertItems(feedId, items) {
166
166
  content_html = COALESCE(?, content_html),
167
167
  published_at = COALESCE(?, published_at),
168
168
  image_url = COALESCE(?, image_url),
169
- author = COALESCE(?, author)
169
+ author = COALESCE(?, author),
170
+ enclosure_url = COALESCE(?, enclosure_url),
171
+ enclosure_type = COALESCE(?, enclosure_type),
172
+ enclosure_duration_seconds = COALESCE(?, enclosure_duration_seconds),
173
+ chapters_url = COALESCE(?, chapters_url)
170
174
  WHERE feed_id = ? AND guid = ?`);
171
175
  const tombstone = db.prepare("SELECT last_seen_at FROM item_tombstones WHERE feed_id = ? AND guid = ?");
172
176
  const touchTombstone = db.prepare("UPDATE item_tombstones SET last_seen_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now') WHERE feed_id = ? AND guid = ?");
@@ -191,6 +195,10 @@ export function upsertItems(feedId, items) {
191
195
  row.publishedAt ?? null,
192
196
  largerHeroImage(row.imageUrl, row.contentHtml, row.link ?? null) ?? row.imageUrl ?? null,
193
197
  row.author ?? null,
198
+ row.enclosureUrl ?? null,
199
+ row.enclosureType ?? null,
200
+ row.enclosureDurationSeconds ?? null,
201
+ row.chaptersUrl ?? null,
194
202
  ];
195
203
  const result = insert.run(...values);
196
204
  if (result.changes > 0) {
@@ -198,7 +206,7 @@ export function upsertItems(feedId, items) {
198
206
  refreshLead(Number(result.lastInsertRowid));
199
207
  }
200
208
  else {
201
- const previous = db.prepare("SELECT id, title, link, image_url, content_snippet, content_html, full_content_html, published_at, author, lead_version FROM items WHERE feed_id = ? AND guid = ?").get(feedId, row.guid);
209
+ const previous = db.prepare("SELECT id, title, link, image_url, content_snippet, content_html, full_content_html, published_at, author, enclosure_url, enclosure_type, enclosure_duration_seconds, chapters_url, lead_version FROM items WHERE feed_id = ? AND guid = ?").get(feedId, row.guid);
202
210
  const next = row.contentHtml;
203
211
  // Some publishers replace complete feed bodies with short teasers on a later poll.
204
212
  const retained = previous?.content_html && next && next.length < previous.content_html.length * 0.9 &&
@@ -216,9 +224,13 @@ export function upsertItems(feedId, items) {
216
224
  (retained !== null && retained !== previous.content_html) ||
217
225
  (row.publishedAt !== undefined && row.publishedAt !== null && row.publishedAt !== previous.published_at) ||
218
226
  (nextImage !== previous.image_url) ||
219
- (row.author !== undefined && row.author !== null && row.author !== previous.author);
227
+ (row.author !== undefined && row.author !== null && row.author !== previous.author) ||
228
+ (row.enclosureUrl !== undefined && row.enclosureUrl !== null && row.enclosureUrl !== previous.enclosure_url) ||
229
+ (row.enclosureType !== undefined && row.enclosureType !== null && row.enclosureType !== previous.enclosure_type) ||
230
+ (row.enclosureDurationSeconds !== undefined && row.enclosureDurationSeconds !== null && row.enclosureDurationSeconds !== previous.enclosure_duration_seconds) ||
231
+ (row.chaptersUrl !== undefined && row.chaptersUrl !== null && row.chaptersUrl !== previous.chapters_url);
220
232
  if (changed) {
221
- update.run(row.title ?? null, row.link ?? null, nextSnippet, retained, row.publishedAt ?? null, nextImage, row.author ?? null, feedId, row.guid);
233
+ update.run(row.title ?? null, row.link ?? null, nextSnippet, retained, row.publishedAt ?? null, nextImage, row.author ?? null, row.enclosureUrl ?? null, row.enclosureType ?? null, row.enclosureDurationSeconds ?? null, row.chaptersUrl ?? null, feedId, row.guid);
222
234
  const leadChanged = (retained !== null && retained !== previous.content_html) ||
223
235
  (row.link !== undefined && row.link !== previous.link) ||
224
236
  (row.title !== undefined && row.title !== previous.title) ||
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.43.0",
3
+ "version": "0.44.1",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }