feedkeeper 0.42.4 → 0.42.6

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.42.4",
3
+ "version": "0.42.6",
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",
@@ -14,6 +14,7 @@ const updateRetentionSchema = z.object({
14
14
  retentionReadDays: z.number().int().min(0).max(3650).optional(),
15
15
  retentionMaxDays: z.number().int().min(0).max(3650).optional(),
16
16
  retentionMaxItemsPerFeed: z.number().int().min(0).max(100000).optional(),
17
+ retentionMinItemsPerFeed: z.number().int().min(0).max(10000).optional(),
17
18
  autoCleanupEnabled: z.boolean().optional(),
18
19
  });
19
20
  systemRouter.patch("/retention", (req, res) => {
@@ -72,6 +72,7 @@ v1Router.get("/meta", (_req, res) => {
72
72
  readDays: retention.retentionReadDays,
73
73
  maxDays: retention.retentionMaxDays,
74
74
  maxItemsPerFeed: retention.retentionMaxItemsPerFeed,
75
+ minItemsPerFeed: retention.retentionMinItemsPerFeed,
75
76
  protectActiveEdition: true,
76
77
  },
77
78
  },
@@ -33,6 +33,7 @@ export const config = {
33
33
  retentionReadDays: Number(process.env.RETENTION_READ_DAYS ?? 30),
34
34
  retentionMaxDays: Number(process.env.RETENTION_MAX_DAYS ?? 90),
35
35
  retentionMaxItemsPerFeed: Number(process.env.RETENTION_MAX_ITEMS_PER_FEED ?? 1000),
36
+ retentionMinItemsPerFeed: Number(process.env.RETENTION_MIN_ITEMS_PER_FEED ?? 30),
36
37
  autoCleanupEnabled: process.env.AUTO_CLEANUP_ENABLED !== "false",
37
38
  // Optional: only these hosts may register OAuth redirect URIs (comma-separated). Loopback addresses are always allowed.
38
39
  oauthAllowedRedirectHosts: (process.env.OAUTH_ALLOWED_REDIRECT_HOSTS ?? "")
@@ -0,0 +1,5 @@
1
+ -- Clear small user/org avatars stored as hero images (e.g. GitHub release/commit/activity Atom feeds).
2
+ UPDATE items
3
+ SET image_url = NULL
4
+ WHERE image_url LIKE 'https://avatars.githubusercontent.com/%'
5
+ OR image_url LIKE 'http://avatars.githubusercontent.com/%';
@@ -0,0 +1,4 @@
1
+ -- Migration 0047: Minimum items per feed exempt from age-based retention
2
+
3
+ INSERT OR IGNORE INTO system_settings (key, value) VALUES
4
+ ('retention_min_items_per_feed', '30');
@@ -40,6 +40,7 @@ export function getRetentionSettings() {
40
40
  retentionReadDays: Number(map.get("retention_read_days") ?? config.retentionReadDays),
41
41
  retentionMaxDays: Number(map.get("retention_max_days") ?? config.retentionMaxDays),
42
42
  retentionMaxItemsPerFeed: Number(map.get("retention_max_items_per_feed") ?? config.retentionMaxItemsPerFeed),
43
+ retentionMinItemsPerFeed: Number(map.get("retention_min_items_per_feed") ?? config.retentionMinItemsPerFeed),
43
44
  autoCleanupEnabled: (map.get("auto_cleanup_enabled") ?? String(config.autoCleanupEnabled)) === "true",
44
45
  };
45
46
  }
@@ -48,6 +49,7 @@ export function getRetentionSettings() {
48
49
  retentionReadDays: config.retentionReadDays,
49
50
  retentionMaxDays: config.retentionMaxDays,
50
51
  retentionMaxItemsPerFeed: config.retentionMaxItemsPerFeed,
52
+ retentionMinItemsPerFeed: config.retentionMinItemsPerFeed,
51
53
  autoCleanupEnabled: config.autoCleanupEnabled,
52
54
  };
53
55
  }
@@ -66,6 +68,9 @@ export function updateRetentionSettings(settings) {
66
68
  if (settings.retentionMaxItemsPerFeed !== undefined) {
67
69
  updateStmt.run("retention_max_items_per_feed", String(Math.max(0, settings.retentionMaxItemsPerFeed)));
68
70
  }
71
+ if (settings.retentionMinItemsPerFeed !== undefined) {
72
+ updateStmt.run("retention_min_items_per_feed", String(Math.max(0, settings.retentionMinItemsPerFeed)));
73
+ }
69
74
  if (settings.autoCleanupEnabled !== undefined) {
70
75
  updateStmt.run("auto_cleanup_enabled", String(settings.autoCleanupEnabled));
71
76
  }
@@ -100,7 +105,21 @@ export function runCleanup(custom) {
100
105
  let deletedReadItems = 0;
101
106
  let deletedOldItems = 0;
102
107
  let deletedPerFeedExcess = 0;
103
- // 1. Delete read items older than retentionReadDays (excluding bookmarked items and items with notes)
108
+ const minKeep = settings.retentionMinItemsPerFeed > 0 ? settings.retentionMinItemsPerFeed : null;
109
+ const minKeepClause = (idCol) => minKeep !== null
110
+ ? `AND ${idCol} NOT IN (
111
+ SELECT id FROM (
112
+ SELECT id, ROW_NUMBER() OVER (
113
+ PARTITION BY feed_id
114
+ ORDER BY COALESCE(julianday(published_at), julianday(created_at)) DESC, id DESC
115
+ ) AS rn
116
+ FROM items
117
+ )
118
+ WHERE rn <= ?
119
+ )`
120
+ : "";
121
+ const minKeepParams = minKeep !== null ? [minKeep] : [];
122
+ // 1. Delete read items older than retentionReadDays (excluding bookmarked items, notes, and the newest minKeep per feed)
104
123
  if (settings.retentionReadDays > 0) {
105
124
  deletedReadItems = retireItems(`id IN (
106
125
  SELECT i.id
@@ -117,16 +136,18 @@ export function runCleanup(custom) {
117
136
  AND NOT EXISTS (SELECT 1 FROM item_reads r WHERE r.item_id = i.id AND r.user_id = s.user_id)
118
137
  )
119
138
  AND COALESCE(julianday(i.published_at), julianday(i.created_at)) <= julianday('now', '-' || ? || ' days')
120
- )`, settings.retentionReadDays);
139
+ ${minKeepClause("i.id")}
140
+ )`, settings.retentionReadDays, ...minKeepParams);
121
141
  }
122
- // 2. Delete all items older than retentionMaxDays (excluding bookmarked items and items with notes)
142
+ // 2. Delete all items older than retentionMaxDays (excluding bookmarked items, notes, and the newest minKeep per feed)
123
143
  if (settings.retentionMaxDays > 0) {
124
144
  deletedOldItems = retireItems(`id NOT IN (SELECT item_id FROM item_bookmarks)
125
145
  AND id NOT IN (SELECT item_id FROM item_notes)
126
146
  AND feed_id NOT IN (SELECT id FROM feeds WHERE is_system_inbox = 1)
127
147
  AND id NOT IN (SELECT CAST(selected.value AS INTEGER) FROM editions e, json_each(e.item_ids) selected
128
148
  WHERE e.source = 'curated' AND e.status <> 'dismissed')
129
- AND COALESCE(julianday(published_at), julianday(created_at)) <= julianday('now', '-' || ? || ' days')`, settings.retentionMaxDays);
149
+ AND COALESCE(julianday(published_at), julianday(created_at)) <= julianday('now', '-' || ? || ' days')
150
+ ${minKeepClause("id")}`, settings.retentionMaxDays, ...minKeepParams);
130
151
  }
131
152
  // 3. Delete items exceeding retentionMaxItemsPerFeed (excluding bookmarked items and items with notes)
132
153
  if (settings.retentionMaxItemsPerFeed > 0) {
@@ -9,6 +9,7 @@ const xmlParser = new Parser({
9
9
  item: [
10
10
  ["media:content", "mediaContent", { keepArray: false }],
11
11
  ["media:thumbnail", "mediaThumbnail", { keepArray: false }],
12
+ ["media:group", "mediaGroup", { keepArray: false }],
12
13
  ["content:encoded", "contentEncoded", { keepArray: false }],
13
14
  ],
14
15
  },
@@ -19,6 +20,7 @@ function isRecord(value) {
19
20
  function asNonEmptyString(value) {
20
21
  return typeof value === "string" && value.trim() !== "" ? value : undefined;
21
22
  }
23
+ const MIN_FEED_IMAGE_SIDE = 100;
22
24
  function mediaAttribute(value, key) {
23
25
  if (!isRecord(value))
24
26
  return undefined;
@@ -26,9 +28,37 @@ function mediaAttribute(value, key) {
26
28
  return value.$[key];
27
29
  return value[key];
28
30
  }
31
+ function asMediaEntries(value) {
32
+ return Array.isArray(value) ? value : [value];
33
+ }
34
+ function parseDimension(value) {
35
+ if (typeof value === "number")
36
+ return Number.isFinite(value) && value > 0 ? value : null;
37
+ if (typeof value !== "string")
38
+ return null;
39
+ const match = /^\s*(\d+(?:\.\d+)?)\s*(?:px)?\s*$/i.exec(value);
40
+ if (!match)
41
+ return null;
42
+ const parsed = Number(match[1]);
43
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
44
+ }
45
+ function isTooSmallMedia(widthRaw, heightRaw) {
46
+ const width = parseDimension(widthRaw);
47
+ const height = parseDimension(heightRaw);
48
+ return (width !== null && width < MIN_FEED_IMAGE_SIDE) || (height !== null && height < MIN_FEED_IMAGE_SIDE);
49
+ }
29
50
  function cleanImageUrl(url) {
30
51
  return url.trim().replace(/&(?:#038|amp);/g, "&");
31
52
  }
53
+ export function isAvatarImageUrl(url) {
54
+ try {
55
+ const host = new URL(url.trim()).hostname.toLowerCase();
56
+ return host === "avatars.githubusercontent.com" || host.endsWith(".avatars.githubusercontent.com");
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ }
32
62
  function isValidImageUrl(url) {
33
63
  if (typeof url !== "string")
34
64
  return false;
@@ -44,39 +74,82 @@ function isValidImageUrl(url) {
44
74
  const host = parsed.hostname.toLowerCase();
45
75
  if (host === "pixel.wp.com" || host.endsWith(".pixel.wp.com"))
46
76
  return false;
77
+ if (isAvatarImageUrl(url))
78
+ return false;
47
79
  const pathAndQuery = (parsed.pathname + parsed.search).toLowerCase();
48
80
  if (pathAndQuery.includes("/1x1") || pathAndQuery.includes("pixel") || pathAndQuery.includes("tracking") || pathAndQuery.includes("beacon")) {
49
81
  return false;
50
82
  }
51
83
  return true;
52
84
  }
85
+ function htmlAttribute(tag, name) {
86
+ const match = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i").exec(tag);
87
+ return match ? (match[1] ?? match[2] ?? match[3]) : undefined;
88
+ }
53
89
  function firstHtmlImageUrl(html) {
54
90
  if (typeof html !== "string" || !html.includes("<img"))
55
91
  return null;
56
- const match = html.match(/<img[^>]+src=["'](https?:\/\/[^"'\s>]+)["']/i);
57
- return match && isValidImageUrl(match[1]) ? cleanImageUrl(match[1]) : null;
92
+ for (const [tag] of html.matchAll(/<img\b[^>]*>/gi)) {
93
+ const src = htmlAttribute(tag, "src");
94
+ if (!src)
95
+ continue;
96
+ const decodedSrc = decodeEntities(src);
97
+ if (!isValidImageUrl(decodedSrc))
98
+ continue;
99
+ if (isTooSmallMedia(htmlAttribute(tag, "width"), htmlAttribute(tag, "height")))
100
+ continue;
101
+ const classes = htmlAttribute(tag, "class") ?? "";
102
+ if (/\b(?:avatar|emoji|icon)\b/i.test(classes))
103
+ continue;
104
+ return cleanImageUrl(decodedSrc);
105
+ }
106
+ return null;
58
107
  }
59
- function extractXmlImageUrl(item) {
108
+ function extractMediaImageUrl(source) {
60
109
  // 1. media:content (Media RSS)
61
- const mediaContent = item.mediaContent ?? item["media:content"];
110
+ const mediaContent = source.mediaContent ?? source["media:content"];
62
111
  if (mediaContent) {
63
- if (isValidImageUrl(mediaContent))
64
- return cleanImageUrl(mediaContent);
65
- const url = mediaAttribute(mediaContent, "url");
66
- const medium = mediaAttribute(mediaContent, "medium");
67
- const type = mediaAttribute(mediaContent, "type");
68
- if (isValidImageUrl(url) && (medium === "image" || !medium || (typeof type === "string" && type.startsWith("image/")))) {
69
- return cleanImageUrl(url);
112
+ for (const entry of asMediaEntries(mediaContent)) {
113
+ if (isValidImageUrl(entry))
114
+ return cleanImageUrl(entry);
115
+ if (isTooSmallMedia(mediaAttribute(entry, "width"), mediaAttribute(entry, "height")))
116
+ continue;
117
+ const url = mediaAttribute(entry, "url");
118
+ const medium = mediaAttribute(entry, "medium");
119
+ const type = mediaAttribute(entry, "type");
120
+ if (isValidImageUrl(url) && (medium === "image" || !medium || (typeof type === "string" && type.startsWith("image/")))) {
121
+ return cleanImageUrl(url);
122
+ }
70
123
  }
71
124
  }
72
125
  // 2. media:thumbnail
73
- const mediaThumbnail = item.mediaThumbnail ?? item["media:thumbnail"];
126
+ const mediaThumbnail = source.mediaThumbnail ?? source["media:thumbnail"];
74
127
  if (mediaThumbnail) {
75
- if (isValidImageUrl(mediaThumbnail))
76
- return cleanImageUrl(mediaThumbnail);
77
- const url = mediaAttribute(mediaThumbnail, "url");
78
- if (isValidImageUrl(url))
79
- return cleanImageUrl(url);
128
+ for (const entry of asMediaEntries(mediaThumbnail)) {
129
+ if (isValidImageUrl(entry))
130
+ return cleanImageUrl(entry);
131
+ if (isTooSmallMedia(mediaAttribute(entry, "width"), mediaAttribute(entry, "height")))
132
+ continue;
133
+ const url = mediaAttribute(entry, "url");
134
+ if (isValidImageUrl(url))
135
+ return cleanImageUrl(url);
136
+ }
137
+ }
138
+ return null;
139
+ }
140
+ function extractXmlImageUrl(item) {
141
+ const direct = extractMediaImageUrl(item);
142
+ if (direct)
143
+ return direct;
144
+ const mediaGroup = item.mediaGroup ?? item["media:group"];
145
+ if (mediaGroup) {
146
+ for (const group of asMediaEntries(mediaGroup)) {
147
+ if (!isRecord(group))
148
+ continue;
149
+ const grouped = extractMediaImageUrl(group);
150
+ if (grouped)
151
+ return grouped;
152
+ }
80
153
  }
81
154
  // 3. enclosure
82
155
  if (item.enclosure?.url) {
@@ -2,6 +2,7 @@ import { config } from "../config.js";
2
2
  import { db } from "../db/index.js";
3
3
  import { articleText } from "./articleContent.js";
4
4
  import { LEAD_VERSION } from "./contentNoise.js";
5
+ import { isAvatarImageUrl } from "./feedParser.js";
5
6
  import { largerHeroImage } from "./heroImage.js";
6
7
  import { refreshGalleryClassification, refreshLead } from "./lead.js";
7
8
  import { decodeEntities, plainTitle } from "./text.js";
@@ -206,7 +207,8 @@ export function upsertItems(feedId, items) {
206
207
  // a feed that alternates between two variants would change the content on every poll.
207
208
  const keptPrevious = retained !== null && next !== retained;
208
209
  const nextSnippet = keptPrevious ? null : row.contentSnippet ?? null;
209
- const nextImage = largerHeroImage(row.imageUrl, retained, row.link ?? previous?.link ?? null) ?? previous?.image_url ?? row.imageUrl ?? null;
210
+ const reusablePreviousImage = previous?.image_url && !isAvatarImageUrl(previous.image_url) ? previous.image_url : null;
211
+ const nextImage = largerHeroImage(row.imageUrl, retained, row.link ?? previous?.link ?? null) ?? reusablePreviousImage ?? row.imageUrl ?? null;
210
212
  if (previous) {
211
213
  const changed = (row.title !== undefined && row.title !== previous.title) ||
212
214
  (row.link !== undefined && row.link !== previous.link) ||
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.42.4",
3
+ "version": "0.42.6",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }