feedkeeper 0.38.3 → 0.38.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feedkeeper",
3
- "version": "0.38.3",
3
+ "version": "0.38.5",
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",
@@ -20,6 +20,13 @@ const loginLimiter = rateLimit({
20
20
  standardHeaders: true,
21
21
  legacyHeaders: false,
22
22
  });
23
+ // Accounts are cheap to ask for and expensive to hash; open signup must not be a way to flood the instance.
24
+ const signupLimiter = rateLimit({
25
+ windowMs: 60 * 60 * 1000,
26
+ limit: 5,
27
+ standardHeaders: true,
28
+ legacyHeaders: false,
29
+ });
23
30
  const loginSchema = z.object({
24
31
  email: z.string().email(),
25
32
  password: z.string().min(1),
@@ -150,7 +157,7 @@ const signupSchema = z.object({
150
157
  password: z.string().min(10),
151
158
  displayName: z.string().min(1).max(100),
152
159
  });
153
- authRouter.post("/signup", (req, res) => {
160
+ authRouter.post("/signup", signupLimiter, (req, res) => {
154
161
  if (!config.allowSignup) {
155
162
  res.status(403).json({ error: "signup_disabled" });
156
163
  return;
@@ -0,0 +1,10 @@
1
+ -- Articles removed by retention while their feed still lists them. Without this record the next poll
2
+ -- would add them again as new, unread articles (and announce them by push), every day.
3
+ CREATE TABLE IF NOT EXISTS item_tombstones (
4
+ feed_id INTEGER NOT NULL REFERENCES feeds(id) ON DELETE CASCADE,
5
+ guid TEXT NOT NULL,
6
+ last_seen_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
7
+ PRIMARY KEY (feed_id, guid)
8
+ ) WITHOUT ROWID;
9
+
10
+ CREATE INDEX IF NOT EXISTS idx_item_tombstones_last_seen ON item_tombstones(last_seen_at);
@@ -0,0 +1,7 @@
1
+ -- Each subscriber keeps their own poll interval; the feed runs at the shortest one. NULL means the server default.
2
+ -- Existing subscriptions take over the interval their feed has today, so nothing changes on upgrade.
3
+ ALTER TABLE subscriptions ADD COLUMN poll_interval_minutes INTEGER;
4
+
5
+ UPDATE subscriptions
6
+ SET poll_interval_minutes = (SELECT feeds.poll_interval_minutes FROM feeds WHERE feeds.id = subscriptions.feed_id)
7
+ WHERE feed_id IN (SELECT id FROM feeds WHERE is_system_inbox = 0);
@@ -73,6 +73,24 @@ export function updateRetentionSettings(settings) {
73
73
  apply();
74
74
  return getRetentionSettings();
75
75
  }
76
+ /** Feeds poll at most weekly, so an article a feed still lists refreshes its tombstone long before this. */
77
+ const TOMBSTONE_RETENTION_DAYS = 90;
78
+ /**
79
+ * Deletes the matching articles and remembers them per feed. Retention cannot remove an article from the publisher's feed,
80
+ * so without the tombstone the next poll would add it again as a new, unread article.
81
+ */
82
+ function retireItems(where, ...params) {
83
+ return db.transaction(() => {
84
+ db.prepare(`INSERT INTO item_tombstones (feed_id, guid)
85
+ SELECT feed_id, guid FROM items WHERE ${where}
86
+ ON CONFLICT (feed_id, guid) DO UPDATE SET last_seen_at = excluded.last_seen_at`).run(...params);
87
+ return db.prepare(`DELETE FROM items WHERE ${where}`).run(...params).changes;
88
+ })();
89
+ }
90
+ /** Forgets articles their feed has stopped listing; those cannot come back. */
91
+ function pruneItemTombstones() {
92
+ db.prepare("DELETE FROM item_tombstones WHERE last_seen_at < strftime('%Y-%m-%dT%H:%M:%fZ', 'now', ?)").run(`-${TOMBSTONE_RETENTION_DAYS} days`);
93
+ }
76
94
  export function runCleanup(custom) {
77
95
  const settings = {
78
96
  ...getRetentionSettings(),
@@ -84,8 +102,7 @@ export function runCleanup(custom) {
84
102
  let deletedPerFeedExcess = 0;
85
103
  // 1. Delete read items older than retentionReadDays (excluding bookmarked items and items with notes)
86
104
  if (settings.retentionReadDays > 0) {
87
- const res = db.prepare(`DELETE FROM items
88
- WHERE id IN (
105
+ deletedReadItems = retireItems(`id IN (
89
106
  SELECT i.id
90
107
  FROM items i
91
108
  WHERE i.id NOT IN (SELECT item_id FROM item_bookmarks)
@@ -100,24 +117,20 @@ export function runCleanup(custom) {
100
117
  AND NOT EXISTS (SELECT 1 FROM item_reads r WHERE r.item_id = i.id AND r.user_id = s.user_id)
101
118
  )
102
119
  AND COALESCE(julianday(i.published_at), julianday(i.created_at)) <= julianday('now', '-' || ? || ' days')
103
- )`).run(settings.retentionReadDays);
104
- deletedReadItems = res.changes;
120
+ )`, settings.retentionReadDays);
105
121
  }
106
122
  // 2. Delete all items older than retentionMaxDays (excluding bookmarked items and items with notes)
107
123
  if (settings.retentionMaxDays > 0) {
108
- const res = db.prepare(`DELETE FROM items
109
- WHERE id NOT IN (SELECT item_id FROM item_bookmarks)
124
+ deletedOldItems = retireItems(`id NOT IN (SELECT item_id FROM item_bookmarks)
110
125
  AND id NOT IN (SELECT item_id FROM item_notes)
111
126
  AND feed_id NOT IN (SELECT id FROM feeds WHERE is_system_inbox = 1)
112
127
  AND id NOT IN (SELECT CAST(selected.value AS INTEGER) FROM editions e, json_each(e.item_ids) selected
113
128
  WHERE e.source = 'curated' AND e.status <> 'dismissed')
114
- AND COALESCE(julianday(published_at), julianday(created_at)) <= julianday('now', '-' || ? || ' days')`).run(settings.retentionMaxDays);
115
- deletedOldItems = res.changes;
129
+ AND COALESCE(julianday(published_at), julianday(created_at)) <= julianday('now', '-' || ? || ' days')`, settings.retentionMaxDays);
116
130
  }
117
131
  // 3. Delete items exceeding retentionMaxItemsPerFeed (excluding bookmarked items and items with notes)
118
132
  if (settings.retentionMaxItemsPerFeed > 0) {
119
- const res = db.prepare(`DELETE FROM items
120
- WHERE id NOT IN (SELECT item_id FROM item_bookmarks)
133
+ deletedPerFeedExcess = retireItems(`id NOT IN (SELECT item_id FROM item_bookmarks)
121
134
  AND id NOT IN (SELECT item_id FROM item_notes)
122
135
  AND feed_id NOT IN (SELECT id FROM feeds WHERE is_system_inbox = 1)
123
136
  AND id NOT IN (SELECT CAST(selected.value AS INTEGER) FROM editions e, json_each(e.item_ids) selected
@@ -131,9 +144,9 @@ export function runCleanup(custom) {
131
144
  FROM items
132
145
  )
133
146
  WHERE rn > ?
134
- )`).run(settings.retentionMaxItemsPerFeed);
135
- deletedPerFeedExcess = res.changes;
147
+ )`, settings.retentionMaxItemsPerFeed);
136
148
  }
149
+ pruneItemTombstones();
137
150
  // Feeds kept only for saved articles go once nothing of them is saved anymore.
138
151
  removeUnusedFeeds();
139
152
  pruneArchive();
@@ -1,4 +1,4 @@
1
- import { PLAY_LABEL } from "../patterns/play-labels/index.js";
1
+ import { PLAY_LABEL, PLAYER_TITLES } from "../patterns/play-labels/index.js";
2
2
  import { flat, linkParagraph, parseAddress, pruneEmpty } from "../shared.js";
3
3
  const PLAY_SOURCE = /(?:^|[/_.-])play[-_]?(?:icon|button|btn)?\.(?:svg|png|webp|gif)(?:[?#]|$)/i;
4
4
  const DURATION = /^\d{1,2}:\d{2}(:\d{2})?$/;
@@ -31,6 +31,17 @@ export function embedTarget(source) {
31
31
  }
32
32
  return null;
33
33
  }
34
+ /** The name of the video site a watch-page address belongs to, for the labels of links that were saved without a title. */
35
+ function videoSiteName(source) {
36
+ const host = parseAddress(source)?.hostname.replace(/^(?:www|m)\./, "") ?? "";
37
+ if (/^(?:youtube(?:-nocookie)?\.com|youtu\.be)$/.test(host))
38
+ return "YouTube";
39
+ if (/^(?:player\.)?vimeo\.com$/.test(host))
40
+ return "Vimeo";
41
+ if (/^dailymotion\.com$/.test(host))
42
+ return "Dailymotion";
43
+ return null;
44
+ }
34
45
  /**
35
46
  * Players need the publisher's script: a reader without it shows their play-button picture as a broken image and
36
47
  * leaves a dead block. What can be reached stays as one plain link to the video (`data-media="video"` tells a client
@@ -83,7 +94,8 @@ function resolveVideoPlayers(root, stats) {
83
94
  if (!target)
84
95
  continue;
85
96
  const parent = frame.parentNode;
86
- const replacement = linkParagraph(frame.ownerDocument, target.url, flat(frame.getAttribute("title")) || target.name);
97
+ const title = flat(frame.getAttribute("title"));
98
+ const replacement = linkParagraph(frame.ownerDocument, target.url, title && !PLAYER_TITLES.some(pattern => pattern.test(title)) ? title : target.name);
87
99
  frame.replaceWith(replacement);
88
100
  pruneEmpty(parent);
89
101
  links.push(replacement.querySelector("a"));
@@ -107,7 +119,17 @@ export const videoPlayers = {
107
119
  apply(root, stats) {
108
120
  const { changed, links } = resolveVideoPlayers(root, stats);
109
121
  links.forEach(link => link.setAttribute("data-media", "video"));
110
- return changed;
122
+ // A video link already saved with the player's technical name as its label ("vimeo-player") shows the platform instead.
123
+ let renamed = false;
124
+ for (const link of root.querySelectorAll("a[data-media='video'][href]")) {
125
+ const name = videoSiteName(link.getAttribute("href") ?? "");
126
+ const label = flat(link.textContent);
127
+ if (name && label && PLAYER_TITLES.some(pattern => pattern.test(label))) {
128
+ link.textContent = name;
129
+ renamed = true;
130
+ }
131
+ }
132
+ return changed || renamed;
111
133
  },
112
134
  };
113
135
  //# sourceMappingURL=video.js.map
@@ -0,0 +1,7 @@
1
+ /** Lines that only restate what a reader's head already shows, in German. See `en.ts`. */
2
+ export default {
3
+ weekdays: ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
4
+ relativeAges: [/^vor\s+(?:\d{1,3}|einer|einem)\s*(?:Sekunden?|Sek\.|Minuten?|Min\.|Stunden?|Std\.|Tagen?|Wochen?)$/i, /^(?:gerade eben|soeben|eben erst)$/i],
5
+ kickers: [/^(?:NEWS|News|Nachrichten|Meldung|Kolumne|Rezension|Interview)\s*[||//·•]\s*[^.!?。!?]{1,40}$/],
6
+ };
7
+ //# sourceMappingURL=de.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Lines that only restate what a reader's head already shows, in English. A line counts only whole and only near the
3
+ * start of the text; a sentence that merely contains a weekday or "ago" is never matched.
4
+ */
5
+ export default {
6
+ weekdays: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
7
+ /** How long ago the page was published: `4 minutes ago`, `just now`. */
8
+ relativeAges: [/^\d{1,3}\s*(?:seconds?|secs?|minutes?|mins?|hours?|hrs?|days?|weeks?)\s+ago$/i, /^(?:just now|moments? ago)$/i],
9
+ /** A section label in front of the story: `NEWS | Sound / Exhibition`. */
10
+ kickers: [/^(?:NEWS|News|Feature|Column|Review|Opinion|Interview)\s*[||//·•]\s*[^.!?。!?]{1,40}$/],
11
+ };
12
+ //# sourceMappingURL=en.js.map
@@ -0,0 +1,13 @@
1
+ import de from "./de.js";
2
+ import en from "./en.js";
3
+ import ja from "./ja.js";
4
+ const LANGUAGES = [de, en, ja];
5
+ const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6
+ /** One file per language, searched all at once. To add a language, add a file next to these and list it here. */
7
+ export const RELATIVE_AGES = LANGUAGES.flatMap(language => language.relativeAges);
8
+ export const SECTION_KICKERS = LANGUAGES.flatMap(language => language.kickers);
9
+ const WEEKDAY = `(?:${LANGUAGES.flatMap(language => language.weekdays).map(escape).join("|")})`;
10
+ /** `2026-11-17`, `2026.11.17 Tue`, `17.11.2026 Di`, `2026年11月17日 17時54分`, repeated as some pages print it twice: a date a reader's head already shows. */
11
+ const NUMERIC_DATE = `(?:\\d{4}[-./年]\\d{1,2}[-./月]\\d{1,2}日?|\\d{1,2}\\.\\s?\\d{1,2}\\.\\s?\\d{2,4})(?:\\s*[((]?${WEEKDAY}[))]?)?(?:\\s+\\d{1,2}(?::|時)\\d{2}分?)?`;
12
+ export const NUMERIC_DATELINE = new RegExp(`^${NUMERIC_DATE}(?:\\s+${NUMERIC_DATE}){0,2}$`, "u");
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ /** Lines that only restate what a reader's head already shows, in Japanese. See `en.ts`. */
2
+ export default {
3
+ weekdays: ["月", "火", "水", "木", "金", "土", "日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日", "日曜日"],
4
+ relativeAges: [/^\d{1,3}\s*(?:秒|分|時間|日|週間|か月|ヶ月)前$/, /^(?:たった今|今さっき|数分前)$/],
5
+ kickers: [/^(?:NEWS|ニュース|コラム|レポート|インタビュー|特集|レビュー)\s*[||//・·•]\s*[^.!?。!?]{1,40}$/],
6
+ };
7
+ //# sourceMappingURL=ja.js.map
@@ -1,3 +1,5 @@
1
1
  /** Labels, in German, that a player's play-button picture carries as its alt text. See `en.ts`. */
2
2
  export default ["video starten", "video abspielen", "abspielen", "wiedergabe", "wiedergabe starten"];
3
+ /** Technical frame titles, in German. See `en.ts`. */
4
+ export const PLAYER_TITLES = [/^[\w. -]{0,30}[ -]?(?:video-?)?player$/i, /^(?:Video-?)?Wiedergabe$/i];
3
5
  //# sourceMappingURL=de.js.map
@@ -3,4 +3,6 @@
3
3
  * with the player. Whole texts only: a sentence that merely contains "play" is never a label.
4
4
  */
5
5
  export default ["play", "play video", "watch", "watch video", "start video"];
6
+ /** Titles a player's frame carries as a technical name, not as the name of the video: `vimeo-player`, `YouTube video player`. */
7
+ export const PLAYER_TITLES = [/^[\w. -]{0,30}[ -]?player$/i];
6
8
  //# sourceMappingURL=en.js.map
@@ -1,6 +1,8 @@
1
- import de from "./de.js";
2
- import en from "./en.js";
3
- import ja from "./ja.js";
1
+ import de, { PLAYER_TITLES as deTitles } from "./de.js";
2
+ import en, { PLAYER_TITLES as enTitles } from "./en.js";
3
+ import ja, { PLAYER_TITLES as jaTitles } from "./ja.js";
4
4
  /** One file per language, searched all at once. To add a language, add a file next to these and list it here. */
5
5
  export const PLAY_LABEL = new RegExp(`^(?:${[de, en, ja].flat().map(label => label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`, "i");
6
+ /** A frame title that names the player technology rather than the video: the platform name is the better label then. */
7
+ export const PLAYER_TITLES = [...deTitles, ...enTitles, ...jaTitles];
6
8
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,5 @@
1
1
  /** Labels, in Japanese, that a player's play-button picture carries as its alt text. See `en.ts`. */
2
2
  export default ["動画を再生", "動画を再生する", "動画を見る", "再生", "再生する", "動画再生"];
3
+ /** Technical frame titles, in Japanese. See `en.ts`. */
4
+ export const PLAYER_TITLES = [/^[\w. -]{0,30}(?:動画)?プレ[ーイ]ヤー$/];
3
5
  //# sourceMappingURL=ja.js.map
@@ -8,7 +8,7 @@ export const SIDEBAR_SELECTORS = [
8
8
  ".yarpp-related", "#jp-relatedposts", ".jp-relatedposts", ".related-posts", ".related_posts", ".relatedposts",
9
9
  ".wp-block-latest-posts", ".post-navigation", ".crp_related",
10
10
  // Sites that mark the block with an analytics label.
11
- "[data-track='popular-stories']", "[data-track='related-stories']", "[data-track='related-articles']",
11
+ "[data-track='popular-stories']", "[data-track='related-stories']", "[data-track='related-articles']", "[data-track*='ranking' i]",
12
12
  // Broadcasters' "this topic in our programme" teasers.
13
13
  ".relatedbroadcast",
14
14
  ];
@@ -0,0 +1,3 @@
1
+ /** Headings, in German, that start the tag cloud at the foot of a page. See `en.ts`. */
2
+ export default [/^(?:Schlagw(?:ö|oe)rter|Schlagworte|Stichw(?:ö|oe)rter|Stichworte|Verwandte Themen)$/i];
3
+ //# sourceMappingURL=de.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Headings that start the tag cloud at the foot of a page. Whole headings only; what follows in the tail of the text is
3
+ * a list of tags and the page's own navigation, never the story.
4
+ */
5
+ export default [/^(?:Tags|Keywords|Related topics|Featured topics)$/i];
6
+ //# sourceMappingURL=en.js.map
@@ -0,0 +1,6 @@
1
+ import de from "./de.js";
2
+ import en from "./en.js";
3
+ import ja from "./ja.js";
4
+ /** One file per language, searched all at once. To add a language, add a file next to these and list it here. */
5
+ export const TAG_HEADINGS = [de, en, ja].flat();
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ /** Headings, in Japanese, that start the tag cloud at the foot of a page. See `en.ts`. */
2
+ export default [/^(?:注目ワード|関連ワード|関連キーワード|キーワード|タグ|関連トピックス)$/];
3
+ //# sourceMappingURL=ja.js.map
@@ -5,6 +5,8 @@ import { SNIPPET_BYLINES, SNIPPET_IMAGE_METADATA } from "./content/patterns/snip
5
5
  import { BOILERPLATE_NEWSLETTER, BOILERPLATE_ORPHAN_HEADINGS } from "./content/patterns/boilerplate/index.js";
6
6
  import { CONSENT_ANCHORS, CONSENT_COMPANIONS } from "./content/patterns/consent/index.js";
7
7
  import { SIDEBAR_HEADINGS } from "./content/patterns/sidebars/index.js";
8
+ import { NUMERIC_DATELINE, RELATIVE_AGES, SECTION_KICKERS } from "./content/patterns/datelines/index.js";
9
+ import { TAG_HEADINGS } from "./content/patterns/tag-headings/index.js";
8
10
  import { resolveEmbeds } from "./content/embeds/index.js";
9
11
  import { embedTarget } from "./content/embeds/video.js";
10
12
  import { socialFrameTarget } from "./content/embeds/social.js";
@@ -329,7 +331,7 @@ function removeReaderNoise(root, title, stats, author) {
329
331
  continue;
330
332
  }
331
333
  if (text.length <= 60) {
332
- if (DATE_ONLY.test(text)) {
334
+ if (DATE_ONLY.test(text) || NUMERIC_DATELINE.test(text) || RELATIVE_AGES.some(pattern => pattern.test(text))) {
333
335
  drop(block, "dateline");
334
336
  continue;
335
337
  }
@@ -337,6 +339,15 @@ function removeReaderNoise(root, title, stats, author) {
337
339
  drop(block, "reading-time");
338
340
  continue;
339
341
  }
342
+ if (SECTION_KICKERS.some(pattern => pattern.test(text))) {
343
+ drop(block, "section-kicker");
344
+ continue;
345
+ }
346
+ // The page number of a one-page article ("1 / 1") belongs to the publisher's pager, not to the story.
347
+ if (/^\d{1,3}\s*[//]\s*\d{1,3}$/.test(text)) {
348
+ drop(block, "pager");
349
+ continue;
350
+ }
340
351
  // When the feed names the author, the reader shows the name in its head: a byline that only says that goes.
341
352
  cleanByline(block, text);
342
353
  if (!root.contains(block))
@@ -349,6 +360,14 @@ function removeReaderNoise(root, title, stats, author) {
349
360
  drop(block, "title-repeat");
350
361
  continue;
351
362
  }
363
+ // A link to the story itself at the very start ("JUST IN <headline> (12:21)"): the headline plus a short label or time.
364
+ if (headline.length >= 8 && position < 4 && block.querySelector("a[href]") && !block.querySelector("img, picture, video") && charsBefore(root, block) <= 300) {
365
+ const own = normalized(text);
366
+ if (own !== headline && own.includes(headline) && own.length <= headline.length + 24) {
367
+ drop(block, "title-repeat");
368
+ continue;
369
+ }
370
+ }
352
371
  if (position < 14 && /^(Audiobeitrag|Videobeitrag)\s*>/.test(text) && headline && normalized(text).endsWith(headline)) {
353
372
  drop(block, "title-repeat");
354
373
  continue;
@@ -367,7 +386,10 @@ function removeReaderNoise(root, title, stats, author) {
367
386
  }
368
387
  if (!pastStart && text.length <= 70 && block.querySelector("time") && charsBefore(root, block) <= 600) {
369
388
  const rest = flat(text.replace(flat(block.querySelector("time")?.textContent), ""));
370
- if (/^(news|ニュース|nachrichten|stand|zuletzt aktualisiert|aktualisiert|ver(ö|oe)ffentlicht|updated|published|posted)?\s*[:·|•-]*\s*$/i.test(rest)) {
389
+ // A short category link next to the date ("2026年11月17日 17時54分 AI") is the section chip of the dateline.
390
+ const chips = [...block.querySelectorAll("a")].map(anchor => flat(anchor.textContent));
391
+ const unlinked = chips.length > 0 && chips.every(chip => chip.length <= 30) ? flat(chips.reduce((left, chip) => (chip ? left.replace(chip, "") : left), rest)) : rest;
392
+ if (/^(news|ニュース|nachrichten|stand|zuletzt aktualisiert|aktualisiert|ver(ö|oe)ffentlicht|updated|published|posted)?\s*[:·|•-]*\s*$/i.test(unlinked)) {
371
393
  drop(block, "dateline");
372
394
  continue;
373
395
  }
@@ -424,6 +446,21 @@ function removeReaderNoise(root, title, stats, author) {
424
446
  drop(block, "consent-wall");
425
447
  break;
426
448
  }
449
+ // The tag cloud at the foot of a page ("Tags", "注目ワード") and the page navigation below it: heading and everything after go.
450
+ for (const block of [...root.querySelectorAll("h2, h3, h4, h5, h6")]) {
451
+ if (!block.parentNode || !TAG_HEADINGS.some(pattern => pattern.test(flat(block.textContent))))
452
+ continue;
453
+ if (total - charsBefore(root, block) > TAIL_CHARACTERS)
454
+ continue;
455
+ let node = block;
456
+ while (node.parentNode && node !== root) {
457
+ while (node.nextSibling)
458
+ node.nextSibling.remove();
459
+ node = node.parentNode;
460
+ }
461
+ drop(block, "tag-cloud");
462
+ break;
463
+ }
427
464
  // An orphan recommendation heading left without subsequent links or content.
428
465
  for (const block of leafBlocks(root)) {
429
466
  if (!block.parentNode)
@@ -1,3 +1,4 @@
1
+ import { config } from "../config.js";
1
2
  import { db } from "../db/index.js";
2
3
  import { articleText } from "./articleContent.js";
3
4
  import { LEAD_VERSION } from "./contentNoise.js";
@@ -36,11 +37,13 @@ export function subscribe(userId, feedId, label, folderId) {
36
37
  label = COALESCE(excluded.label, subscriptions.label),
37
38
  folder_id = COALESCE(excluded.folder_id, subscriptions.folder_id)`)
38
39
  .run(userId, feedId, label?.trim() || null, folderId ?? null, nextPosition);
40
+ refreshFeedPollInterval(feedId);
39
41
  return Number(result.lastInsertRowid);
40
42
  }
41
43
  export function unsubscribe(userId, feedId) {
42
44
  db.transaction(() => {
43
45
  db.prepare("DELETE FROM subscriptions WHERE user_id = ? AND feed_id = ?").run(userId, feedId);
46
+ refreshFeedPollInterval(feedId);
44
47
  removeFeedIfUnused(feedId);
45
48
  })();
46
49
  }
@@ -54,6 +57,8 @@ export function removeFeedIfUnused(feedId) {
54
57
  db.prepare(`DELETE FROM items WHERE feed_id = ? AND id NOT IN (SELECT item_id FROM item_bookmarks) AND id NOT IN (SELECT item_id FROM item_notes)
55
58
  AND id NOT IN (SELECT CAST(selected.value AS INTEGER) FROM editions e, json_each(e.item_ids) selected
56
59
  WHERE e.source = 'curated' AND e.status <> 'dismissed')`).run(feedId);
60
+ // A later subscriber starts with everything the feed lists, as with a feed nobody had before.
61
+ db.prepare("DELETE FROM item_tombstones WHERE feed_id = ?").run(feedId);
57
62
  db.prepare("DELETE FROM feeds WHERE id = ? AND is_system_inbox = 0 AND NOT EXISTS (SELECT 1 FROM items WHERE feed_id = ?)").run(feedId, feedId);
58
63
  }
59
64
  /** Feeds kept only for saved articles or annotated articles whose last bookmark and note are gone. */
@@ -91,6 +96,7 @@ export function listSubscriptionsForUser(userId) {
91
96
  s.full_text_mode AS full_text_mode,
92
97
  s.notify AS notify,
93
98
  s.badge AS badge,
99
+ COALESCE(s.poll_interval_minutes, f.poll_interval_minutes) AS poll_interval_minutes,
94
100
  (
95
101
  SELECT COUNT(*) FROM items i
96
102
  WHERE i.feed_id = f.id
@@ -146,6 +152,8 @@ export function updateFeedAfterPoll(feedId, data) {
146
152
  WHERE id = ?`).run(data.title ?? null, data.siteUrl ?? null, data.etag ?? null, data.lastModified ?? null, feedId);
147
153
  }
148
154
  }
155
+ /** A tombstone records that its feed still lists the article; once a day is enough for its 90-day expiry. */
156
+ const TOMBSTONE_TOUCH_INTERVAL_MS = 24 * 60 * 60 * 1000;
149
157
  export function upsertItems(feedId, items) {
150
158
  const insert = db.prepare(`INSERT INTO items (feed_id, guid, title, link, content_snippet, content_html, published_at, image_url, author)
151
159
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
@@ -159,9 +167,19 @@ export function upsertItems(feedId, items) {
159
167
  image_url = COALESCE(?, image_url),
160
168
  author = COALESCE(?, author)
161
169
  WHERE feed_id = ? AND guid = ?`);
170
+ const tombstone = db.prepare("SELECT last_seen_at FROM item_tombstones WHERE feed_id = ? AND guid = ?");
171
+ const touchTombstone = db.prepare("UPDATE item_tombstones SET last_seen_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now') WHERE feed_id = ? AND guid = ?");
172
+ const touchBefore = new Date(Date.now() - TOMBSTONE_TOUCH_INTERVAL_MS).toISOString();
162
173
  const insertMany = db.transaction((rows) => {
163
174
  let inserted = 0;
164
175
  for (const row of rows) {
176
+ // Retention removed this article; the feed still lists it. Keep it gone instead of adding it again as new.
177
+ const removed = tombstone.get(feedId, row.guid);
178
+ if (removed) {
179
+ if (removed.last_seen_at < touchBefore)
180
+ touchTombstone.run(feedId, row.guid);
181
+ continue;
182
+ }
165
183
  const values = [
166
184
  feedId,
167
185
  row.guid,
@@ -367,6 +385,7 @@ export function findSubscriptionForUser(userId, feedId) {
367
385
  s.full_text_mode AS full_text_mode,
368
386
  s.notify AS notify,
369
387
  s.badge AS badge,
388
+ COALESCE(s.poll_interval_minutes, f.poll_interval_minutes) AS poll_interval_minutes,
370
389
  (
371
390
  SELECT COUNT(*) FROM items i
372
391
  WHERE i.feed_id = f.id
@@ -439,8 +458,23 @@ export function updateFolder(userId, id, updates) {
439
458
  export function deleteFolder(userId, id) {
440
459
  db.prepare("DELETE FROM folders WHERE id = ? AND user_id = ?").run(id, userId);
441
460
  }
442
- export function updateFeedPollInterval(feedId, minutes) {
443
- db.prepare("UPDATE feeds SET poll_interval_minutes = ? WHERE id = ?").run(minutes, feedId);
461
+ /** The interval a subscription gets until its subscriber picks one. */
462
+ export function defaultPollIntervalMinutes() {
463
+ return Math.max(config.minPollIntervalMinutes, 15);
464
+ }
465
+ /** A subscriber's own choice; it never slows down the feed for anyone else. */
466
+ export function updateSubscriptionPollInterval(userId, feedId, minutes) {
467
+ db.transaction(() => {
468
+ db.prepare("UPDATE subscriptions SET poll_interval_minutes = ? WHERE user_id = ? AND feed_id = ?").run(minutes, userId, feedId);
469
+ refreshFeedPollInterval(feedId);
470
+ })();
471
+ }
472
+ /** One poll serves every subscriber, so a feed runs at the shortest interval any of them chose. */
473
+ export function refreshFeedPollInterval(feedId) {
474
+ db.prepare(`UPDATE feeds SET poll_interval_minutes = (
475
+ SELECT MIN(COALESCE(s.poll_interval_minutes, ?)) FROM subscriptions s WHERE s.feed_id = feeds.id
476
+ )
477
+ WHERE id = ? AND is_system_inbox = 0 AND EXISTS (SELECT 1 FROM subscriptions s WHERE s.feed_id = feeds.id)`).run(defaultPollIntervalMinutes(), feedId);
444
478
  }
445
479
  export function markAllRead(userId, filter) {
446
480
  const feedId = typeof filter === "number" ? filter : filter?.feedId;
@@ -473,12 +507,11 @@ export function markItemRead(userId, itemId) {
473
507
  export function markItemUnread(userId, itemId) {
474
508
  return db.prepare("DELETE FROM item_reads WHERE user_id = ? AND item_id = ?").run(userId, itemId).changes;
475
509
  }
510
+ /** Whatever a person may open they may also save, including articles of their edition from a feed they have left. */
476
511
  export function bookmarkItem(userId, itemId) {
477
- return db.prepare(`INSERT INTO item_bookmarks (user_id, item_id)
478
- SELECT ?, i.id FROM items i
479
- JOIN subscriptions s ON s.feed_id = i.feed_id AND s.user_id = ?
480
- WHERE i.id = ?
481
- ON CONFLICT (user_id, item_id) DO NOTHING`).run(userId, userId, itemId).changes;
512
+ if (!canAccessItem(userId, itemId))
513
+ return 0;
514
+ return db.prepare("INSERT INTO item_bookmarks (user_id, item_id) VALUES (?, ?) ON CONFLICT (user_id, item_id) DO NOTHING").run(userId, itemId).changes;
482
515
  }
483
516
  export function unbookmarkItem(userId, itemId) {
484
517
  return db.prepare("DELETE FROM item_bookmarks WHERE user_id = ? AND item_id = ?").run(userId, itemId).changes;
@@ -565,6 +598,8 @@ export function replaceFeedUrl(feedId, url) {
565
598
  export function moveSubscription(userId, fromFeedId, toFeedId) {
566
599
  db.transaction(() => {
567
600
  db.prepare("UPDATE subscriptions SET feed_id = ? WHERE user_id = ? AND feed_id = ?").run(toFeedId, userId, fromFeedId);
601
+ refreshFeedPollInterval(toFeedId);
602
+ refreshFeedPollInterval(fromFeedId);
568
603
  removeFeedIfUnused(fromFeedId);
569
604
  })();
570
605
  }
@@ -1,5 +1,6 @@
1
1
  import { config } from "../config.js";
2
- import { createFeed, findFeedByUrl, isUserSubscribed, subscribe, unsubscribe as unsubscribeRepo, findSubscriptionForUser, updateSubscriptionLabel, updateSubscriptionFolder, updateFeedPollInterval, updateSubscriptionFullTextMode, updateSubscriptionNotify, updateSubscriptionBadge, findFolderById, findFeedById, countFeedSubscribers, replaceFeedUrl, moveSubscription, } from "./repository.js";
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
4
  import { pollFeed, probeFeed } from "./poller.js";
4
5
  import { assertPublicFeedUrl } from "./blockedHosts.js";
5
6
  import { discoverFeeds } from "./discovery.js";
@@ -107,10 +108,9 @@ export function updateFeedSettings(userId, feedId, settings) {
107
108
  updateSubscriptionBadge(userId, feedId, settings.badge);
108
109
  }
109
110
  if (settings.pollIntervalMinutes !== undefined) {
110
- // The poll interval is stored per feed (shared across every subscriber),
111
- // so it's floored account-wide rather than trusting each caller's input.
111
+ // Stored per subscription; the feed polls at the shortest interval among its subscribers, never below the server minimum.
112
112
  const minutes = Math.max(settings.pollIntervalMinutes, config.minPollIntervalMinutes);
113
- updateFeedPollInterval(feedId, minutes);
113
+ updateSubscriptionPollInterval(userId, feedId, minutes);
114
114
  }
115
115
  const subscription = findSubscriptionForUser(userId, feedId);
116
116
  if (!subscription)
@@ -146,17 +146,22 @@ export async function changeFeedUrl(userId, feedId, inputUrl) {
146
146
  catch (error) {
147
147
  throw new FeedError(`feed_unreachable: ${error instanceof Error ? error.message : String(error)}`);
148
148
  }
149
- let previousItemsKept;
150
- if (!existing && countFeedSubscribers(feedId) === 1) {
151
- replaceFeedUrl(feedId, url);
152
- previousItemsKept = true;
153
- }
154
- else {
155
- const next = existing ?? createFeed(url, current.poll_interval_minutes);
149
+ // The probe takes a while: another account may have added this feed, or this person left the old one, in the meantime.
150
+ const previousItemsKept = db.transaction(() => {
151
+ if (!isUserSubscribed(userId, feedId))
152
+ throw new FeedError("not_subscribed");
153
+ const added = findFeedByUrl(url);
154
+ if (added && isUserSubscribed(userId, added.id))
155
+ throw new FeedError("already_subscribed");
156
+ if (!added && countFeedSubscribers(feedId) === 1) {
157
+ replaceFeedUrl(feedId, url);
158
+ return true;
159
+ }
160
+ const next = added ?? createFeed(url, current.poll_interval_minutes);
156
161
  moveSubscription(userId, feedId, next.id);
157
162
  target = next.id;
158
- previousItemsKept = false;
159
- }
163
+ return false;
164
+ })();
160
165
  const feed = findFeedById(target);
161
166
  if (feed)
162
167
  await pollFeed(feed);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.38.3",
3
+ "version": "0.38.5",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }