did some stuff.

nothing special
This commit is contained in:
valentijn
2024-02-01 13:55:07 +01:00
parent fe674c9e06
commit beda73729d
5 changed files with 387 additions and 12 deletions

View File

@@ -40,18 +40,28 @@ function cd(req, res, raw_command) {
if (!req.session.state.directory.endsWith("/")) req.session.state.directory += "/";
respondToCommand(req, res, "", req.session.state.directory, command);
return;
}
else if (key === argument && fileSystem[req.session.state.directory][key] === "noperms") {
respondToCommand(req, res, "You don't have permission to open this directory", req.session.state.directory, command);
return;
} else if (key === argument) {
respondToCommand(req, res, "You cannot open a file as a directory", req.session.state.directory, command);
return;
}
}
if (argument === "/" || argument === "~" || argument === "~/") {
if (argument === "/") {
req.session.state.directory = "/";
respondToCommand(req, res, "", req.session.state.directory, command);
return;
}
if (argument === "~" || argument === "~/"){
req.session.state.directory = `/home/${req.session.state.username}`;
respondToCommand(req, res, "", req.session.state.directory, command);
return;
}
if (argument === ".." || argument === "../") {
const lastSlashIndex = req.session.state.directory.lastIndexOf('/');
const pathWithoutTrailingSlash = lastSlashIndex === req.session.state.directory.length - 1 ? req.session.state.directory.substring(0, req.session.state.directory.length - 1) : req.session.state.directory;
@@ -104,6 +114,7 @@ function help(req, res) {
Here is a list of the available commands:<br><br>
"help" - shows you this menu<br>
"clear" - clears the screen from previous ran commands<br>
"ls" - shows you the files and directories in your current directory<br>
"cd" - move into a folder you specify, you can use the name of the folder, or you can also use things like ../ to move back one folder<br>
"whoami" - shows you as what user you are logged in as<br>
@@ -113,6 +124,11 @@ function help(req, res) {
respondToCommand(req, res, text, req.session.state.directory, command);
}
function info(req, res){
}
function respondToCommand(req, res, text, directory, command) {
res.json({
"username": req.session.state.username,
@@ -125,10 +141,12 @@ function respondToCommand(req, res, text, directory, command) {
module.exports = {
getCurrentDir,
customTextResponse,
ls,
whoami,
cd,
pwd,
cat,
help,
info,
};