feat: TurboHR 14项优化与功能增强
- #1 Dashboard风险提醒增加立刻办理按钮 - #2 Calendar月份选择器改为input month - #3 Termination增加7种解聘原因法律依据和操作步骤 - #5 合同审查支持PDF TXT格式 - #6 AI合同审查prompt优化为具体修改建议 - #7 知识库添加更新机制说明 - #9 SpecialStatus员工选择改用all-lite接口 - #10 Termination增加详细法律条款引用 - #11 Money发薪批次增加社保公积金合计列 - #12 EmployeeAttachment扩展文件类型 - #13 花名册增加女职工干部工人选项加退休提醒 - #14 新增公司备用文件上传模块
This commit is contained in:
@@ -957,7 +957,7 @@ const reviewUpload = multer({
|
||||
limits: { fileSize: 100 * 1024 * 1024 },
|
||||
fileFilter: (_req, file, cb) => {
|
||||
const ext = path.extname(file.originalname).toLowerCase()
|
||||
if (ext !== '.docx' && ext !== '.doc') {
|
||||
if (ext !== '.docx' && ext !== '.txt' && ext !== '.pdf') {
|
||||
return cb(null, false)
|
||||
}
|
||||
cb(null, true)
|
||||
@@ -967,15 +967,27 @@ const reviewUpload = multer({
|
||||
router.post('/review/upload', authMiddleware, reviewUpload.single('file'), async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
if (!req.file) {
|
||||
return res.status(400).json({ success: false, error: { code: 'NO_FILE', message: '请上传 .docx 文件' } })
|
||||
return res.status(400).json({ success: false, error: { code: 'NO_FILE', message: '请上传 .docx / .txt / .pdf 文件' } })
|
||||
}
|
||||
const ext = path.extname(req.file.originalname).toLowerCase()
|
||||
let text = ''
|
||||
if (ext === '.docx') {
|
||||
const result = await mammoth.extractRawText({ buffer: req.file.buffer })
|
||||
text = result.value
|
||||
} else if (ext === '.txt') {
|
||||
text = req.file.buffer.toString('utf-8')
|
||||
} else if (ext === '.pdf') {
|
||||
// PDF 简单文本提取:提取括号内的文本流内容
|
||||
const raw = req.file.buffer.toString('latin1')
|
||||
const textMatches = raw.match(/\(([^)]+)\)/g)
|
||||
if (textMatches) {
|
||||
text = textMatches.map(m => m.slice(1, -1).replace(/\\[nrt()\\]/g, ' ')).join(' ')
|
||||
}
|
||||
if (!text || text.trim().length < 10) {
|
||||
return res.status(400).json({ success: false, error: { code: 'PDF_PARSE_FAIL', message: 'PDF 文件无法提取文本,可能是扫描件或图片格式。建议将文件另存为 .docx 后上传' } })
|
||||
}
|
||||
} else {
|
||||
return res.status(400).json({ success: false, error: { code: 'UNSUPPORTED', message: '暂不支持 .doc 格式,请将文件另存为 .docx 后上传' } })
|
||||
return res.status(400).json({ success: false, error: { code: 'UNSUPPORTED', message: '暂不支持该格式,请上传 .docx / .txt / .pdf 文件' } })
|
||||
}
|
||||
if (text.length > 50000) {
|
||||
text = text.slice(0, 50000) + '\n\n[文本过长,已截断]'
|
||||
|
||||
Reference in New Issue
Block a user