36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
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){
|
|
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
|
|
} |