29 lines
773 B
JavaScript
29 lines
773 B
JavaScript
// 验证房间创建请求
|
|
const validateRoom = (req, res, next) => {
|
|
const { title, streamerName } = req.body;
|
|
|
|
// 验证标题
|
|
if (!title || typeof title !== 'string' || title.trim().length === 0) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: { code: 'VALIDATION_ERROR', message: '标题不能为空' }
|
|
});
|
|
}
|
|
|
|
// 验证主播名称
|
|
if (!streamerName || typeof streamerName !== 'string' || streamerName.trim().length === 0) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: { code: 'VALIDATION_ERROR', message: '主播名称不能为空' }
|
|
});
|
|
}
|
|
|
|
// 清理输入
|
|
req.body.title = title.trim();
|
|
req.body.streamerName = streamerName.trim();
|
|
|
|
next();
|
|
};
|
|
|
|
module.exports = { validateRoom };
|