Skip to content

feat(share): add Open Graph preview for social media crawlers#3234

Merged
HFO4 merged 3 commits intocloudreve:masterfrom
WittF:dev/share-og-preview
Jan 25, 2026
Merged

feat(share): add Open Graph preview for social media crawlers#3234
HFO4 merged 3 commits intocloudreve:masterfrom
WittF:dev/share-og-preview

Conversation

@WittF
Copy link
Copy Markdown
Contributor

@WittF WittF commented Jan 24, 2026

Summary

Warning

Only respects group-level share access permission (Cloudreve Pro share-level permissions not supported).

Enable rich previews when sharing Cloudreve links on Discord, Twitter, Telegram, etc.

Clean rewrite of #3227.

Preview

State Title Description
File {file_name} {size} · {owner}
Folder {folder_name} Folder · {owner}
Password {site_name} Password Required
Login {site_name} Login Required
Invalid {site_name} Invalid Link
Discord X/Twitter

Closes #3226


Note

Enable rich Open Graph previews for shared resources on social platforms.

  • Add middleware/SharePreview to detect social media bots and render an OG HTML page for /s/:id(/:password) and /home?path=share: links, sourcing site settings/icons and share info without counting views; includes folder/file status, owner, file size, and thumbnail when available
  • Register SharePreview in master router before FrontendFileHandler and static gzip; sets appropriate headers and client redirect
  • Extend explorer.Share response with size (for unlocked file shares) to support preview details
  • Minor import reordering in inventory/share.go

Written by Cursor Bugbot for commit daba550. This will update automatically on new commits. Configure here.

Add middleware to intercept social media bot requests and return
OG meta tags for share links, enabling rich previews on platforms
like Facebook, Twitter, Discord, etc.
@WittF
Copy link
Copy Markdown
Contributor Author

WittF commented Jan 24, 2026

Subpath previews (?path=xxx) were considered but not implemented. Distinguishing files from folders requires a DB query, and most shares don't need path-level previews.

@HFO4
Copy link
Copy Markdown
Member

HFO4 commented Jan 25, 2026

Subpath previews (?path=xxx) were considered but not implemented. Distinguishing files from folders requires a DB query, and most shares don't need path-level previews.

That's fine, only previews for root level is sufficient.

@HFO4
Copy link
Copy Markdown
Member

HFO4 commented Jan 25, 2026

Thanks a lot, this one looks much better. I also pushed changes to reuse some of existing service, and show file thumbnails for single shared file if possible.
Please take a look, we can merge this now if you're OK with it.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.


if t == types.FileTypeFile && s.Edges.File != nil {
res.Size = s.Edges.File.Size
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File size may display as zero if edge not loaded

Medium Severity

The Size field in BuildShare is only populated when s.Edges.File != nil, which requires the file edge to be eagerly loaded via the LoadShareFile{} context key. If ShareInfoService doesn't set this key, the file edge won't be loaded, Size remains 0, and the OG preview description will incorrectly display "0 B" for all file shares instead of the actual file size.

Additional Locations (1)

Fix in Cursor Fix in Web

@WittF
Copy link
Copy Markdown
Contributor Author

WittF commented Jan 25, 2026

Thanks a lot, this one looks much better. I also pushed changes to reuse some of existing service, and show file thumbnails for single shared file if possible.非常感谢,这个看起来好多了。我还推送了修改,重用部分现有服务,并尽可能显示单个共享文件的缩略图。 Please take a look, we can merge this now if you're OK with it.请看看,如果你同意,我们现在可以合并。

Sure, looks good to me. 👍
The thumbnail looks great too. Images with extreme aspect ratios (e.g., 1000x100) look a bit off on some platforms (like Discord), but you can click to enlarge, so no biggie.
image

@HFO4 HFO4 merged commit e4e6beb into cloudreve:master Jan 25, 2026
2 of 3 checks passed
@HFO4
Copy link
Copy Markdown
Member

HFO4 commented Jan 25, 2026

Thanks a lot!

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.

public share link preview in apps such as discord, slack, MS teams, whatsapp.

2 participants