From 21f9824a24037917b05ffbbb06e140c689040210 Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 13 May 2026 21:09:39 +0800 Subject: [PATCH] feat: optimize /api/user/profile to return key fields for VIP status refresh --- src/routes/user.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/routes/user.js b/src/routes/user.js index 1fc4e52..b637ebd 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -6,11 +6,31 @@ const { downloadAndSaveAvatar } = require('../services/avatarService'); router.get('/profile', auth, async (req, res, next) => { try { - const user = await User.findById(req.user._id).select('-__v'); + const user = await User.findById(req.user._id) + .select('userId nickname avatarUrl status isVip vipExpireAt ocrCount ocrCountTotal platformLimit platformCount lastLoginAt'); + + if (!user) { + return res.status(404).json({ + success: false, + error: '用户不存在' + }); + } res.json({ success: true, - data: user + data: { + userId: user.userId, + nickname: user.nickname, + avatarUrl: user.avatarUrl, + status: user.status, + isVip: user.isVip, + vipExpireAt: user.vipExpireAt, + ocrCount: user.ocrCount, + ocrCountTotal: user.ocrCountTotal, + platformLimit: user.platformLimit, + platformCount: user.platformCount, + lastLoginAt: user.lastLoginAt + } }); } catch (error) { next(error);