dsh-inline-image
v1.0.0
Published
DeepSeek Harness (DSH) plugin: serve whitelisted local images over a same-origin route so assistant markdown can embed them / 本地图片内联插件
Maintainers
Readme
dsh-inline-image
在 DeepSeek Harness(DSH)对话中内联本地图片。 插件把白名单目录内的本地图片通过同源 GET 路由对外提供,助手回复的标准 Markdown 图片语法即可直接显示磁盘上的图片——无需上传、无需搬运文件:
工作原理
- 在 DSH web 服务器上注册
GET /api/inline-image?path=<绝对路径>(经webServer服务)。 - 只有位于白名单根目录下的文件才会被提供,其余一律
403。 - 助手消息里的标准 Markdown 图片语法即可渲染。
安装
dsh plugin --profile web add dsh-inline-image或手动方式:在 profile 的 package.json(~/.dsh/profiles/<profile>/package.json)中把
"dsh-inline-image": "^1.0.0" 加入 dependencies,把 "dsh-inline-image" 加入
dsh.profile.bundles,然后重装 profile。
配置
默认值:allowedRoots = 整个文件系统(全盘放行),maxBytes = 64 MB。
在 profile 的 cordis.patch.yml(~/.dsh/profiles/<profile>/cordis.patch.yml)中覆盖:
- id: inline-image
config:
allowedRoots:
- /Volumes/Data
- /Users/you/Pictures
maxBytes: 104857600环境变量覆盖(优先级最高;分隔符为 path.delimiter,macOS/Linux 下是 :):
export DSH_INLINE_IMAGE_ROOTS=/Volumes/Data:/Users/you/Pictures优先级:DSH_INLINE_IMAGE_ROOTS > allowedRoots 配置 > 默认全盘。
allowedRoots 留空时回落到默认全盘(POSIX 下等价于白名单写 /)。
要允许所有目录,显式配置 allowedRoots: ['/'] 即可。
支持格式
.png .jpg .jpeg .gif .webp .svg —— TIFF 浏览器无法显示,请先转成 PNG。
安全模型
| 检查项 | 行为 |
| --- | --- |
| 请求方法 | 仅 GET —— 其余 405 |
| 来源 | 仅同源 —— 跨源请求 403 |
| 白名单 | 请求路径必须解析到允许的根目录之下 —— 否则 403 |
| 符号链接 | realpath 收敛校验:符号链接无法逃出白名单(白名单根本身是符号链接亦可正常使用) |
| 类型 | 扩展名白名单(PNG/JPEG/GIF/WebP/SVG),以真实路径为准 —— 否则 415 |
| 大小 | maxBytes 上限 —— 超限 413 |
| 响应头 | 所有响应带 X-Content-Type-Options: nosniff;SVG 额外带 Content-Security-Policy: sandbox |
| 缓存 | 图片 Cache-Control: private, max-age=300;JSON 错误 no-store |
错误以 JSON 返回 —— { "error": "<原因>" } —— 状态码 400/403/405/413/415。
默认白名单是整个文件系统:凡能访问你 DSH web 服务器的客户端都能读取磁盘上的图片文件。
单用户本机使用没问题;共享或多用户环境请把 allowedRoots 收得尽量窄。
API
GET /api/inline-image?path=<URL 编码的绝对路径>
→ 200 图片字节流 | 4xx JSON 错误许可
MIT © Samuel Lu
