mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
✨ feat: Refactor Favorites functionality to support new data structure and enhance UI interactions
This commit is contained in:
parent
d2faf9c67d
commit
4c10fcd118
13 changed files with 347 additions and 175 deletions
|
|
@ -35,11 +35,16 @@ const getFavoritesController = async (req, res) => {
|
|||
return res.status(404).json({ message: 'User not found' });
|
||||
}
|
||||
|
||||
const favorites = user.favorites || {};
|
||||
res.status(200).json({
|
||||
agents: favorites.agents || [],
|
||||
models: favorites.models || [],
|
||||
});
|
||||
let favorites = user.favorites || [];
|
||||
|
||||
// Ensure favorites is an array (migration/dev fix)
|
||||
if (!Array.isArray(favorites)) {
|
||||
favorites = [];
|
||||
// Optionally update the DB to fix it permanently
|
||||
await User.findByIdAndUpdate(userId, { $set: { favorites: [] } });
|
||||
}
|
||||
|
||||
res.status(200).json(favorites);
|
||||
} catch (error) {
|
||||
console.error('Error fetching favorites:', error);
|
||||
res.status(500).json({ message: 'Internal server error' });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue