mirror of
https://github.com/Mintplex-Labs/anything-llm
synced 2026-04-25 17:15:37 +02:00
add user id to chat feedback
update JSDOC on middleware for typedef GHSA-2qmm-82f7-8qj5
This commit is contained in:
@@ -498,21 +498,16 @@ function workspaceEndpoints(app) {
|
||||
try {
|
||||
const { chatId } = request.params;
|
||||
const { feedback = null } = reqBody(request);
|
||||
const user = await userFromSession(request, response);
|
||||
const existingChat = await WorkspaceChats.get({
|
||||
id: Number(chatId),
|
||||
workspaceId: response.locals.workspace.id,
|
||||
user_id: user?.id,
|
||||
});
|
||||
|
||||
if (!existingChat) {
|
||||
response.status(404).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await WorkspaceChats.updateFeedbackScore(
|
||||
chatId,
|
||||
feedback
|
||||
);
|
||||
response.status(200).json({ success: result });
|
||||
if (!existingChat) return response.status(404).json({ success: false });
|
||||
await WorkspaceChats.updateFeedbackScore(chatId, feedback);
|
||||
return response.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
console.error("Error updating chat feedback:", error);
|
||||
response.status(500).end();
|
||||
|
||||
@@ -28,8 +28,14 @@ function makeJWT(info = {}, expiry = "30d") {
|
||||
return JWT.sign(info, process.env.JWT_SECRET, { expiresIn: expiry });
|
||||
}
|
||||
|
||||
// Note: Only valid for finding users in multi-user mode
|
||||
// as single-user mode with password is not a "user"
|
||||
/**
|
||||
* Gets the user from the session
|
||||
* Note: Only valid for multi-user mode
|
||||
* as single-user mode with password is not a "user"
|
||||
* @param {import("express").Request} request - The request object
|
||||
* @param {import("express").Response} response - The response object
|
||||
* @returns {Promise<import("@prisma/client").users | null>} The user
|
||||
*/
|
||||
async function userFromSession(request, response = null) {
|
||||
if (!!response && !!response.locals?.user) {
|
||||
return response.locals.user;
|
||||
|
||||
Reference in New Issue
Block a user