修复(08-28-reimbursement-detail-material-preview-fixes): 收紧撤回展示并校正材料图片尺寸

这个提交包含在:
2026-08-28 21:53:26 +08:00
父节点 f178aa0de3
当前提交 46bfa7e00f
共修改 14 个文件,包含 342 行新增和 13 行删除
@@ -24,15 +24,14 @@ function materialCollectionHash(materials, mergerVersion) {
async function normalizeImageForPdf(source, limits) {
const image = sharp(source, { failOn: "error", limitInputPixels: limits.maxImagePixels }).rotate();
const metadata = await image.metadata();
if (!metadata.width || !metadata.height || metadata.width * metadata.height > limits.maxImagePixels) {
throw new Error("material_preview_image_invalid");
}
const normalized = await image
const { data: normalized, info } = await image
.flatten({ background: "#ffffff" })
.jpeg({ quality: 90, chromaSubsampling: "4:4:4", mozjpeg: false })
.toBuffer();
return { buffer: normalized, width: metadata.width, height: metadata.height };
.toBuffer({ resolveWithObject: true });
if (!info.width || !info.height || info.width * info.height > limits.maxImagePixels) {
throw new Error("material_preview_image_invalid");
}
return { buffer: normalized, width: info.width, height: info.height };
}
function fitPage(width, height) {
@@ -3,7 +3,7 @@ const path = require("node:path");
const { Worker } = require("node:worker_threads");
const { materialCollectionHash } = require("./reimbursementMaterialPdf");
const MATERIAL_PREVIEW_MERGER_VERSION = "pdf-v1";
const MATERIAL_PREVIEW_MERGER_VERSION = "pdf-v2";
const MATERIAL_PREVIEW_LIMITS = Object.freeze({
maxMaterials: 20,
maxSourceBytes: 50 * 1024 * 1024,