Update index.js
Browse files
index.js
CHANGED
|
@@ -22,9 +22,11 @@ async function loadSessions() {
|
|
| 22 |
try {
|
| 23 |
const data = await fs.readFile(sessionFilePath, 'utf-8');
|
| 24 |
sessions = JSON.parse(data);
|
|
|
|
| 25 |
} catch (error) {
|
| 26 |
if (error.code === 'ENOENT') {
|
| 27 |
sessions = {};
|
|
|
|
| 28 |
} else {
|
| 29 |
console.error('Error reading session file:', error);
|
| 30 |
}
|
|
@@ -35,6 +37,7 @@ async function loadSessions() {
|
|
| 35 |
async function saveSessions() {
|
| 36 |
try {
|
| 37 |
await fs.writeFile(sessionFilePath, JSON.stringify(sessions, null, 2), 'utf-8');
|
|
|
|
| 38 |
} catch (error) {
|
| 39 |
console.error('Error writing to session file:', error);
|
| 40 |
}
|
|
@@ -46,6 +49,7 @@ function cleanUpSessions() {
|
|
| 46 |
for (const username in sessions) {
|
| 47 |
if (sessions[username].lastAccess && (now - sessions[username].lastAccess > SESSION_TIMEOUT)) {
|
| 48 |
delete sessions[username];
|
|
|
|
| 49 |
}
|
| 50 |
}
|
| 51 |
}
|
|
@@ -67,6 +71,7 @@ async function blackboxChat(content, username = null, prompt = null, webSearchMo
|
|
| 67 |
cleanUpSessions();
|
| 68 |
if (!sessions[username]) {
|
| 69 |
sessions[username] = { messages: [], lastAccess: Date.now() };
|
|
|
|
| 70 |
} else {
|
| 71 |
sessions[username].lastAccess = Date.now();
|
| 72 |
}
|
|
|
|
| 22 |
try {
|
| 23 |
const data = await fs.readFile(sessionFilePath, 'utf-8');
|
| 24 |
sessions = JSON.parse(data);
|
| 25 |
+
console.log('Sessions loaded successfully.');
|
| 26 |
} catch (error) {
|
| 27 |
if (error.code === 'ENOENT') {
|
| 28 |
sessions = {};
|
| 29 |
+
console.log('Session file not found. Starting with empty sessions.');
|
| 30 |
} else {
|
| 31 |
console.error('Error reading session file:', error);
|
| 32 |
}
|
|
|
|
| 37 |
async function saveSessions() {
|
| 38 |
try {
|
| 39 |
await fs.writeFile(sessionFilePath, JSON.stringify(sessions, null, 2), 'utf-8');
|
| 40 |
+
console.log('Sessions saved successfully.');
|
| 41 |
} catch (error) {
|
| 42 |
console.error('Error writing to session file:', error);
|
| 43 |
}
|
|
|
|
| 49 |
for (const username in sessions) {
|
| 50 |
if (sessions[username].lastAccess && (now - sessions[username].lastAccess > SESSION_TIMEOUT)) {
|
| 51 |
delete sessions[username];
|
| 52 |
+
console.log(`Session for user ${username} has been cleaned up.`);
|
| 53 |
}
|
| 54 |
}
|
| 55 |
}
|
|
|
|
| 71 |
cleanUpSessions();
|
| 72 |
if (!sessions[username]) {
|
| 73 |
sessions[username] = { messages: [], lastAccess: Date.now() };
|
| 74 |
+
console.log(`Creating new session for user ${username}.`);
|
| 75 |
} else {
|
| 76 |
sessions[username].lastAccess = Date.now();
|
| 77 |
}
|