Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix Pinterest sync pulling 0 pins from section URLs and entity-escaped feeds

[._.]/ Adam Eivy45e2a7c77141
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 2e0368dbdd..cd899ee1b2 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,7 @@
## Mood boards
+- **Fix: Pinterest sync pulled 0 pins from boards that actually had images.** Two bugs compounded. (1) Linking a board *section* URL (`/user/board/section/`) stored a `/user/board/section.rss` feed, but Pinterest serves no per-section RSS — that path returns its HTML page with a 200, which parsed to zero pins. Section URLs now collapse to the parent board's feed (the best available, since Pinterest has no section feed), keeping the section URL for display; already-linked section boards self-heal on the next sync. (2) Pinterest entity-escapes each pin's description HTML (`&lt;img src=…&gt;`) rather than wrapping it in CDATA, so the `<img>` fallback never matched the live feed and every pin was skipped; the parser now decodes the description before probing for the image. (`server/lib/pinterestFeed.js`, `server/services/moodBoard/pinterest.js`)
- **Import a Pinterest board into a mood board — link it once, then "Sync now" pulls new pins on demand.** Paste a public Pinterest board URL onto a mood board and PortOS fetches the board's RSS feed, downloads each pin's image into your own `data/images/` (so it federates with the board and survives Pinterest link rot), and pins it as an image item with the pin's title as the caption and its permalink as the source. Syncing is incremental: the first sync after linking pulls everything the feed exposes; later syncs add only pins it hasn't seen (deduped by permalink), and re-linking to a different board pulls that one down. NOTE: Pinterest's RSS exposes only the most-recent ~25 pins, not the entire board — the UI states this rather than implying a full backfill. Feed and image fetches go through a new shared SSRF-guarded fetcher (`server/lib/safeUrlFetch.js`), and the link rides the board record's JSONB so it federates with no schema-version bump. (`server/lib/pinterestFeed.js`, `server/services/moodBoard/pinterest.js`, `server/routes/moodBoard.js`, `client/src/pages/MoodBoardDetail.jsx`)
## Creative onramp
diff --git a/server/lib/pinterestFeed.js b/server/lib/pinterestFeed.js
index b68ecdee0d..f7fada1ad8 100644
--- a/server/lib/pinterestFeed.js
+++ b/server/lib/pinterestFeed.js
@@ -46,9 +46,19 @@ const badUrl = (msg) => new ServerError(msg, { status: 400, code: 'INVALID_PINTE
/**
* Normalize a user-supplied Pinterest board URL (or an already-`.rss` feed URL)
- * into `{ feedUrl, boardUrl }`. Accepts the human board URL and appends `.rss`;
- * passes a `.rss` URL through. Throws a 400 ServerError for a non-URL, a
- * non-http(s) scheme, a non-Pinterest host, or a board-less root path.
+ * into `{ feedUrl, boardUrl, isSection }`. Accepts the human board URL and
+ * appends `.rss`; passes a `.rss` URL through. Throws a 400 ServerError for a
+ * non-URL, a non-http(s) scheme, a non-Pinterest host, or a board-less root path.
+ *
+ * Pinterest exposes an RSS feed ONLY for a top-level board (`/user/board.rss`),
+ * NOT for a board *section* (`/user/board/section/`). Appending `.rss` to a
+ * section path returns Pinterest's HTML page with a 200 (content-type text/html,
+ * zero `<item>`s), which silently parses to 0 pins. So when the URL points at a
+ * section (3+ path segments), we collapse the FEED to the parent board's RSS
+ * while preserving the section URL the user pasted as `boardUrl` (for display /
+ * "view on Pinterest"). The feed then returns the whole board's recent pins —
+ * the best available, since Pinterest has no per-section feed — and `isSection`
+ * lets callers surface that the sync isn't section-scoped.
*/
export function normalizePinterestFeedUrl(input) {
if (typeof input !== 'string' || !input.trim()) {
@@ -69,11 +79,17 @@ export function normalizePinterestFeedUrl(input) {
throw badUrl('Include the board path, e.g. pinterest.com/user/board');
}
const isRss = path.toLowerCase().endsWith('.rss');
- const feedPath = isRss ? path : `${path}.rss`;
- const boardPath = isRss ? path.slice(0, -'.rss'.length) : path;
+ // Logical (no `.rss`) path → segments. A section is anything deeper than
+ // /<user>/<board>; the RSS feed always lives at the first two segments.
+ const logicalPath = isRss ? path.slice(0, -'.rss'.length) : path;
+ const segments = logicalPath.split('/').filter(Boolean);
+ const isSection = segments.length > 2;
+ const feedPath = isSection ? `/${segments.slice(0, 2).join('/')}.rss` : `${logicalPath}.rss`;
+ // Keep the section path the user pasted as the displayed board URL.
return {
feedUrl: `https://${host}${feedPath}`,
- boardUrl: `https://${host}${boardPath}/`,
+ boardUrl: `https://${host}${logicalPath}/`,
+ isSection,
};
}
@@ -137,14 +153,18 @@ export function parsePinterestRss(xml) {
for (const block of blocks) {
const pinUrl = decodeEntities(extractTag(block, 'link') || extractTag(block, 'guid'));
const rawDescription = extractTag(block, 'description');
- const found = decodeEntities(extractImageUrl(block, rawDescription));
+ // Pinterest entity-escapes the description's HTML (`&lt;img src=&quot;…&quot;&gt;`)
+ // rather than wrapping it in CDATA, so decode it before probing for the <img>;
+ // a no-op when the feed already ships a literal <img> (CDATA) tag.
+ const decodedDescription = decodeEntities(rawDescription);
+ const found = decodeEntities(extractImageUrl(block, decodedDescription));
if (!pinUrl || !found) continue;
pins.push({
pinUrl,
imageUrl: upgradePinImageSize(found),
imageUrlOriginal: found,
title: stripHtml(extractTag(block, 'title')).slice(0, 500),
- description: stripHtml(rawDescription).slice(0, 500),
+ description: stripHtml(decodedDescription).slice(0, 500),
pubDate: extractTag(block, 'pubDate'),
});
}
diff --git a/server/lib/pinterestFeed.test.js b/server/lib/pinterestFeed.test.js
index 4e82d51f17..4290cbecff 100644
--- a/server/lib/pinterestFeed.test.js
+++ b/server/lib/pinterestFeed.test.js
@@ -11,6 +11,7 @@ describe('normalizePinterestFeedUrl', () => {
expect(normalizePinterestFeedUrl('https://www.pinterest.com/jane/cyberpunk/')).toEqual({
feedUrl: 'https://www.pinterest.com/jane/cyberpunk.rss',
boardUrl: 'https://www.pinterest.com/jane/cyberpunk/',
+ isSection: false,
});
});
@@ -18,6 +19,24 @@ describe('normalizePinterestFeedUrl', () => {
expect(normalizePinterestFeedUrl('https://www.pinterest.com/jane/cyberpunk.rss')).toEqual({
feedUrl: 'https://www.pinterest.com/jane/cyberpunk.rss',
boardUrl: 'https://www.pinterest.com/jane/cyberpunk/',
+ isSection: false,
+ });
+ });
+
+ it('collapses a board-section URL to the parent board feed (Pinterest has no section RSS)', () => {
+ // A section path (3+ segments) has no RSS; appending .rss returns HTML → 0 pins.
+ expect(normalizePinterestFeedUrl('https://www.pinterest.com/jane/cyberpunk/neon-alleys/')).toEqual({
+ feedUrl: 'https://www.pinterest.com/jane/cyberpunk.rss',
+ boardUrl: 'https://www.pinterest.com/jane/cyberpunk/neon-alleys/',
+ isSection: true,
+ });
+ });
+
+ it('collapses a section .rss URL to the parent board feed too', () => {
+ expect(normalizePinterestFeedUrl('https://www.pinterest.com/jane/cyberpunk/neon-alleys.rss')).toEqual({
+ feedUrl: 'https://www.pinterest.com/jane/cyberpunk.rss',
+ boardUrl: 'https://www.pinterest.com/jane/cyberpunk/neon-alleys/',
+ isSection: true,
});
});
@@ -78,6 +97,22 @@ describe('parsePinterestRss', () => {
});
});
+ it('extracts the img from an entity-escaped description (live feed shape, no CDATA)', () => {
+ // Pinterest escapes the description HTML with entities instead of CDATA.
+ const xml = wrap([item(`
+ <title>点击查看大图</title>
+ <link>https://www.pinterest.com/pin/201465783329049465/</link>
+ <description>&lt;a href=&quot;https://www.pinterest.com/pin/201465783329049465/&quot;&gt;&lt;img src=&quot;https://i.pinimg.com/236x/a2/6a/00/a26a00dc0156784e3ab7188b95301bcd.jpg&quot;&gt;&lt;/a&gt;</description>
+ `)]);
+ const pins = parsePinterestRss(xml);
+ expect(pins).toHaveLength(1);
+ expect(pins[0]).toMatchObject({
+ pinUrl: 'https://www.pinterest.com/pin/201465783329049465/',
+ imageUrl: 'https://i.pinimg.com/736x/a2/6a/00/a26a00dc0156784e3ab7188b95301bcd.jpg',
+ imageUrlOriginal: 'https://i.pinimg.com/236x/a2/6a/00/a26a00dc0156784e3ab7188b95301bcd.jpg',
+ });
+ });
+
it('prefers <media:content> over an <img>, and decodes &amp; in URLs', () => {
const xml = wrap([item(`
<link>https://www.pinterest.com/pin/222/</link>
diff --git a/server/services/moodBoard/pinterest.js b/server/services/moodBoard/pinterest.js
index c8b185eec6..a4e9a41866 100644
--- a/server/services/moodBoard/pinterest.js
+++ b/server/services/moodBoard/pinterest.js
@@ -66,10 +66,10 @@ async function downloadPinImage({ pinUrl, imageUrl, imageUrlOriginal }) {
* normalizes the URL (throws 400 on a non-Pinterest host) and stores the link.
*/
export async function linkPinterestBoard(boardId, { url }) {
- const { feedUrl, boardUrl } = normalizePinterestFeedUrl(url);
+ const { feedUrl, boardUrl, isSection } = normalizePinterestFeedUrl(url);
const board = await store.setPinterestLink(boardId, { feedUrl, boardUrl });
emitRecordUpdated('moodBoard', boardId);
- console.log(`📌 Pinterest link set: board ${boardId} → ${feedUrl}`);
+ console.log(`📌 Pinterest link set: board ${boardId} → ${feedUrl}${isSection ? ' (section URL — feed covers the whole board; Pinterest has no per-section RSS)' : ''}`);
return board;
}
@@ -86,10 +86,21 @@ export async function unlinkPinterestBoard(boardId) {
* unreachable).
*/
export async function syncPinterestBoard(boardId) {
- const board = await store.getBoard(boardId);
+ let board = await store.getBoard(boardId);
if (!board) throw new ServerError('Mood board not found', { status: 404, code: 'NOT_FOUND' });
- const feedUrl = board.pinterest?.feedUrl;
- if (!feedUrl) throw new ServerError('This board is not linked to a Pinterest board', { status: 400, code: 'NOT_LINKED' });
+ if (!board.pinterest?.feedUrl) throw new ServerError('This board is not linked to a Pinterest board', { status: 400, code: 'NOT_LINKED' });
+
+ // Self-heal links saved before section detection: a section URL was stored with
+ // a `/user/board/section.rss` feed that Pinterest serves as HTML (0 pins). Re-
+ // normalize the stored link (preferring the displayed boardUrl, which retains
+ // the section path) and persist the corrected board-level feed in place.
+ const { feedUrl: healedFeedUrl, boardUrl: healedBoardUrl } =
+ normalizePinterestFeedUrl(board.pinterest.boardUrl || board.pinterest.feedUrl);
+ if (healedFeedUrl !== board.pinterest.feedUrl) {
+ board = await store.setPinterestLink(boardId, { feedUrl: healedFeedUrl, boardUrl: healedBoardUrl });
+ console.log(`📌 Pinterest sync: board ${boardId} feed corrected to ${healedFeedUrl} (section URL has no RSS)`);
+ }
+ const feedUrl = board.pinterest.feedUrl;
const xml = await fetchPublicText(feedUrl, { timeoutMs: FEED_TIMEOUT_MS, headers: FEED_HEADERS });
if (!xml) throw new ServerError('Could not fetch the Pinterest feed (it may be private or rate-limited)', { status: 502, code: 'FEED_FETCH_FAILED' });