i had to stop becuz online lesson
This commit is contained in:
9
commands/commands.js
Normal file
9
commands/commands.js
Normal file
@@ -0,0 +1,9 @@
|
||||
function cd (req, res) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
cd
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"root": {
|
||||
"home": {
|
||||
"guest": {
|
||||
"aboutme.txt": "Ik hou van kaas :)",
|
||||
"projects": {
|
||||
"project_1": "Epic project 1",
|
||||
"project_2": "Epic project 2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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");
|
||||
19
server.js
19
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"});
|
||||
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user