Adds full text indexes, and advanced search capabilities to the StyleAI chat bot.

This commit is contained in:
Cameron Redmore 2025-04-26 14:20:15 +01:00
parent ef002ec79b
commit 8dda301461
11 changed files with 252 additions and 36 deletions

View file

@ -4,6 +4,8 @@ import { requireAuth } from '../middlewares/authMiddleware.js'; // Import the mi
import { askGeminiChat } from '../utils/gemini.js';
import { getUserById } from './auth.js';
const router = Router();
// Apply the authentication middleware to all chat routes
@ -47,7 +49,14 @@ router.post('/threads', async(req, res) =>
if(content)
{
await askGeminiChat(newThread.id, content); // Call the function to handle the bot response
const user = await getUserById(req.session.loggedInUserId);
if (!user)
{
req.session.destroy(err =>
{});
return res.status(401).json({ status: 'unauthenticated' });
}
await askGeminiChat(newThread.id, `[${user.fullName || user.username}] ${content}`);
}
// Respond with the new thread ID and messages (if any)
@ -146,7 +155,14 @@ router.post('/threads/:threadId/messages', async(req, res) =>
data: { updatedAt: new Date() }
});
await askGeminiChat(threadId, content); // Call the function to handle the bot response
const user = await getUserById(req.session.loggedInUserId);
if (!user)
{
req.session.destroy(err =>
{});
return res.status(401).json({ status: 'unauthenticated' });
}
await askGeminiChat(threadId, `[${user.fullName || user.username}] ${content}`);
res.status(201).json({ ...newMessage, createdAt: newMessage.createdAt.toISOString() });
}