changing the commands to ostly run server-side (NOT DONE))

a
This commit is contained in:
valentijn
2024-01-19 19:16:30 +01:00
parent 33db47102c
commit d0fb604680
4 changed files with 59 additions and 89 deletions

View File

@@ -8,17 +8,6 @@ app.use(express.static("httpdocs/public"))
const documentRoot = `${__dirname}/httpdocs`
let fileSystem = {
"/": {
"file1.txt": "this is the content of file1",
"projects": "dir"
},
"/projects/": {
"file2.txt": "this is file 2 :0",
"file3.txt": "and file 3 :D"
}
}
app.get('/', (req, res) => {
res.sendFile(documentRoot+"/index.html")
@@ -27,30 +16,24 @@ app.get('/', (req, res) => {
app.get("/execute", (req, res)=> {
const raw_command = req.query.command;
if (raw_command == ""){
res.json({"response": ""});
commands.customTextResponse(res, "");
return;
}
const formatted_command = String(raw_command).trim();
const formatted_command = raw_command.trim();
const command = formatted_command.split(" ")[0]
const currentDir = req.query.currentDir
switch(command){
default:
commands.customTextResponse(res, "Command '"+command+"' not found, please try again later, or type 'help' for the list of available commands");
break;
case "ls":
commands.ls(res);
}
})
if (formatted_command.startsWith("ls")){
commands.ls(req, res, currentDir, fileSystem);
}
else if (formatted_command.startsWith("whoami")){
commands.whoami(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": "Unknown command, please try again later, or run 'help' for a list of commands"});
}
app.get("/currentDir", (req, res)=>{
res.send(commands.getCurrentDir());
})
app.listen(port, () => {