Bundle
dsh-attachment-downscale
附件自动降级:DSH 图片准入(单边 ≤2000px / ≤3.5MB / ≤4000万像素)超限图片不再拒绝,用 sharp 自动缩小/重编码后入库,用户上传手机原图不再踩线。
- Source
- zoumutou
- stars
- 1 stars
- License
- MIT
- Updated
- Updated 13 days ago
Readme
# dsh-attachment-downscale
DSH 图片附件准入对超限图片(单边 >2000px / 单图 >3.5MB / 像素超 4000 万)直接拒绝,
上传手机原图时体验很差。本插件在 **attachments 服务入口**(`saveImages`)把超限图片
用 sharp 自动降级后再入库:
- 超尺寸 → 等比缩放到限制内(长边 ≤2000px)
- 缩放后仍超字节数 → 同格式降质(jpeg/webp 质量阶梯),仍不行转 webp
- 多帧动图(GIF/WebP)跳过不处理,避免破坏动画
- 处理失败 → 直通原准入逻辑(维持原拒绝行为),绝不吞错误
入库后图片恒满足准入限制,模型请求 / vision-bridge / 历史导出拿到的都是合规文件。
## 安装
```bash
# 本地开发
npm run build # 或 dev_build_plugin
# 装入 web profile(热生效,免重启):
# dev_install_package /Users/zoumutou/coded/dsh-attachment-downscale web
# 生产(npm 发布后)
dsh plugin --profile web add dsh-attachment-downscale
# 或 GitHub 装配
dsh plugin --profile web add github:zoumutou/dsh-attachment-downscale
```
## 市场上架
- npm 包带 `dsh-plugin` 关键词,GitHub 仓库打 `dsh-plugin` 话题后,社区市场
(dsh-suite 每小时刷新 / chnjames dsh-plugin-market 实时查询)自动收录,无需 PR。
- Release 附件:`npm pack` 产出 `dsh-attachment-downscale-<version>.tgz`。
## 配置
插件行支持 `config`:
```yaml
- insert:
- name: dsh-attachment-downscale
config:
enabled: true # 关闭后恢复原拒绝行为
quality: 82 # 重编码质量(jpeg/webp)
# 以下缺省跟随 attachments 服务自身的准入限制:
# maxImageDimension: 2000
# maxImageBytes: 3670016
# maxImagePixels: 40000000
```
## 测试
```bash
node test/normalize.test.mjs
```
Install
dsh plugin --profile web add github:zoumutou/dsh-attachment-downscale
Profile: web
With the hub plugin installed, ask your agent to install it by name — it resolves the same plan shown here.
dsh plugin --profile web add github:stvlynn/dsh.fish#path:packages/dsh-plugin-hub
install dsh-attachment-downscale from the hub
- This package builds from source on install. pnpm will ask you to allow its build script — that is permission to run the package’s code on your machine, outside the agent sandbox. Only allow sources you trust.
- This source has no pinned commit, so a later push upstream changes what installs. Prefer pinning a commit.