Compare commits
7 Commits
f045f5804d
...
302589e97e
Author | SHA1 | Date | |
---|---|---|---|
|
302589e97e | ||
|
736a3a5e70 | ||
|
7855689289 | ||
|
8dbaa629d2 | ||
|
b1271ceb82 | ||
|
5931d68a29 | ||
|
5f8817a2f2 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
node_modules
|
||||
package-lock.json
|
||||
shared-storage
|
||||
storage_*
|
||||
storage
|
||||
chatBot/.env
|
||||
chatBot/.env
|
||||
|
15
app.js
15
app.js
@ -8,7 +8,8 @@ import Hyperdrive from 'hyperdrive';
|
||||
import Corestore from 'corestore';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
const store = new Corestore('./storage');
|
||||
const storagePath = `./storage_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
||||
const store = new Corestore(storagePath);
|
||||
const drive = new Hyperdrive(store);
|
||||
|
||||
await drive.ready();
|
||||
@ -21,10 +22,18 @@ let peerCount = 0;
|
||||
let currentRoom = null;
|
||||
const eventEmitter = new EventEmitter();
|
||||
|
||||
// Define servePort at the top level
|
||||
let servePort;
|
||||
|
||||
// Function to get a random port between 1337 and 2223
|
||||
function getRandomPort() {
|
||||
return Math.floor(Math.random() * (2223 - 1337 + 1)) + 1337;
|
||||
}
|
||||
|
||||
async function initialize() {
|
||||
swarm = new Hyperswarm();
|
||||
|
||||
const servePort = 1337;
|
||||
servePort = getRandomPort();
|
||||
const serve = new ServeDrive({ port: servePort, get: ({ key, filename, version }) => drive });
|
||||
await serve.ready();
|
||||
console.log('Listening on http://localhost:' + serve.address().port);
|
||||
@ -129,7 +138,7 @@ function registerUser(e) {
|
||||
reader.onload = async (event) => {
|
||||
const buffer = new Uint8Array(event.target.result);
|
||||
await drive.put(`/icons/${regUsername}.png`, buffer);
|
||||
userAvatar = `http://localhost:1337/icons/${regUsername}.png`; // Set the correct URL
|
||||
userAvatar = `http://localhost:${servePort}/icons/${regUsername}.png`; // Set the correct URL
|
||||
registeredUsers[regUsername] = userAvatar;
|
||||
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
|
||||
continueRegistration(regUsername);
|
||||
|
Loading…
Reference in New Issue
Block a user