i had to stop becuz online lesson

This commit is contained in:
valentijn
2024-01-17 15:17:06 +01:00
parent 39fea6e13b
commit 9c0e165b33
5 changed files with 53 additions and 26 deletions

9
commands/commands.js Normal file
View File

@@ -0,0 +1,9 @@
function cd (req, res) {
}
module.exports = {
cd
}

View File

@@ -1,13 +0,0 @@
{
"root": {
"home": {
"guest": {
"aboutme.txt": "Ik hou van kaas :)",
"projects": {
"project_1": "Epic project 1",
"project_2": "Epic project 2"
}
}
}
}
}

View File

@@ -1,6 +1,7 @@
* { * {
margin:0; margin:0;
padding: 0; padding: 0;
overflow: hidden;
} }
#main { #main {
@@ -9,13 +10,41 @@
height: 100vh; height: 100vh;
} }
#terminal { #terminal {
--padding: 30px; --padding: 30px;
width: calc(100% - (2 * var(--padding))); width: calc(100% - (2 * var(--padding)));
height: calc(100% - (2 * var(--padding))); height: calc(100% - (2 * var(--padding)));
padding: 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 { .terminalLine {
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;

View File

@@ -1,6 +1,6 @@
const terminalContainer = document.getElementById("terminal"); const terminalContainer = document.getElementById("terminal");
const hostname = `192.168.${Math.floor(Math.random() * 100)}.${Math.floor(Math.random() * 255)}`; 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 { try {
// Construct the URL with the command parameter in the query string // Construct the URL with the command parameter in the query string
const url = "/execute?command=" + encodeURIComponent(command); const url = "/execute?command=" + encodeURIComponent(command) + "&currentDir=" + encodeURIComponent(currentFolder);
// Make a GET request using the fetch API // Make a GET request using the fetch API
const response = await fetch(url); const response = await fetch(url);
@@ -65,6 +65,11 @@ function deactivateAllStuff() {
function handleExecutionResponse(response) { function handleExecutionResponse(response) {
if (response.command === "cd"){
currentFolder = response.directory
}
//Show Response //Show Response
let commandResponse = document.createElement("div") let commandResponse = document.createElement("div")
commandResponse.classList.add("terminalLine"); commandResponse.classList.add("terminalLine");

View File

@@ -2,7 +2,9 @@ const express = require('express')
const app = express() const app = express()
const port = 3000 const port = 3000
app.use(express.static("public")) const commands = require("./commands/commands")
app.use(express.static("httpdocs/public"))
const documentRoot = `${__dirname}/httpdocs` const documentRoot = `${__dirname}/httpdocs`
@@ -15,10 +17,12 @@ app.get("/execute", (req, res)=> {
const raw_command = req.query.command; const raw_command = req.query.command;
const formatted_command = String(raw_command).trim(); const formatted_command = String(raw_command).trim();
const currentDir = req.query.currentDir
console.log(`Executed Command: ${formatted_command}`); console.log(`Executed Command: ${formatted_command}`);
if (formatted_command.startsWith("ls")){ if (formatted_command.startsWith("cd")){
LS(req, res); commands.cd(req, res);
} }
else { else {
res.json({"response": "invalid command"}) res.json({"response": "invalid command"})
@@ -28,10 +32,3 @@ app.get("/execute", (req, res)=> {
app.listen(port, () => { app.listen(port, () => {
console.log(`Example app listening on port ${port}`) console.log(`Example app listening on port ${port}`)
}) })
function LS (req, res) {
res.json({"response": "LS IS WEL FICKING EPISCH"});
}