move to browserfs
This commit is contained in:
parent
e8ff03d471
commit
6c4e0593b7
@ -5,11 +5,29 @@ import Docker from 'dockerode';
|
|||||||
import crypto from 'hypercore-crypto';
|
import crypto from 'hypercore-crypto';
|
||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import fs from 'fs';
|
import BrowserFS from 'browserfs';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
// Load environment variables from .env file
|
// Initialize BrowserFS with LocalStorage
|
||||||
dotenv.config();
|
BrowserFS.configure({ fs: 'LocalStorage' }, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('Failed to configure BrowserFS:', err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const fs = BrowserFS.BFSRequire('fs');
|
||||||
|
|
||||||
|
// Manually load environment variables from .env file using BrowserFS
|
||||||
|
if (fs.existsSync('.env')) {
|
||||||
|
const envData = fs.readFileSync('.env', 'utf-8');
|
||||||
|
envData.split('\n').forEach(line => {
|
||||||
|
const [key, value] = line.split('=');
|
||||||
|
if (key && value) {
|
||||||
|
process.env[key.trim()] = value.trim();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const docker = new Docker({
|
const docker = new Docker({
|
||||||
socketPath: os.platform() === "win32" ? '//./pipe/dockerDesktopLinuxEngine' : '/var/run/docker.sock',
|
socketPath: os.platform() === "win32" ? '//./pipe/dockerDesktopLinuxEngine' : '/var/run/docker.sock',
|
||||||
@ -21,6 +39,12 @@ const terminalSessions = new Map(); // Map to track terminal sessions per peer
|
|||||||
// Function to generate a new key
|
// Function to generate a new key
|
||||||
function generateNewKey() {
|
function generateNewKey() {
|
||||||
const newKey = crypto.randomBytes(32);
|
const newKey = crypto.randomBytes(32);
|
||||||
|
|
||||||
|
// Ensure .env file exists before appending
|
||||||
|
if (!fs.existsSync('.env')) {
|
||||||
|
fs.writeFileSync('.env', '', 'utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
fs.appendFileSync('.env', `SERVER_KEY=${newKey.toString('hex')}\n`, { flag: 'a' });
|
fs.appendFileSync('.env', `SERVER_KEY=${newKey.toString('hex')}\n`, { flag: 'a' });
|
||||||
return newKey;
|
return newKey;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user