Skip to content

feat: 重构压缩 API 为 responseMode 无状态契约#5

Merged
zzgosh merged 3 commits intomainfrom
codex/api-optimization
Mar 6, 2026
Merged

feat: 重构压缩 API 为 responseMode 无状态契约#5
zzgosh merged 3 commits intomainfrom
codex/api-optimization

Conversation

@zzgosh
Copy link
Copy Markdown
Owner

@zzgosh zzgosh commented Mar 5, 2026

变更概述

POST /api/image-compress/v1/compress 从“成功直接返回二进制(语义藏在 headers)”重构为更适合自动化编排的无状态接口:

  • 新增显式 responseMode=metadata|binary(默认 metadata
  • metadata:仅返回结构化 JSON 元信息(success/compressed/outcome/reason + 体积统计 + results[]),便于 Shortcuts/脚本/Agent 做稳定 if/else
  • binary:继续流式返回单图或 ZIP;headers 仅作为辅助信息,并补充 X-Compressed / X-Outcome

说明:HTTP 200 仅表示请求处理成功,不代表一定变小;请以 compressed/outcome 判断。

契约更新

  • OpenAPI:补齐 CompressMetadataResponse(single/zip 两种 schema)以及 responseMode 参数说明
  • README:补齐 responseMode 用法与 cURL 示例

回归验证

  • npm run check && npm run build
  • curl:
    • ?responseMode=metadata 检查 JSON 字段(尤其是 compressed/outcome/reason
    • ?responseMode=binary 检查单图/多图 ZIP、Content-Disposition 与辅助 headers

zzgosh added 2 commits March 5, 2026 18:13
- 支持 responseMode=metadata|binary(默认 metadata),解耦业务判断与文件响应\n- metadata 返回结构化 JSON:success/compressed/outcome/reason + 体积统计 + results[]\n- binary 继续流式返回单图或 ZIP,并补充 X-Compressed/X-Outcome 等辅助 headers\n- 同步更新 OpenAPI 与 README
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 92edd64b92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- 恢复带 EXIF Orientation 的图片在方向归一化后不回退原图\n- 按真实 fallback 状态返回 compressed/outcome/reason\n- 补充回归测试并同步更新 README 与 OpenAPI
@zzgosh
Copy link
Copy Markdown
Owner Author

zzgosh commented Mar 6, 2026

@codex reviewer the new commit

@chatgpt-codex-connector
Copy link
Copy Markdown

Summary

  • Added a reusable helper to build multipart payloads with multiple files parts, so mixed-outcome multi-file route behavior can be tested in one request path. tests/compress.test.tsL90-L110
  • Added a new regression test that verifies top-level metadata outcome aggregation for mixed results (one rotated file kept as processed output + one non-rotated fallback), asserting compressed=true and outcome=compressed. tests/compress.test.tsL223-L265
  • Extended the same mixed-case test to verify binary mode headers (X-Compressed, X-Outcome) remain consistent with the aggregated outcome logic. tests/compress.test.tsL266-L279
  • Committed the follow-up change on the current branch (fa7b034) and created a PR via make_pr titled: test: add regression coverage for mixed compressed/fallback summary outcome.

Testing

  • npm test
  • npm run check && npm run build
  • ⚠️ curl -L 'https://duckduckgo.com/html/?q=sharp+rotate+exif+orientation+output+larger+fallback' -o /tmp/web_search.html && wc -c /tmp/web_search.html (network/proxy restriction: CONNECT tunnel failed, response 403)

View task →

@zzgosh zzgosh merged commit 7371f3f into main Mar 6, 2026
1 check passed
@zzgosh zzgosh deleted the codex/api-optimization branch March 6, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant