changing the commands to ostly run server-side (NOT DONE))
a
This commit is contained in:
@@ -1,34 +1,48 @@
|
||||
function ls (req, res, dir, fs) {
|
||||
dir = dir.startsWith('/') ? dir : '/' + dir;
|
||||
dir = dir.endsWith('/') ? dir : dir + '/';
|
||||
let currentState = {
|
||||
"username": "guest",
|
||||
"directory": "/"
|
||||
}
|
||||
const fileSystem = require("../filesystem.json")
|
||||
|
||||
function getCurrentDir(){
|
||||
return currentState.directory;
|
||||
}
|
||||
|
||||
function customTextResponse(res, txt){
|
||||
respondToCommand(res, txt, currentState.directory, "");
|
||||
}
|
||||
|
||||
|
||||
const contents = fs[dir];
|
||||
function ls(res) {
|
||||
const command = "ls";
|
||||
|
||||
|
||||
const contents = fileSystem[currentState.directory];
|
||||
|
||||
if (contents && typeof contents === 'object') {
|
||||
let keys = Object.keys(contents)
|
||||
res.json({"response": keys.join(" "), "command": "ls"});
|
||||
respondToCommand(res, keys.join(" "), currentState.directory, command);
|
||||
} else {
|
||||
res.json({"response": "No Files Found!", "command": "ls"});
|
||||
respondToCommand(res, "No Files Found In Current Directory", currentState.directory, command);
|
||||
}
|
||||
}
|
||||
|
||||
function whoami (req, res){
|
||||
res.json({"response": "guest", "command": "whoami"});
|
||||
}
|
||||
|
||||
function pwd (req, res, dir){
|
||||
res.json({"response": `/home/guest${dir}`})
|
||||
}
|
||||
|
||||
function help (req, res){
|
||||
res.json({"response": "Here is a list of commands:<br><br>help: show this menu.<br>cd: open a directory, for example 'cd myFolder'.<br>ls: shows you a list of the files in the current directory.<br>whoami: shows you who you are logged in as.<br>pwd: shows you the current directory you are located in.", "command":"help"});
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
ls,
|
||||
whoami,
|
||||
pwd,
|
||||
help
|
||||
getCurrentDir,
|
||||
customTextResponse,
|
||||
|
||||
ls
|
||||
}
|
||||
|
||||
|
||||
|
||||
function respondToCommand(res, text, directory, command){
|
||||
res.json({
|
||||
"username": "guest",
|
||||
"directory": directory,
|
||||
"response": text,
|
||||
"command": command
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user