added some more commands, chnaged filesystem layout, and added a help command :)
This commit is contained in:
@@ -1,5 +1,18 @@
|
||||
function ls (req, res) {
|
||||
res.json({"response": "dit is totaal een reactie op een ls command :)", "command": "ls"});
|
||||
function ls (req, res, dir, fs) {
|
||||
dir = dir.startsWith('/') ? dir : '/' + dir;
|
||||
dir = dir.endsWith('/') ? dir : dir + '/';
|
||||
|
||||
console.log(dir);
|
||||
|
||||
const contents = fs[dir];
|
||||
|
||||
if (contents && typeof contents === 'object') {
|
||||
let keys = Object.keys(contents)
|
||||
console.log(keys);
|
||||
res.json({"response": keys.join(" "), "command": "ls"});
|
||||
} else {
|
||||
res.json({"response": "No Files Found!", "command": "ls"});
|
||||
}
|
||||
}
|
||||
|
||||
function whoami (req, res){
|
||||
@@ -10,9 +23,14 @@ 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
|
||||
pwd,
|
||||
help
|
||||
}
|
||||
Reference in New Issue
Block a user