Complete Rewrite

This commit is contained in:
2024-09-14 11:04:06 -04:00
parent 926964f774
commit ec568c65b1
27 changed files with 2525 additions and 249 deletions

44
server/APISession.js Normal file
View File

@@ -0,0 +1,44 @@
export default class APISession {
constructor() {
this.sessions = new Map();
}
generateSessionID() {
let id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
return id;
}
createSession(id) {
if(this.sessions.get(id)) return false;
this.sessions.set(id, this.generateSessionID());
return this.sessions.get(id);
}
getSession(id) {
for (let [key, value] in this.sessions) {
if (key == id) return value;
}
return null;
}
setSession(id, value) {
if (!this.sessions.get(id)) return false;
this.sessions.set(id, value);
return true;
}
getSessionUser(sessionValue) {
for (let [key, value] of this.sessions) {
if (value == sessionValue) return key;
}
return null;
}
deleteSessionValue(id, key) {
if (!this.sessions.get(id)) return false;
this.sessions.delete(key);
return
}
}