修复: 添加原密码验证UI并修复中文文件名乱码
## 问题1: 修改密码缺少原密码验证UI
后端已有current_password验证,但前端没有输入框:
- 用户无法输入当前密码
- 导致密码修改功能无法正常使用
修复内容(前端):
1. app.html: 添加当前密码输入框
2. app.js:
- 添加current_password字段到data
- 添加current_password必填验证
- 请求体中包含current_password
- 成功后清空current_password
## 问题2: 中文文件名上传后乱码
原因:
- multer默认将文件名从UTF-8转换为Latin1编码
- req.file.originalname获取到的是乱码
修复内容(后端):
1. 配置multer.diskStorage自定义文件名处理
2. 在filename回调中将Latin1转回UTF-8:
Buffer.from(file.originalname, 'latin1').toString('utf8')
3. 在上传路由中同样转换originalname
4. 临时文件名使用时间戳+随机数+原始文件名避免冲突
影响范围:
- 所有文件上传操作
- 中文、日文、韩文等非ASCII文件名
测试建议:
- 上传中文文件名文件(如测试文档.pdf)
- 上传emoji文件名
- 修改密码功能完整流程测试
This commit is contained in:
@@ -840,9 +840,11 @@ app.post('/api/upload', authMiddleware, upload.single('file'), async (req, res)
|
||||
}
|
||||
|
||||
const remotePath = req.body.path || '/';
|
||||
// 修复中文文件名:multer将UTF-8转为了Latin1,需要转回来
|
||||
const originalFilename = Buffer.from(req.file.originalname, 'latin1').toString('utf8');
|
||||
const remoteFilePath = remotePath === '/'
|
||||
? `/${req.file.originalname}`
|
||||
: `${remotePath}/${req.file.originalname}`;
|
||||
? `/${originalFilename}`
|
||||
: `${remotePath}/${originalFilename}`;
|
||||
|
||||
let storage;
|
||||
|
||||
@@ -862,7 +864,7 @@ app.post('/api/upload', authMiddleware, upload.single('file'), async (req, res)
|
||||
res.json({
|
||||
success: true,
|
||||
message: '文件上传成功',
|
||||
filename: req.file.originalname,
|
||||
filename: originalFilename,
|
||||
path: remoteFilePath
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user