From 7d43032a98b20c84215b56c8da359ba9a5661389 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Tue, 28 Mar 2023 00:15:29 +0800 Subject: [PATCH 01/30] feat: return home page on any path fix: clearConvo will remove all messages --- api/server/index.js | 15 ++++++++------- api/server/routes/convos.js | 23 ----------------------- client/public/index.html | 4 ++-- 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/api/server/index.js b/api/server/index.js index d929bd5d8a..17a3e9f809 100644 --- a/api/server/index.js +++ b/api/server/index.js @@ -67,26 +67,27 @@ const projectPath = path.join(__dirname, '..', '..', 'client'); res.send(JSON.stringify({ hasOpenAI, hasChatGpt, hasBing })); }); + app.get('/*', routes.authenticatedOrRedirect, function (req, res) { + res.sendFile(path.join(projectPath, 'public', 'index.html')); + }); + app.listen(port, host, () => { if (host == '0.0.0.0') console.log( `Server listening on all interface at port ${port}. Use http://localhost:${port} to access it` ); - else - console.log( - `Server listening at http://${host == '0.0.0.0' ? 'localhost' : host}:${port}` - ); + else console.log(`Server listening at http://${host == '0.0.0.0' ? 'localhost' : host}:${port}`); }); })(); let messageCount = 0; -process.on('uncaughtException', (err) => { +process.on('uncaughtException', err => { if (!err.message.includes('fetch failed')) { console.error('There was an uncaught error:', err.message); } - + if (err.message.includes('fetch failed')) { - if (messageCount === 0) { + if (messageCount === 0) { console.error('Meilisearch error, search will be disabled'); messageCount++; } diff --git a/api/server/routes/convos.js b/api/server/routes/convos.js index 7b2f9c72f9..45b23d0bd6 100644 --- a/api/server/routes/convos.js +++ b/api/server/routes/convos.js @@ -16,29 +16,6 @@ router.get('/:conversationId', async (req, res) => { res.status(200).send(convo.toObject()); }); -router.post('/gen_title', async (req, res) => { - const { conversationId } = req.body.arg; - - const convo = await getConvo(req?.session?.user?.username, conversationId); - const firstMessage = (await getMessages({ conversationId }))[0]; - const secondMessage = (await getMessages({ conversationId }))[1]; - - const title = convo.jailbreakConversationId - ? await getConvoTitle(req?.session?.user?.username, conversationId) - : await titleConvo({ - model: convo?.model, - message: firstMessage?.text, - response: JSON.stringify(secondMessage?.text || '') - }); - - await saveConvo(req?.session?.user?.username, { - conversationId, - title - }); - - res.status(200).send(title); -}); - router.post('/clear', async (req, res) => { let filter = {}; const { conversationId } = req.body.arg; diff --git a/client/public/index.html b/client/public/index.html index 8e8c205f6c..cc2670e745 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -26,7 +26,7 @@ />
@@ -34,7 +34,7 @@