Files
bigwo/test2/server/routes/assistantProfile.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

const express = require('express');
const router = express.Router();
const { getAssistantProfile, clearAssistantProfileCache } = require('../services/assistantProfileService');
router.get('/', async (req, res) => {
try {
const userId = String(req.query.userId || '').trim() || null;
const forceRefresh = String(req.query.forceRefresh || '').trim() === 'true';
const result = await getAssistantProfile({ userId, forceRefresh });
res.json({
code: 0,
message: 'success',
success: true,
data: {
userId,
profile: result.profile,
source: result.source,
cached: result.cached,
fetchedAt: result.fetchedAt,
configured: result.configured,
error: result.error,
},
});
} catch (error) {
console.error('[AssistantProfile] query failed:', error.message);
res.status(500).json({
code: 500,
message: error.message,
success: false,
error: error.message,
});
}
});
router.post('/refresh', async (req, res) => {
try {
const userId = String(req.body?.userId || '').trim() || null;
clearAssistantProfileCache(userId);
const result = await getAssistantProfile({ userId, forceRefresh: true });
res.json({
code: 0,
message: 'success',
success: true,
data: {
userId,
profile: result.profile,
source: result.source,
cached: result.cached,
fetchedAt: result.fetchedAt,
configured: result.configured,
error: result.error,
},
});
} catch (error) {
console.error('[AssistantProfile] refresh failed:', error.message);
res.status(500).json({
code: 500,
message: error.message,
success: false,
error: error.message,
});
}
});
module.exports = router;