读图压缩加无收益守卫:JPEG 重编码变大时不落盘、外链直指原图

- executor.readImageAsBlocks:sharp 产物 >= 原图时跳过 .imgcache 落盘,image_rel 指向原文件(与浏览器端压缩同款守卫,截图/线稿等低内容熵图不再越压越大)
- engine.mintImageUrl:image_rel 可能直指原文件后,签发公网链前补 realpath 复核(同 mint_public_link),防任务目录内指向外部的符号链接图片被签上公网
- smoke:vision 断言放宽为 image_rel 非空且文件存在(小尺寸测试图必然走无收益分支)
- ARCHITECTURE:read_file 条目同步守卫与 realpath 复核说明
This commit is contained in:
2026-09-21 22:01:37 +08:00
parent bca41f3c7e
commit 11716afdee
4 changed files with 21 additions and 8 deletions
+8
View File
@@ -142,6 +142,7 @@ function outlineWrapper(outlineText) {
// 用 sharp 压缩(按 EXIF 摆正、长边 ≤2000px、JPEG 质量 80)并落盘 .imgcache/。
// 成功返回 {text, image_rel};产物文件名带源文件指纹(mtime+size),同图重复读复用同一份不增殖。
// 无收益守卫(与浏览器端压缩同款):重编码 JPEG 反而 ≥ 原图时不落盘,image_rel 直指原文件。
// sharp 缺失或解码失败时退回纯文本提示,不让整个工具回合报错。
async function readImageAsBlocks(ctx, abs, rel, size) {
let sharp;
@@ -153,6 +154,13 @@ async function readImageAsBlocks(ctx, abs, rel, size) {
.resize({ width: IMG_MAX_SIDE, height: IMG_MAX_SIDE, fit: 'inside', withoutEnlargement: true })
.jpeg({ quality: IMG_JPEG_QUALITY })
.toBuffer({ resolveWithObject: true });
if (r.data.length >= size) {
// 低内容熵图(截图/线稿/纯色)JPEG 重编码可能比原图还大:不产出缓存,外链直接指向原文件
return {
text: '[图片文件] ' + rel + '(' + size + ' 字节,压缩无收益,按原图回传)',
image_rel: rel,
};
}
let st = null;
try { st = await fsp.stat(abs); } catch (_) {}
const stem = path.basename(rel).replace(/\.[^.]+$/, '').replace(/[^\w.\-\u4e00-\u9fff]/g, '_').slice(0, 60);