@wendongfly/myhi 1.3.195 → 1.3.196

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/chat.html CHANGED
@@ -7092,13 +7092,17 @@
7092
7092
  const img = new Image(); const url = URL.createObjectURL(srcBlob);
7093
7093
  const blob = await new Promise((resolve, reject) => {
7094
7094
  img.onload = () => { URL.revokeObjectURL(url); let {width:w, height:h} = img;
7095
- // 压缩策略:长边限制 768px,JPEG 质量 0.7,适合截图分析且降低图片累积压力
7096
- const M = 768;
7097
- if(w>M||h>M){if(w>=h){h=Math.round(h*M/w);w=M}else{w=Math.round(w*M/h);h=M}}
7095
+ // 压缩策略:长边 ≤1568px 且总像素 ≤1.15MP(Claude 视觉的原生上限,再大也会被模型侧缩小),
7096
+ // JPEG 质量 0.85 —— 768px/0.7 时截图里的小字糊到模型认不出
7097
+ const M = 1568, P = 1.15e6;
7098
+ const s = Math.min(1, M / Math.max(w, h), Math.sqrt(P / (w * h)));
7099
+ w = Math.round(w * s); h = Math.round(h * s);
7098
7100
  const c=document.createElement('canvas');c.width=w;c.height=h;c.getContext('2d').drawImage(img,0,0,w,h);
7099
- c.toBlob(b=>b?resolve(b):reject(new Error('toBlob failed')),'image/jpeg',0.7); };
7101
+ c.toBlob(b=>b?resolve(b):reject(new Error('toBlob failed')),'image/jpeg',0.85); };
7100
7102
  img.onerror=reject; img.src=url; });
7101
- const form = new FormData(); form.append('image', blob, filename || 'image.jpg');
7103
+ // 输出恒为 JPEG:扩展名跟着改,免得 paste.png 里装 JPEG 导致按扩展名判类型的下游报错
7104
+ const base = (filename || 'image').replace(/\.[^.]+$/, '');
7105
+ const form = new FormData(); form.append('image', blob, base + '.jpg');
7102
7106
  const res = await fetch(`/upload?sessionId=${SESSION_ID}`, { method: 'POST', body: form });
7103
7107
  const data = await res.json();
7104
7108
  if (!data.path) throw new Error(data.error || '上传失败');