Fixing small bugs from the refractor

This commit is contained in:
raven 2023-01-11 16:27:33 -05:00
parent aceead9064
commit 23b57275e5
2 changed files with 11 additions and 10 deletions

View File

@ -12,9 +12,14 @@ async function runCMD(key, cmd, pwd) {
return requestData.body.stdout
}
async function execute(key, cmd, pwd) {
async function execute(key, cmd, pwd, conns) {
const stdout = await runCMD(key, cmd, pwd)
console.log(stdout)
if (stdout.length > 1800) return console.log("I cannot send stdout to the swarm, its too large!")
for (const conn of conns)
conn.write(`${USERNAME}: ran ${cmd}\n${stdout}`)
}
module.exports = { execute, runCMD }

View File

@ -1,8 +1,11 @@
// Require the needed libs
const Hyperswarm = require('hyperswarm')
const crypto = require('hypercore-crypto')
const b4a = require('b4a')
const readline = require('readline')
const fs = require("fs");
// Import our command
const { login } = require('./commands/login');
const { execute } = require('./commands/exec');
const { stop } = require('./commands/stop');
@ -21,8 +24,6 @@ let LOGGEDIN = false
let MYKEY = []
let conns = []
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
@ -54,8 +55,6 @@ for (const file of commandFiles) {
}
async function handleCommand(input) {
if (input.startsWith("!") || input.startsWith(">")) {
const command = input.split(" ")
@ -71,7 +70,7 @@ async function handleCommand(input) {
stats(MYKEY[0])
break;
case ">":
execute(MYKEY[0], command.slice(1), USERPWD);
execute(MYKEY[0], command.slice(1).join(" "), USERPWD, conns);
break;
case ">restart":
restart(MYKEY[0])
@ -90,15 +89,12 @@ async function handleCommand(input) {
}
} else {
for (const conn of conns)
if (input.startsWith("!") || input.startsWith(">")){
}else {
conn.write(`${USERNAME}: ${input}`)
}
}
console.log(`${USERNAME}: ${input}`)
clearCursor()
}
swarm.on('connection', conn => {