实现腾讯通用票据OCR安全适配(07-28-travel-reimbursement-guide)
这个提交包含在:
@@ -9,7 +9,11 @@ const { compactDateString } = require("../utils/date");
|
||||
const { sha256Hex } = require("../utils/crypto");
|
||||
const { toMoneyString } = require("../utils/workflow");
|
||||
const { findActiveDelegationForDelegate } = require("../utils/delegation");
|
||||
const { getMissingRequiredOcrFields, isOcrEnabledForType } = require("../services/ocr");
|
||||
const {
|
||||
OCR_PDF_MAX_BYTES,
|
||||
getMissingRequiredOcrFields,
|
||||
isOcrEnabledForType,
|
||||
} = require("../services/ocr");
|
||||
const { enqueueOcrInvoice } = require("../jobs/pgBossJobs");
|
||||
const { registerInvoiceVerificationRoutes } = require("./invoicePool/verification");
|
||||
const { registerInvoicePoolReadRoutes } = require("./invoicePool/read");
|
||||
@@ -353,6 +357,11 @@ async function invoicePoolRoutes(fastify) {
|
||||
let fileMimeType = null;
|
||||
let fileSize = 0;
|
||||
const fields = {};
|
||||
const configuredUploadMaxBytes = Number(fastify.config.maxUploadSizeBytes);
|
||||
const invoiceUploadMaxBytes =
|
||||
Number.isFinite(configuredUploadMaxBytes) && configuredUploadMaxBytes > 0
|
||||
? Math.min(configuredUploadMaxBytes, OCR_PDF_MAX_BYTES)
|
||||
: OCR_PDF_MAX_BYTES;
|
||||
|
||||
try {
|
||||
for await (const part of request.parts()) {
|
||||
@@ -380,12 +389,21 @@ async function invoicePoolRoutes(fastify) {
|
||||
const chunks = [];
|
||||
for await (const chunk of part.file) {
|
||||
fileSize += chunk.length;
|
||||
if (fileSize > fastify.config.maxUploadSizeBytes) {
|
||||
if (fileSize > invoiceUploadMaxBytes) {
|
||||
throw new AppError({
|
||||
code: "VALID_001",
|
||||
message: "参数校验失败",
|
||||
message:
|
||||
invoiceUploadMaxBytes === OCR_PDF_MAX_BYTES
|
||||
? "PDF 发票不能超过 7 MiB"
|
||||
: "参数校验失败",
|
||||
statusCode: 400,
|
||||
details: { file: "file_too_large" },
|
||||
details: {
|
||||
file:
|
||||
invoiceUploadMaxBytes === OCR_PDF_MAX_BYTES
|
||||
? "ocr_pdf_too_large"
|
||||
: "file_too_large",
|
||||
maxBytes: invoiceUploadMaxBytes,
|
||||
},
|
||||
});
|
||||
}
|
||||
chunks.push(chunk);
|
||||
|
||||
在新工单中引用
屏蔽一个用户