From 9c0e165b33f439a30679d8378b01408475c247c4 Mon Sep 17 00:00:00 2001 From: valentijn <120188387+HerpieDerpieee@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:17:06 +0100 Subject: [PATCH] i had to stop becuz online lesson --- commands/commands.js | 9 +++++++ filesystem.json | 13 ---------- {public => httpdocs/public}/css/styles.css | 29 ++++++++++++++++++++++ {public => httpdocs/public}/js/terminal.js | 9 +++++-- server.js | 19 ++++++-------- 5 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 commands/commands.js delete mode 100644 filesystem.json rename {public => httpdocs/public}/css/styles.css (77%) rename {public => httpdocs/public}/js/terminal.js (96%) diff --git a/commands/commands.js b/commands/commands.js new file mode 100644 index 0000000..1398a50 --- /dev/null +++ b/commands/commands.js @@ -0,0 +1,9 @@ +function cd (req, res) { + +} + + + +module.exports = { + cd +} \ No newline at end of file diff --git a/filesystem.json b/filesystem.json deleted file mode 100644 index 1c9b027..0000000 --- a/filesystem.json +++ /dev/null @@ -1,13 +0,0 @@ -{ -"root": { - "home": { - "guest": { - "aboutme.txt": "Ik hou van kaas :)", - "projects": { - "project_1": "Epic project 1", - "project_2": "Epic project 2" - } - } - } -} -} \ No newline at end of file diff --git a/public/css/styles.css b/httpdocs/public/css/styles.css similarity index 77% rename from public/css/styles.css rename to httpdocs/public/css/styles.css index 606fe96..42d1d5d 100644 --- a/public/css/styles.css +++ b/httpdocs/public/css/styles.css @@ -1,6 +1,7 @@ * { margin:0; padding: 0; + overflow: hidden; } #main { @@ -9,13 +10,41 @@ height: 100vh; } + + #terminal { --padding: 30px; width: calc(100% - (2 * var(--padding))); height: calc(100% - (2 * var(--padding))); padding: var(--padding); + + overflow-y: auto; } +#terminal::-webkit-scrollbar { + width: 7px; +} + +#terminal::-webkit-scrollbar-thumb { + background-color: #222; + border-radius: 5px; +} + +#terminal::-webkit-scrollbar-thumb:hover { + background-color: #333; +} + +#terminal::-webkit-scrollbar-track { + background: none; + border-radius: 8px; +} + +#terminal::-webkit-scrollbar-track:hover { + background: none; +} + + + .terminalLine { display: flex; justify-content: flex-start; diff --git a/public/js/terminal.js b/httpdocs/public/js/terminal.js similarity index 96% rename from public/js/terminal.js rename to httpdocs/public/js/terminal.js index f405a8c..f3c9327 100644 --- a/public/js/terminal.js +++ b/httpdocs/public/js/terminal.js @@ -1,6 +1,6 @@ const terminalContainer = document.getElementById("terminal"); const hostname = `192.168.${Math.floor(Math.random() * 100)}.${Math.floor(Math.random() * 255)}`; -let currentFolder = "~/projects"; +let currentFolder = "~/"; @@ -23,7 +23,7 @@ async function sendCommand(e){ try { // Construct the URL with the command parameter in the query string - const url = "/execute?command=" + encodeURIComponent(command); + const url = "/execute?command=" + encodeURIComponent(command) + "¤tDir=" + encodeURIComponent(currentFolder); // Make a GET request using the fetch API const response = await fetch(url); @@ -65,6 +65,11 @@ function deactivateAllStuff() { function handleExecutionResponse(response) { + if (response.command === "cd"){ + currentFolder = response.directory + } + + //Show Response let commandResponse = document.createElement("div") commandResponse.classList.add("terminalLine"); diff --git a/server.js b/server.js index 95ea41c..15e067e 100644 --- a/server.js +++ b/server.js @@ -2,7 +2,9 @@ const express = require('express') const app = express() const port = 3000 -app.use(express.static("public")) +const commands = require("./commands/commands") + +app.use(express.static("httpdocs/public")) const documentRoot = `${__dirname}/httpdocs` @@ -15,10 +17,12 @@ app.get("/execute", (req, res)=> { const raw_command = req.query.command; const formatted_command = String(raw_command).trim(); + const currentDir = req.query.currentDir + console.log(`Executed Command: ${formatted_command}`); - if (formatted_command.startsWith("ls")){ - LS(req, res); + if (formatted_command.startsWith("cd")){ + commands.cd(req, res); } else { res.json({"response": "invalid command"}) @@ -27,11 +31,4 @@ app.get("/execute", (req, res)=> { app.listen(port, () => { console.log(`Example app listening on port ${port}`) -}) - - - -function LS (req, res) { - res.json({"response": "LS IS WEL FICKING EPISCH"}); - -} \ No newline at end of file +}) \ No newline at end of file