Commit 7bd1e40b by Michael Pastushkov

fix clear

parent efce9518
...@@ -10,7 +10,6 @@ const ConversationManager = require('./ConversationManager'); ...@@ -10,7 +10,6 @@ const ConversationManager = require('./ConversationManager');
const MODEL = 'gpt-oss:20b'; // 'llama3:8b'; // 'gpt-oss:20b'; const MODEL = 'gpt-oss:20b'; // 'llama3:8b'; // 'gpt-oss:20b';
const EMBED_MODEL = 'nomic-embed-text'; const EMBED_MODEL = 'nomic-embed-text';
const LABEL_MODEL = 'llama3:8b'; const LABEL_MODEL = 'llama3:8b';
const COOKIE_TIMEOUT = 1 * 1 * 10 * 60 * 1000 // 10 minutes
const sessions = new Map(); // cookie -> ConversationManager const sessions = new Map(); // cookie -> ConversationManager
//const queues = new Map(); // cookie -> Promise (to serialize) //const queues = new Map(); // cookie -> Promise (to serialize)
...@@ -21,12 +20,11 @@ async function run(req, res) { ...@@ -21,12 +20,11 @@ async function run(req, res) {
let cookie = req.cookies?.session; let cookie = req.cookies?.session;
if (!cookie) { if (!cookie) {
cookie = uuidv4(); cookie = uuidv4();
res.cookie('session', cookie, { maxAge: COOKIE_TIMEOUT }); res.cookie('session', cookie, { path: '/', sameSite: 'Lax', httpOnly: true });
utils.log(`[session] New cookie set: ${cookie}`, 5); utils.log(`[session] New cookie set: ${cookie}`, 5);
} else { } else {
utils.log(`[session] Existing cookie: ${cookie}`, 5); utils.log(`[session] Existing cookie: ${cookie}`, 5);
} }
// Get conversation manager // Get conversation manager
let convman = sessions.get(cookie); let convman = sessions.get(cookie);
if (!convman) { if (!convman) {
...@@ -46,8 +44,16 @@ async function run(req, res) { ...@@ -46,8 +44,16 @@ async function run(req, res) {
async function stop(req, res) { async function stop(req, res) {
utils.log('stop'); utils.log('stop');
res.send('Stop OK');
}
async function clear(req, res) {
res.clearCookie('session', { path: '/', sameSite: 'Lax', httpOnly: true });
utils.log('clear');
res.send('Clear OK');
} }
module.exports = { run, stop }; module.exports = { run, stop };
/* Testing * / /* Testing * /
...@@ -63,4 +69,6 @@ function log(data) { ...@@ -63,4 +69,6 @@ function log(data) {
/**/ /**/
module.exports.run = run; module.exports.run = run;
\ No newline at end of file module.exports.stop = stop;
module.exports.clear = clear;
...@@ -21,6 +21,7 @@ function init(app) { ...@@ -21,6 +21,7 @@ function init(app) {
// Misc // Misc
[POST, '/stream', './KotGPT'], [POST, '/stream', './KotGPT'],
[GET, '/stop', './KotGPT', 'stop'], [GET, '/stop', './KotGPT', 'stop'],
[GET, '/clear', './KotGPT', 'clear'],
// Misc // Misc
[GET, '/info', '../common/info'], [GET, '/info', '../common/info'],
[GET, '/logcat', '../utils/logcat'], [GET, '/logcat', '../utils/logcat'],
......
...@@ -178,6 +178,11 @@ ...@@ -178,6 +178,11 @@
let controller = null; let controller = null;
window.addEventListener('DOMContentLoaded', async () => { window.addEventListener('DOMContentLoaded', async () => {
try {
await fetch('/api/clear', { method: 'GET' });
} catch (err) {
// nothing to do
}
await loadLocale(CURRENT_LOCALE); await loadLocale(CURRENT_LOCALE);
inputText.focus(); inputText.focus();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment