fix(ssa): harden spreadsheet upload recognition and guidance
Fix SSA data-context generation for Excel uploads by parsing xlsx/xls via extension-aware paths instead of UTF-8 fallback. Add on-demand overview rebuild in Agent flow, align xls friendly prompts on frontend/backend, and surface backend upload errors to users. Made-with: Cursor
This commit is contained in:
@@ -50,13 +50,27 @@ export default async function sessionRoutes(app: FastifyInstance) {
|
||||
if (data) {
|
||||
const buffer = await data.toBuffer();
|
||||
const filename = data.filename;
|
||||
const ext = filename.split('.').pop()?.toLowerCase() || '';
|
||||
|
||||
if (ext === 'xls') {
|
||||
return reply.status(400).send({
|
||||
error: '系统为了保证表格解析的稳定性,当前仅支持 .xlsx / .csv 格式。请您在本地 Excel/WPS 中打开该文件,选择“另存为 -> Excel 工作簿 (.xlsx)”后再次上传。',
|
||||
});
|
||||
}
|
||||
|
||||
const allowedExt = new Set(['csv', 'xlsx']);
|
||||
if (!allowedExt.has(ext)) {
|
||||
return reply.status(400).send({
|
||||
error: `不支持的文件类型: .${ext || 'unknown'}。当前支持:.csv、.xlsx`,
|
||||
});
|
||||
}
|
||||
|
||||
const baseName = filename.replace(/\.(csv|xlsx?)$/i, '') || '数据';
|
||||
const now = new Date();
|
||||
title = `${baseName} ${now.getMonth() + 1}月${now.getDate()}日`;
|
||||
|
||||
// 生成存储 Key(遵循 OSS 目录结构规范)
|
||||
const uuid = crypto.randomUUID().replace(/-/g, '').substring(0, 16);
|
||||
const ext = filename.split('.').pop()?.toLowerCase() || 'csv';
|
||||
dataOssKey = `tenants/${tenantId}/users/${userId}/ssa/${uuid}.${ext}`;
|
||||
|
||||
// 上传到 OSS
|
||||
|
||||
Reference in New Issue
Block a user