Files
Terminal-Website/commands/commands.js
2024-01-19 19:16:30 +01:00

48 lines
962 B
JavaScript

let currentState = {
"username": "guest",
"directory": "/"
}
const fileSystem = require("../filesystem.json")
function getCurrentDir(){
return currentState.directory;
}
function customTextResponse(res, txt){
respondToCommand(res, txt, currentState.directory, "");
}
function ls(res) {
const command = "ls";
const contents = fileSystem[currentState.directory];
if (contents && typeof contents === 'object') {
let keys = Object.keys(contents)
respondToCommand(res, keys.join(" "), currentState.directory, command);
} else {
respondToCommand(res, "No Files Found In Current Directory", currentState.directory, command);
}
}
module.exports = {
getCurrentDir,
customTextResponse,
ls
}
function respondToCommand(res, text, directory, command){
res.json({
"username": "guest",
"directory": directory,
"response": text,
"command": command
})
}