added some more commands, chnaged filesystem layout, and added a help command :)

This commit is contained in:
valentijn
2024-01-19 11:48:07 +01:00
parent e4be64245b
commit 73d455d4bd
3 changed files with 81 additions and 20 deletions

View File

@@ -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
}