feedkeeper 0.42.6 → 0.44.0

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.
@@ -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) ||
@@ -74,12 +74,37 @@ const strings = {
74
74
  manage: "プランを管理",
75
75
  forbidden: "別のサイトからのリクエストのためブロックしました。",
76
76
  },
77
+ ru: {
78
+ passkey: "Войти с помощью пароля",
79
+ loginTitle: "Вход в FeedKeeper",
80
+ loginIntro: "{client} хочет подключиться к вашему аккаунту FeedKeeper. Войдите, чтобы продолжить.",
81
+ email: "Электронная почта",
82
+ password: "Пароль",
83
+ signIn: "Войти",
84
+ badLogin: "Неверная электронная почта или пароль.",
85
+ consentTitle: "Разрешить доступ?",
86
+ consentIntro: "{client} хочет получить доступ к вашему аккаунту FeedKeeper через MCP.",
87
+ returnsTo: "После вашего выбора вы вернётесь на {host}.",
88
+ readOnly: "Только чтение",
89
+ readOnlyHint: "Просмотр лент и статей. Без изменений.",
90
+ readWrite: "Чтение и запись",
91
+ readWriteHint: "Отмечать статьи прочитанными, добавлять в избранное, управлять лентами и папками.",
92
+ allow: "Разрешить",
93
+ deny: "Отклонить",
94
+ signedInAs: "Вход выполнен как {user}",
95
+ errorTitle: "Этот запрос невозможно выполнить",
96
+ unknownClient: "Приложение не зарегистрировано на этом сервере.",
97
+ badRedirect: "Адрес возврата не совпадает с регистрацией приложения.",
98
+ noAccess: "Ваш аккаунт не включает доступ MCP.",
99
+ manage: "Управление планом",
100
+ forbidden: "Запрос пришёл с другого сайта и был заблокирован.",
101
+ },
77
102
  };
78
103
  function languageOf(req) {
79
104
  const header = String(req.headers["accept-language"] ?? "").toLowerCase();
80
105
  for (const part of header.split(",")) {
81
106
  const tag = part.trim().slice(0, 2);
82
- if (tag === "de" || tag === "ja" || tag === "en")
107
+ if (tag === "de" || tag === "ja" || tag === "en" || tag === "ru")
83
108
  return tag;
84
109
  }
85
110
  return "en";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.42.6",
3
+ "version": "0.44.0",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }