diff --git a/server.js b/server.js index 2605c73..2b6e88a 100644 --- a/server.js +++ b/server.js @@ -613,9 +613,11 @@ app.post('/api/ai/parse-catalog', requireAuth, aiLimiter, (req, res) => { try { tmpDir = fs.mkdtempSync(path.join(OCR_TMP_ROOT, 'catalog-ocr-')); const imagePaths = []; + const htmlTextParts = []; // HTML文件不用OCR,直接读文字内容(保留表格标签结构,AI能看懂rowspan这种分组关系) for (const file of req.files) { const isPdf = (file.mimetype || '').includes('pdf') || file.originalname.toLowerCase().endsWith('.pdf'); const isImage = (file.mimetype || '').startsWith('image/'); + const isHtml = (file.mimetype || '').includes('html') || /\.html?$/i.test(file.originalname); if (isPdf) { const pdfSubDir = fs.mkdtempSync(path.join(tmpDir, 'pdf-')); const pages = await renderPdfToImages(file.buffer, pdfSubDir); @@ -625,13 +627,24 @@ app.post('/api/ai/parse-catalog', requireAuth, aiLimiter, (req, res) => { const imgPath = path.join(tmpDir, `img_${imagePaths.length}${ext}`); fs.writeFileSync(imgPath, file.buffer); imagePaths.push(imgPath); + } else if (isHtml) { + const raw = file.buffer.toString('utf8'); + // 只去掉