forked from snxraven/LinkUp-P2P-Chat
Remove localStorage uses
This commit is contained in:
parent
7461dadf88
commit
060308ec92
14
app.js
14
app.js
@ -14,7 +14,6 @@ const drive = new Hyperdrive(store);
|
|||||||
await drive.ready();
|
await drive.ready();
|
||||||
|
|
||||||
let swarm;
|
let swarm;
|
||||||
let registeredUsers = JSON.parse(localStorage.getItem('registeredUsers')) || {};
|
|
||||||
let peerCount = 0;
|
let peerCount = 0;
|
||||||
let activeRooms = [];
|
let activeRooms = [];
|
||||||
const eventEmitter = new EventEmitter();
|
const eventEmitter = new EventEmitter();
|
||||||
@ -26,7 +25,8 @@ let servePort;
|
|||||||
let config = {
|
let config = {
|
||||||
userName: '',
|
userName: '',
|
||||||
userAvatar: '',
|
userAvatar: '',
|
||||||
rooms: []
|
rooms: [],
|
||||||
|
registeredUsers: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Store messages for each room
|
// Store messages for each room
|
||||||
@ -97,8 +97,8 @@ async function initialize() {
|
|||||||
config.rooms.forEach(room => {
|
config.rooms.forEach(room => {
|
||||||
room.alias = room.alias || truncateHash(room.topic);
|
room.alias = room.alias || truncateHash(room.topic);
|
||||||
});
|
});
|
||||||
for (let user in registeredUsers) {
|
for (let user in config.registeredUsers) {
|
||||||
registeredUsers[user] = updatePortInUrl(registeredUsers[user]);
|
config.registeredUsers[user] = updatePortInUrl(config.registeredUsers[user]);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderRoomList(); // Render the room list with aliases
|
renderRoomList(); // Render the room list with aliases
|
||||||
@ -189,7 +189,7 @@ function registerUser(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const regUsername = document.querySelector('#reg-username').value;
|
const regUsername = document.querySelector('#reg-username').value;
|
||||||
|
|
||||||
if (registeredUsers[regUsername]) {
|
if (config.registeredUsers[regUsername]) {
|
||||||
alert('Username already taken. Please choose another.');
|
alert('Username already taken. Please choose another.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -201,8 +201,8 @@ function registerUser(e) {
|
|||||||
const buffer = new Uint8Array(event.target.result);
|
const buffer = new Uint8Array(event.target.result);
|
||||||
await drive.put(`/icons/${regUsername}.png`, buffer);
|
await drive.put(`/icons/${regUsername}.png`, buffer);
|
||||||
config.userAvatar = `http://localhost:${servePort}/icons/${regUsername}.png`; // Set the correct URL
|
config.userAvatar = `http://localhost:${servePort}/icons/${regUsername}.png`; // Set the correct URL
|
||||||
registeredUsers[regUsername] = `http://localhost:${servePort}/icons/${regUsername}.png`; // Use placeholder URL
|
config.registeredUsers[regUsername] = `http://localhost:${servePort}/icons/${regUsername}.png`; // Use placeholder URL
|
||||||
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
|
writeConfigToFile("./config.json");
|
||||||
continueRegistration(regUsername);
|
continueRegistration(regUsername);
|
||||||
};
|
};
|
||||||
reader.readAsArrayBuffer(avatarFile);
|
reader.readAsArrayBuffer(avatarFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user