const express = require('express') const app = express() const port = 3000 const commands = require("./commands/commands") 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") }) 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 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": "invalid command"}) } }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })