feedkeeper 0.28.4 → 0.28.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.28.4",
3
+ "version": "0.28.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",
@@ -42,17 +42,17 @@
42
42
  "better-sqlite3": "^13.0.3",
43
43
  "cookie-session": "^2.1.1",
44
44
  "cors": "^2.8.6",
45
- "dotenv": "^18.0.5",
45
+ "dotenv": "^18.0.8",
46
46
  "express": "^5.2.1",
47
47
  "express-rate-limit": "^8.7.1",
48
48
  "fast-xml-parser": "^5.11.2",
49
49
  "helmet": "^8.3.0",
50
50
  "ipaddr.js": "^2.5.0",
51
- "jsdom": "^30.1.2",
51
+ "jsdom": "^30.1.3",
52
52
  "node-cron": "^4.6.0",
53
53
  "otpauth": "^9.5.2",
54
54
  "rss-parser": "^3.13.0",
55
- "undici": "^8.11.2",
55
+ "undici": "^8.12.2",
56
56
  "web-push": "^3.6.7",
57
57
  "zod": "^4.6.5"
58
58
  }
@@ -1,4 +1,5 @@
1
1
  import crypto from "node:crypto";
2
+ import zlib from "node:zlib";
2
3
  import { Resvg } from "@resvg/resvg-js";
3
4
  import { extractLargestImageAsPng } from "@humanwhocodes/ico-to-png";
4
5
  import { db } from "../db/index.js";
@@ -36,8 +37,11 @@ function candidates(feed, declaredUrls) {
36
37
  urls.add(feed.icon_url);
37
38
  for (const source of [feed.site_url, feed.url]) {
38
39
  try {
39
- if (source)
40
- urls.add(`${new URL(source).origin}/favicon.ico`);
40
+ if (source) {
41
+ const origin = new URL(source).origin;
42
+ urls.add(`${origin}/apple-touch-icon.png`);
43
+ urls.add(`${origin}/favicon.ico`);
44
+ }
41
45
  }
42
46
  catch {
43
47
  // Try the next source.
@@ -45,6 +49,79 @@ function candidates(feed, declaredUrls) {
45
49
  }
46
50
  return [...urls];
47
51
  }
52
+ /** Rejects 8-bit grayscale+alpha or RGBA PNGs whose alpha channel is 0 across every pixel. */
53
+ function hasVisiblePngPixels(buffer) {
54
+ if (buffer.length < 33)
55
+ return false;
56
+ const width = buffer.readUInt32BE(16);
57
+ const height = buffer.readUInt32BE(20);
58
+ const bitDepth = buffer[24];
59
+ const colorType = buffer[25];
60
+ const interlace = buffer[28];
61
+ if (width < 1 || height < 1)
62
+ return false;
63
+ if (colorType === 0 || colorType === 2)
64
+ return true;
65
+ if (interlace !== 0 || bitDepth !== 8 || (colorType !== 4 && colorType !== 6))
66
+ return true;
67
+ const chunks = [];
68
+ let pos = 8;
69
+ while (pos + 8 <= buffer.length) {
70
+ const len = buffer.readUInt32BE(pos);
71
+ const type = buffer.toString("ascii", pos + 4, pos + 8);
72
+ if (pos + 12 + len > buffer.length)
73
+ break;
74
+ if (type === "IDAT")
75
+ chunks.push(buffer.subarray(pos + 8, pos + 8 + len));
76
+ pos += 12 + len;
77
+ }
78
+ if (chunks.length === 0)
79
+ return true;
80
+ try {
81
+ const raw = zlib.inflateSync(Buffer.concat(chunks), { finishFlush: zlib.constants.Z_SYNC_FLUSH });
82
+ const bpp = colorType === 6 ? 4 : 2;
83
+ const stride = width * bpp + 1;
84
+ const prev = new Uint8Array(width * bpp);
85
+ const curr = new Uint8Array(width * bpp);
86
+ for (let y = 0; y < height; y++) {
87
+ const rowStart = y * stride;
88
+ if (rowStart + stride > raw.length)
89
+ break;
90
+ const filter = raw[rowStart];
91
+ for (let i = 0; i < width * bpp; i++) {
92
+ const x = raw[rowStart + 1 + i];
93
+ const a = i >= bpp ? curr[i - bpp] : 0;
94
+ const b = prev[i];
95
+ const c = i >= bpp ? prev[i - bpp] : 0;
96
+ let val = x;
97
+ if (filter === 1)
98
+ val = (x + a) & 0xff;
99
+ else if (filter === 2)
100
+ val = (x + b) & 0xff;
101
+ else if (filter === 3)
102
+ val = (x + ((a + b) >> 1)) & 0xff;
103
+ else if (filter === 4) {
104
+ const p = a + b - c;
105
+ const pa = Math.abs(p - a);
106
+ const pb = Math.abs(p - b);
107
+ const pc = Math.abs(p - c);
108
+ const pr = pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
109
+ val = (x + pr) & 0xff;
110
+ }
111
+ curr[i] = val;
112
+ }
113
+ for (let px = bpp - 1; px < width * bpp; px += bpp) {
114
+ if (curr[px] > 0)
115
+ return true;
116
+ }
117
+ prev.set(curr);
118
+ }
119
+ return false;
120
+ }
121
+ catch {
122
+ return true;
123
+ }
124
+ }
48
125
  /** Keep the same raster icon in every client, including clients without SVG or ICO support. */
49
126
  function rasterIcon(buffer, mime) {
50
127
  if (mime === "image/svg+xml") {
@@ -52,13 +129,18 @@ function rasterIcon(buffer, mime) {
52
129
  if (svg.width > 4096 || svg.height > 4096 || svg.width < 1 || svg.height < 1 ||
53
130
  svg.width / svg.height > 8 || svg.height / svg.width > 8)
54
131
  throw new Error("Invalid SVG icon size");
55
- return { buffer: svg.render().asPng(), mime: "image/png" };
132
+ buffer = svg.render().asPng();
133
+ mime = "image/png";
56
134
  }
57
- if (mime === "image/x-icon") {
135
+ else if (mime === "image/x-icon") {
58
136
  const image = extractLargestImageAsPng(buffer);
59
137
  if (!image)
60
138
  throw new Error("Invalid ICO icon");
61
- return { buffer: Buffer.from(image.data), mime: "image/png" };
139
+ buffer = Buffer.from(image.data);
140
+ mime = "image/png";
141
+ }
142
+ if (mime === "image/png" && !hasVisiblePngPixels(buffer)) {
143
+ throw new Error("Blank transparent icon");
62
144
  }
63
145
  return { buffer, mime };
64
146
  }
@@ -62,8 +62,24 @@ export function iconCheckDue(checkedAt) {
62
62
  }
63
63
  /** Include a linked web-app manifest, which often contains the site's highest-resolution icons. */
64
64
  export async function discoverIconUrls(siteUrl, signal) {
65
+ const discovered = await discoverPageIconUrls(siteUrl, signal);
66
+ if (discovered.length > 0)
67
+ return discovered;
68
+ // Many feeds set `<channel><link>` to their own feed URL instead of the site homepage.
65
69
  try {
66
- const page = await fetchFeed(siteUrl, { signal });
70
+ const parsed = new URL(siteUrl);
71
+ if (parsed.pathname !== "/" && parsed.pathname !== "") {
72
+ return await discoverPageIconUrls(`${parsed.origin}/`, signal);
73
+ }
74
+ }
75
+ catch {
76
+ // Ignore invalid URLs.
77
+ }
78
+ return [];
79
+ }
80
+ async function discoverPageIconUrls(pageUrl, signal) {
81
+ try {
82
+ const page = await fetchFeed(pageUrl, { signal });
67
83
  const candidates = declaredCandidates(page.body, page.finalUrl);
68
84
  const manifestTag = headLinks(page.body).find((tag) => attribute(tag, "rel")?.toLowerCase().split(/\s+/).includes("manifest"));
69
85
  const href = manifestTag && attribute(manifestTag, "href");
@@ -101,6 +101,7 @@ function extractOutlines(node, items = [], currentFolder) {
101
101
  }
102
102
  return items;
103
103
  }
104
+ export const MAX_OPML_FEEDS = 2000;
104
105
  /**
105
106
  * Parses an OPML document string and returns a list of feed URLs and their labels.
106
107
  */
@@ -114,7 +115,11 @@ export function parseOpml(xmlContent) {
114
115
  if (!parsed || !parsed.opml || !parsed.opml.body) {
115
116
  throw new Error("invalid_opml_format");
116
117
  }
117
- return extractOutlines(parsed.opml.body.outline);
118
+ const feeds = extractOutlines(parsed.opml.body.outline);
119
+ if (feeds.length > MAX_OPML_FEEDS) {
120
+ throw new Error("too_many_opml_feeds");
121
+ }
122
+ return feeds;
118
123
  }
119
124
  const urlSchema = z.string().url();
120
125
  /**
@@ -26,6 +26,7 @@ function mediaAttribute(value, key) {
26
26
  }
27
27
  const parser = new Parser({
28
28
  customFields: {
29
+ feed: ["icon"],
29
30
  item: [
30
31
  ["media:content", "mediaContent", { keepArray: false }],
31
32
  ["media:thumbnail", "mediaThumbnail", { keepArray: false }],
@@ -33,6 +34,25 @@ const parser = new Parser({
33
34
  ],
34
35
  },
35
36
  });
37
+ function extractFeedIconUrls(parsed, baseUrl) {
38
+ if (!parsed)
39
+ return [];
40
+ const urls = [];
41
+ for (const raw of [parsed.icon, parsed.image?.url]) {
42
+ if (typeof raw !== "string" || !raw.trim())
43
+ continue;
44
+ try {
45
+ const resolved = new URL(raw.trim(), baseUrl);
46
+ if (resolved.protocol === "https:" || resolved.protocol === "http:") {
47
+ urls.push(resolved.toString());
48
+ }
49
+ }
50
+ catch {
51
+ // Ignore malformed feed icon URLs.
52
+ }
53
+ }
54
+ return urls;
55
+ }
36
56
  function cleanImageUrl(url) {
37
57
  return url.trim().replace(/&#038;/g, "&").replace(/&amp;/g, "&");
38
58
  }
@@ -134,9 +154,10 @@ async function pollAttempt(feed, signal) {
134
154
  if (iconCheckDue(feed.icon_checked_at)) {
135
155
  updateFeedIcon(feed.id, feed.icon_url);
136
156
  const siteUrl = parsed?.link || feed.site_url;
137
- const urls = siteUrl ? await discoverIconUrls(siteUrl, signal) : [];
157
+ const htmlUrls = siteUrl ? await discoverIconUrls(siteUrl, signal) : [];
158
+ const feedUrls = extractFeedIconUrls(parsed, siteUrl || feed.url);
138
159
  signal.throwIfAborted();
139
- await refreshFeedIcon(feed.id, siteUrl, urls, signal);
160
+ await refreshFeedIcon(feed.id, siteUrl, [...htmlUrls, ...feedUrls], signal);
140
161
  }
141
162
  }
142
163
  catch { /* Keep the successful poll; icon failures are best effort. */ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.28.4",
3
+ "version": "0.28.6",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }