Repository navigation
feat(siyuan): 支持自定义思源笔记接口地址 - #1370
Merged
DiamondYuan merged 1 commit intoNov 17, 2026
Merged
Conversation
- 思源笔记账号配置新增「接口地址」,默认仍为 http://127.0.0.1:6806/, 可填写局域网、远端、反向代理或其它端口地址 - ServiceMeta.permission 支持函数式配置,改为按当前账号的地址动态计算 host 权限,避免远端账号切换时一直提示 No Permission - 地址统一规整(自动补协议、去掉重复末尾斜杠),正文图片前缀与内置图床 上传都使用配置的地址 - 新增「授权」按钮,申请自定义地址的 host 权限后自动重新校验账号 - 修复 Windows 下 less loader include 正则不匹配导致的构建失败 - 新增思源地址规整与客户端请求的单测
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
背景
思源笔记的服务地址目前硬编码在
clients/siyuan/client.ts(SIYUAN_BASE_URL = 'http://127.0.0.1:6806/'),只能剪藏到本机默认端口上的内核,无法指向局域网内的另一台机器、云主机、反向代理或其它端口。改动
http://127.0.0.1:6806/,可填写任意 http/https 地址ServiceMeta.permission支持函数式配置(ServicePermission),由getServicePermission()统一解析;思源按当前账号的地址动态计算 host 权限。这一层必须改,否则远端账号切换时contains会判为无权限,而request只能申请本地 origin,会陷入「一直提示 No Permission」normalizeSiyuanBaseUrl()统一地址(缺协议补http://、去掉重复末尾斜杠);createNote的图片前缀、uploadImage、内置图床都使用同一地址useOriginPermission返回授权结果并去掉末尾斜杠(避免生成http://h:6806//*这种非法匹配模式)backend.services.siyuan.form.origin与...form.authenticationinclude正则只匹配/的问题,改为[\\/](原正则导致 Windows + pnpm 构建报Module parse failed)兼容性
http://localhost:6806/*和http://127.0.0.1:6806/*optional_host_permissions已包含http://*/*、https://*/*、<all_urls>,因此任意地址都能在运行时申请权限,无需改动 manifest验证
tsc --noEmit:与改动前的基线逐条比对,无新增报错(仓库本身存在既有的 node_modules 类型告警,构建走 transpileOnly)vitest run:34 passed / 4 skipped,其中新增的 8 个思源用例全部通过webpack --config webpack/webpack.prod.js:0 error,产物 16 个文件POST /api/notebook/lsNotebooks在127.0.0.1:6806与localhost:6806(不同 origin)均返回code: 0(另:该分支也发布了一个可直接安装的构建产物 https://github.com/kuler86/web-clipper/releases/tag/v1.42.0-siyuan 便于试用)