feat: improve share page link generation with smart routing #361
+148
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description / 描述
Improve share page link generation with smart internal/external network routing.
改进分享页链接生成,支持智能内外网分流。
Changes / 更改
Smart Routing (
useLink.ts) / 智能分流Use
location.originfor automatic network routing:ol.example.com→ links useol.example.com192.168.x.x→ links use192.168.x.xNo configuration needed - works automatically based on how user accesses the site
使用
location.origin实现自动网络分流:ol.example.com→ 链接使用ol.example.com192.168.x.x→ 链接使用192.168.x.x无需配置,根据用户访问方式自动生效
Single File Share Fix / 单文件分享修复
Added
extractSharingId()andextractPathAfterSid()helper functionsCorrectly handle single file shares (avoid path duplication like
/sd/sid/file.mp3/file.mp3)Fixed URL format:
/sd/{sid}/for single file,/sd/{sid}/path/to/filefor folder shares添加
extractSharingId()和extractPathAfterSid()辅助函数正确处理单文件分享(避免路径重复如
/sd/sid/file.mp3/file.mp3)修复URL格式:单文件使用
/sd/{sid}/,文件夹分享使用/sd/{sid}/path/to/fileCopy Link Improvement / 复制链接改进
On share pages, "Copy Link" now copies the current page URL (shareable)
On regular pages, still copies the direct download link
分享页面上,"复制链接"现在复制当前页面URL(可分享)
普通页面上,仍复制直接下载链接
Settings Loading (
App.tsx) / 设置加载Added initial loading state to ensure settings are loaded before rendering
添加初始加载状态,确保设置在渲染前加载完成
Motivation and Context / 背景
When OpenList is deployed behind a reverse proxy, users access it via different URLs (internal IP vs external domain). Previously, share page resources always used the configured external domain, even from internal network, causing slow speeds. Now links automatically use the correct domain based on how the user accesses the site.
当 OpenList 部署在反向代理后面时,用户通过不同URL访问(内网IP vs 外网域名)。之前分享页资源总是使用配置的外网域名,即使从内网访问也是如此,导致速度慢。现在链接会根据用户访问方式自动使用正确的域名。
Configuration Recommendation / 配置建议
For optimal smart routing, leave
site_urlempty in config. The backend will automatically use the request's Host header for URL generation.为了最佳智能分流效果,将配置中的
site_url留空。后端会自动使用请求的 Host 头生成URL。How Has This Been Tested? / 测试
Checklist / 检查清单