From c3a7a35346978385557e44c5c0f53fa63466a154 Mon Sep 17 00:00:00 2001 From: Location <59411633+James-Lu-none@users.noreply.github.com> Date: Fri, 25 Oct 2024 05:49:06 +0800 Subject: [PATCH 1/3] Alignment crime fixed (#2528) fix alignment crime --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1f308a143..4edf494820 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ This monorepo consists of three main sections: Mintplex Labs & the community maintain a number of deployment methods, scripts, and templates that you can use to run AnythingLLM locally. Refer to the table below to read how to deploy on your preferred environment or to automatically deploy. | Docker | AWS | GCP | Digital Ocean | Render.com | -|----------------------------------------|----:|-----|---------------|------------| +|----------------------------------------|----|-----|---------------|------------| | [![Deploy on Docker][docker-btn]][docker-deploy] | [![Deploy on AWS][aws-btn]][aws-deploy] | [![Deploy on GCP][gcp-btn]][gcp-deploy] | [![Deploy on DigitalOcean][do-btn]][do-deploy] | [![Deploy on Render.com][render-btn]][render-deploy] | | Railway | RepoCloud | Elestio | From 72ba9f7f289047eac3bf1199a7e6892bf40bb3da Mon Sep 17 00:00:00 2001 From: Timothy Carambat Date: Thu, 24 Oct 2024 15:10:50 -0700 Subject: [PATCH 2/3] Add filtering to sessionID for workspace chats (#2531) --- server/endpoints/api/workspace/index.js | 14 +++++++++++++- server/models/workspaceChats.js | 25 +++++++++++++++++++++++++ server/swagger/openapi.json | 9 +++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/server/endpoints/api/workspace/index.js b/server/endpoints/api/workspace/index.js index fca441e25a..dca21e49f6 100644 --- a/server/endpoints/api/workspace/index.js +++ b/server/endpoints/api/workspace/index.js @@ -339,6 +339,12 @@ function apiWorkspaceEndpoints(app) { required: true, type: 'string' } + #swagger.parameters['apiSessionId'] = { + in: 'query', + description: 'Optional apiSessionId to filter by', + required: false, + type: 'string' + } #swagger.responses[200] = { content: { "application/json": { @@ -370,6 +376,7 @@ function apiWorkspaceEndpoints(app) { */ try { const { slug } = request.params; + const { apiSessionId = null } = request.query; const workspace = await Workspace.get({ slug }); if (!workspace) { @@ -377,7 +384,12 @@ function apiWorkspaceEndpoints(app) { return; } - const history = await WorkspaceChats.forWorkspace(workspace.id); + const history = apiSessionId + ? await WorkspaceChats.forWorkspaceByApiSessionId( + workspace.id, + apiSessionId + ) + : await WorkspaceChats.forWorkspace(workspace.id); response.status(200).json({ history: convertToChatHistory(history) }); } catch (e) { console.error(e.message, e); diff --git a/server/models/workspaceChats.js b/server/models/workspaceChats.js index ef474c4ef7..4a2b884f8b 100644 --- a/server/models/workspaceChats.js +++ b/server/models/workspaceChats.js @@ -55,6 +55,31 @@ const WorkspaceChats = { } }, + forWorkspaceByApiSessionId: async function ( + workspaceId = null, + apiSessionId = null, + limit = null, + orderBy = null + ) { + if (!workspaceId || !apiSessionId) return []; + try { + const chats = await prisma.workspace_chats.findMany({ + where: { + workspaceId, + user_id: null, + api_session_id: String(apiSessionId), + thread_id: null, + }, + ...(limit !== null ? { take: limit } : {}), + ...(orderBy !== null ? { orderBy } : { orderBy: { id: "asc" } }), + }); + return chats; + } catch (error) { + console.error(error.message); + return []; + } + }, + forWorkspace: async function ( workspaceId = null, limit = null, diff --git a/server/swagger/openapi.json b/server/swagger/openapi.json index b12fbf5359..fb343ee836 100644 --- a/server/swagger/openapi.json +++ b/server/swagger/openapi.json @@ -1649,6 +1649,15 @@ "type": "string" }, "description": "Unique slug of workspace to find" + }, + { + "name": "apiSessionId", + "in": "query", + "description": "Optional apiSessionId to filter by", + "required": false, + "schema": { + "type": "string" + } } ], "responses": { From 40800631e3da62a6ddd54116fd892b81ade763ca Mon Sep 17 00:00:00 2001 From: Timothy Carambat Date: Fri, 25 Oct 2024 12:03:19 -0700 Subject: [PATCH 3/3] Patch `v1/document/upload` filename charset encoding (#2535) --- server/endpoints/api/document/index.js | 4 +- server/utils/files/multer.js | 66 ++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/server/endpoints/api/document/index.js b/server/endpoints/api/document/index.js index a646fb584a..f49cf0dd43 100644 --- a/server/endpoints/api/document/index.js +++ b/server/endpoints/api/document/index.js @@ -1,6 +1,6 @@ const { Telemetry } = require("../../../models/telemetry"); const { validApiKey } = require("../../../utils/middleware/validApiKey"); -const { handleFileUpload } = require("../../../utils/files/multer"); +const { handleAPIFileUpload } = require("../../../utils/files/multer"); const { viewLocalFiles, findDocumentInDocuments, @@ -23,7 +23,7 @@ function apiDocumentEndpoints(app) { app.post( "/v1/document/upload", - [validApiKey, handleFileUpload], + [validApiKey, handleAPIFileUpload], async (request, response) => { /* #swagger.tags = ['Documents'] diff --git a/server/utils/files/multer.js b/server/utils/files/multer.js index 22f1217e36..a4b90042e1 100644 --- a/server/utils/files/multer.js +++ b/server/utils/files/multer.js @@ -3,7 +3,10 @@ const path = require("path"); const fs = require("fs"); const { v4 } = require("uuid"); -// Handle File uploads for auto-uploading. +/** + * Handle File uploads for auto-uploading. + * Mostly used for internal GUI/API uploads. + */ const fileUploadStorage = multer.diskStorage({ destination: function (_, __, cb) { const uploadOutput = @@ -20,6 +23,23 @@ const fileUploadStorage = multer.diskStorage({ }, }); +/** + * Handle API file upload as documents - this does not manipulate the filename + * at all for encoding/charset reasons. + */ +const fileAPIUploadStorage = multer.diskStorage({ + destination: function (_, __, cb) { + const uploadOutput = + process.env.NODE_ENV === "development" + ? path.resolve(__dirname, `../../../collector/hotdir`) + : path.resolve(process.env.STORAGE_DIR, `../../collector/hotdir`); + cb(null, uploadOutput); + }, + filename: function (_, file, cb) { + cb(null, file.originalname); + }, +}); + // Asset storage for logos const assetUploadStorage = multer.diskStorage({ destination: function (_, __, cb) { @@ -38,7 +58,9 @@ const assetUploadStorage = multer.diskStorage({ }, }); -// Asset sub-storage manager for pfp icons. +/** + * Handle PFP file upload as logos + */ const pfpUploadStorage = multer.diskStorage({ destination: function (_, __, cb) { const uploadOutput = @@ -55,7 +77,12 @@ const pfpUploadStorage = multer.diskStorage({ }, }); -// Handle Generic file upload as documents +/** + * Handle Generic file upload as documents from the GUI + * @param {Request} request + * @param {Response} response + * @param {NextFunction} next + */ function handleFileUpload(request, response, next) { const upload = multer({ storage: fileUploadStorage }).single("file"); upload(request, response, function (err) { @@ -73,7 +100,33 @@ function handleFileUpload(request, response, next) { }); } -// Handle logo asset uploads +/** + * Handle API file upload as documents - this does not manipulate the filename + * at all for encoding/charset reasons. + * @param {Request} request + * @param {Response} response + * @param {NextFunction} next + */ +function handleAPIFileUpload(request, response, next) { + const upload = multer({ storage: fileAPIUploadStorage }).single("file"); + upload(request, response, function (err) { + if (err) { + response + .status(500) + .json({ + success: false, + error: `Invalid file upload. ${err.message}`, + }) + .end(); + return; + } + next(); + }); +} + +/** + * Handle logo asset uploads + */ function handleAssetUpload(request, response, next) { const upload = multer({ storage: assetUploadStorage }).single("logo"); upload(request, response, function (err) { @@ -91,7 +144,9 @@ function handleAssetUpload(request, response, next) { }); } -// Handle PFP file upload as logos +/** + * Handle PFP file upload as logos + */ function handlePfpUpload(request, response, next) { const upload = multer({ storage: pfpUploadStorage }).single("file"); upload(request, response, function (err) { @@ -111,6 +166,7 @@ function handlePfpUpload(request, response, next) { module.exports = { handleFileUpload, + handleAPIFileUpload, handleAssetUpload, handlePfpUpload, };