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

@@ -9,16 +9,14 @@ app.use(express.static("httpdocs/public"))
const documentRoot = `${__dirname}/httpdocs`
let fileSystem = {
"guest": {
"type": "directory",
"contents": {
"file.txt": {
"type": "file",
"content": "This is the text in the file <br> and I don't use \n to simulate a line break"
}
}
"/": {
"file1.txt": "this is the content of file1",
"projects": "dir"
},
"/projects/": {
"file2.txt": "this is file 2 :0",
"file3.txt": "and file 3 :D"
}
}
@@ -28,6 +26,11 @@ app.get('/', (req, res) => {
app.get("/execute", (req, res)=> {
const raw_command = req.query.command;
if (raw_command == ""){
res.json({"response": ""});
return;
}
const formatted_command = String(raw_command).trim();
const currentDir = req.query.currentDir
@@ -35,7 +38,7 @@ app.get("/execute", (req, res)=> {
console.log(`Executed Command: ${formatted_command}`);
if (formatted_command.startsWith("ls")){
commands.ls(req, res);
commands.ls(req, res, currentDir, fileSystem);
}
else if (formatted_command.startsWith("whoami")){
commands.whoami(req, res);
@@ -43,6 +46,10 @@ app.get("/execute", (req, res)=> {
else if (formatted_command.startsWith("pwd")){
commands.pwd(req, res, currentDir);
}
else if (formatted_command.startsWith("help"))
{
commands.help(req, res);
}
else {
res.json({"response": "invalid command"})
}