Introduction

DSH’s core philosophy is “everything is a plugin.” In the attachments service entry point saveImages, if an uploaded image violates the original admission limits (longest side > 2000px, single image > 3.5MB, or pixels > 40 million), the system rejects it directly. This results in a very poor experience when users upload full-resolution smartphone images, often being blocked for compliance.

This plugin intercepts these oversized images before persistence, uses sharp to automatically downgrade them, and ensures that stored images always satisfy the admission limits, so model requests, vision-bridge, and history exports can all obtain compliant files.

Plugin Overview

  • Name: dsh-attachment-downscale
  • One-liner: DSH plugin: automatic downscaling of oversized image attachments (longest side ≤ 2000px / single image ≤ 3.5MB / pixels ≤ 40 million)
  • Maintainer: zoumutou
  • Category: Workflow
  • License: MIT

Core Features

The plugin processes images at the saveImages entry point and provides the following capabilities:

  1. Automatic proportional scaling for oversized images: Prioritizes scaling the longest side to within 2000px.
  2. Re-encoding compression: If the image still exceeds limits after scaling, applies progressive quality reduction (quality ladder) to jpeg/webp formats.
  3. Format fallback: If re-encoding fails, automatically converts to webp format.
  4. Skip animated images: Multi-frame animated images (GIF/WebP) are skipped directly to avoid breaking animation effects.
  5. Error handling: On processing failure, falls through to the original admission logic (preserving the original rejection behavior) and never swallows errors.
  6. Compliance guarantee: Stored images always satisfy the admission limits.

Installation and Enablement

The plugin depends on @deepseek-ai/cordis and sharp.

Local development build:

npm run build

Install into the web profile (hot-applied, no restart required):

dev_install_package /Users/zoumutou/coded/dsh-attachment-downscale web

Production installation:

dsh plugin --profile web add github:zoumutou/dsh-attachment-downscale

Configuration

The plugin supports adjusting behavior through the config field:

- insert:
    - name: dsh-attachment-downscale
      config:
        enabled: true      # 关闭后恢复原拒绝行为
        quality: 82        # 重编码质量(jpeg/webp)
        # 以下缺省值跟随 attachments 服务自身的准入限制:
        # maxImageDimension: 2000
        # maxImageBytes: 3670016
        # maxImagePixels: 40000000

Ecosystem and Marketplace

  • Dependency environment: Runs inside the DSH process; ensure the environment includes @deepseek-ai/cordis and sharp.
  • Marketplace inclusion: The npm package must include the dsh-plugin keyword, and the GitHub repository must have the dsh-plugin topic tag. The community marketplace (dsh-suite or standalone marketplace) will index it automatically, without manually submitting a PR.
  • Package publishing: Running npm pack generates a .tgz file.

Conclusion

By preprocessing at the saveImages entry point, this plugin resolves the conflict between strict admission rules and user upload behavior, ensuring that images processed by downstream systems remain compliant. The complete catalog and source code are available via the links below.