mirror of
https://github.com/patdelphi/suanming.git
synced 2026-02-27 21:23:12 +08:00
fix: resolve user ID validation issue in yijing analysis
- Fixed overly strict user ID validation that rejected string IDs - Added proper type conversion from string to integer for user IDs - Ensured compatibility with both string and numeric user ID formats - Prevents 'Invalid User ID' error for legitimate users
This commit is contained in:
@@ -154,7 +154,9 @@ router.post('/yijing', authenticate, asyncHandler(async (req, res) => {
|
||||
|
||||
// 验证用户ID
|
||||
const targetUserId = user_id || req.user.id;
|
||||
if (!Number.isInteger(targetUserId) || targetUserId <= 0) {
|
||||
const numericUserId = typeof targetUserId === 'string' ? parseInt(targetUserId, 10) : targetUserId;
|
||||
|
||||
if (!numericUserId || isNaN(numericUserId) || numericUserId <= 0) {
|
||||
throw new AppError('用户ID无效', 400, 'INVALID_USER_ID');
|
||||
}
|
||||
|
||||
@@ -162,7 +164,7 @@ router.post('/yijing', authenticate, asyncHandler(async (req, res) => {
|
||||
// 执行易经分析(纯分析,不存储历史记录)
|
||||
const analysisResult = yijingAnalyzer.performYijingAnalysis({
|
||||
question: question.trim(),
|
||||
user_id: targetUserId,
|
||||
user_id: numericUserId,
|
||||
divination_method: divination_method || 'time',
|
||||
user_timezone: user_timezone,
|
||||
local_time: local_time
|
||||
|
||||
Reference in New Issue
Block a user