Really fix it
This commit is contained in:
parent
7a1eef31e4
commit
f83befa2e5
16
app.js
16
app.js
@ -7,7 +7,7 @@ import Corestore from 'corestore';
|
|||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
const storagePath = `./storage/storage_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
const storagePath = `./storage/`;
|
||||||
const store = new Corestore(storagePath);
|
const store = new Corestore(storagePath);
|
||||||
const drive = new Hyperdrive(store);
|
const drive = new Hyperdrive(store);
|
||||||
|
|
||||||
@ -99,9 +99,14 @@ async function initialize() {
|
|||||||
if (configExists) {
|
if (configExists) {
|
||||||
config = JSON.parse(fs.readFileSync("./config.json", 'utf8'));
|
config = JSON.parse(fs.readFileSync("./config.json", 'utf8'));
|
||||||
console.log("Read config from file:", config)
|
console.log("Read config from file:", config)
|
||||||
|
// Update port in URLs
|
||||||
|
config.userAvatar = updatePortInUrl(config.userAvatar);
|
||||||
config.rooms.forEach(room => {
|
config.rooms.forEach(room => {
|
||||||
addRoomToListWithoutWritingToConfig(room);
|
addRoomToListWithoutWritingToConfig(room);
|
||||||
});
|
});
|
||||||
|
for (let user in registeredUsers) {
|
||||||
|
registeredUsers[user] = updatePortInUrl(registeredUsers[user]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const registerDiv = document.querySelector('#register');
|
const registerDiv = document.querySelector('#register');
|
||||||
@ -175,7 +180,7 @@ 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] = config.userAvatar;
|
registeredUsers[regUsername] = `http://localhost:${servePort}/icons/${regUsername}.png`; // Use placeholder URL
|
||||||
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
|
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
|
||||||
continueRegistration(regUsername);
|
continueRegistration(regUsername);
|
||||||
};
|
};
|
||||||
@ -438,4 +443,11 @@ function writeConfigToFile(filePath) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePortInUrl(url) {
|
||||||
|
if (!url) return url;
|
||||||
|
const urlObject = new URL(url);
|
||||||
|
urlObject.port = servePort;
|
||||||
|
return urlObject.toString();
|
||||||
|
}
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
|
Loading…
Reference in New Issue
Block a user