Skip to content

fix(hub): make inline markdown image URLs absolute when caching remote notes - #1258

Closed
luoliguang wants to merge 1 commit into
blinkospace:mainfrom
luoliguang:pr/fix-hub-image-401
Closed

luoliguang wants to merge 1 commit into
blinkospace:mainfrom
luoliguang:pr/fix-hub-image-401

Conversation

@luoliguang

Copy link
Copy Markdown

Problem

Images embedded inline in note content (markdown ![]() syntax or HTML <img> tags) show as 401 Unauthorized when viewed in the Hub recommend tab.

Example console errors:

GET https://viewer.example.com/api/file/root/blinko-data/IMG_9398.JPG  401 (Unauthorized)

Root cause

RecommandJob already rewrites attachments[].path to absolute URLs:

path: `${url.origin}${a.path}`

But inline images in the content markdown string are not rewritten. When the hub renders the cached note, the viewer's browser resolves /api/file/… against the viewer's own server — which has no token for the remote site's files.

Fix

After rewriting attachments, also rewrite relative /api/file/ references in the content string:

// markdown: ![alt](/api/file/…) → ![alt](https://remote.site/api/file/…)
newItem.content = newItem.content.replace(
  /(!\[[^\]]*\]\()(\/api\/file\/[^)]+)(\))/g,
  (_, open, path, close) => `${open}${url.origin}${path}${close}`
);
// HTML: <img src="/api/file/…"> → <img src="https://remote.site/api/file/…">
newItem.content = newItem.content.replace(
  /(<img\s[^>]*src=["'])(\/api\/file\/[^"']+)(["'][^>]*>)/g,
  (_, open, path, close) => `${open}${url.origin}${path}${close}`
);

Steps to reproduce

  1. Follow a remote Blinko site that has notes with inline images
  2. Open Hub → 推荐 (Recommend tab)
  3. Observe 401 errors in the browser console for every inline image

…e notes

The RecommandJob already rewrites attachment paths to absolute URLs, but
inline images embedded directly in note content (markdown `![]()` syntax
and HTML `<img>` tags) were left as relative `/api/file/…` paths.

When the hub renders those cached notes the viewer's browser resolves the
relative paths against the viewer's own server, which has no token for
the remote site's files → 401 Unauthorized for every inline image.

Fix: after rewriting attachments, also rewrite relative `/api/file/`
references in the content string to include the remote site's origin.
@luoliguang luoliguang closed this Oct 6, 2026
@luoliguang
luoliguang deleted the pr/fix-hub-image-401 branch October 6, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant