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 a8c7729558
commit 910d1b3d21
11 changed files with 252 additions and 36 deletions

View file

@ -28,13 +28,13 @@ async function getUserAuthenticators(userId)
}
// Helper function to get a user by username
async function getUserByUsername(username)
export async function getUserByUsername(username)
{
return prisma.user.findUnique({ where: { username } });
}
// Helper function to get a user by ID
async function getUserById(id)
export async function getUserById(id)
{
return prisma.user.findUnique({ where: { id } });
}

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() });
}