Web验收拍照识别 + 修上传失败
① Web 验收拍照/拖入后自动 AI 识别(复用库存入库识别,预填 规格/生产日期/保质期/产地,只补空、切单丢弃过期响应,零新增文案)。 ② 修「拍照后上传失败」:根因是照片 dataURL 内联在提交体,而全局 express.json 仅 2mb 且照片不降尺寸/质量 0.92 ⇒ 大图必 413。 甲:照片先降尺寸再画水印(≤1600px / q0.8,对齐小程序); 丙:仅把 /api/workflow/inspection/submit 体上限放宽到 20mb。 ③ 小程序逐张上传单张失败不中断整批 + 汇总提示。 新增契约测试;门禁与全量回归对基线。
This commit is contained in:
@@ -62,7 +62,16 @@ function readFileAsDataUrl(file: File): Promise<string> {
|
||||
});
|
||||
}
|
||||
|
||||
const INSPECTION_PHOTO_JPEG_QUALITY = 0.92;
|
||||
/**
|
||||
* 验收存档照片上限:最长边 ≤1600px、JPEG 质量 0.8 —— 与小程序 `utils/orderImage.js`
|
||||
* (`MAX_DIMENSION = 1600` / `COMPRESS_QUALITY = 80`)**同口径**。
|
||||
*
|
||||
* 为什么必须降尺寸:Web 验收把照片作为 **dataURL 内联**在提交体里(`POST /inspection/submit`),
|
||||
* 而全局 `express.json({ limit: '2mb' })` ⇒ 原图不缩 + 质量 0.92 时,一张 5MB 原图可达 4~6MB,
|
||||
* 直接 413「上传失败」(同族先例见 docs/design/20260921-quality-report-upload-multer-channel.md)。
|
||||
*/
|
||||
export const INSPECTION_PHOTO_MAX_DIMENSION = 1600;
|
||||
const INSPECTION_PHOTO_JPEG_QUALITY = 0.8;
|
||||
|
||||
export async function loadOrientedCanvasFromFile(file: File): Promise<HTMLCanvasElement> {
|
||||
if (typeof createImageBitmap === 'function') {
|
||||
@@ -101,7 +110,26 @@ export async function renderInspectionPhotoWithWatermark(
|
||||
file: File,
|
||||
meta: { orderCode?: string; branchName?: string }
|
||||
): Promise<string> {
|
||||
const canvas = await loadOrientedCanvasFromFile(file);
|
||||
const source = await loadOrientedCanvasFromFile(file);
|
||||
/**
|
||||
* ⚠️ 顺序:**先降尺寸、再画水印**。
|
||||
* 若先画水印再缩,水印字会被一起缩小到不可读;降尺寸后画,水印相对更清晰。
|
||||
*/
|
||||
const maxSide = Math.max(source.width, source.height);
|
||||
const scale =
|
||||
maxSide > INSPECTION_PHOTO_MAX_DIMENSION ? INSPECTION_PHOTO_MAX_DIMENSION / maxSide : 1;
|
||||
let canvas = source;
|
||||
if (scale < 1) {
|
||||
const resized = document.createElement('canvas');
|
||||
resized.width = Math.max(1, Math.round(source.width * scale));
|
||||
resized.height = Math.max(1, Math.round(source.height * scale));
|
||||
const resizedContext = resized.getContext('2d');
|
||||
if (!resizedContext) {
|
||||
throw new Error('浏览器不支持图片处理');
|
||||
}
|
||||
resizedContext.drawImage(source, 0, 0, resized.width, resized.height);
|
||||
canvas = resized;
|
||||
}
|
||||
const context = canvas.getContext('2d');
|
||||
if (!context) {
|
||||
throw new Error('浏览器不支持图片处理');
|
||||
|
||||
Reference in New Issue
Block a user