No more admin!

This commit is contained in:
bingus_violet 2024-01-19 18:43:17 +00:00
parent f6db197a87
commit add75fe476
2 changed files with 3 additions and 69 deletions

View file

@ -6,12 +6,9 @@ bodyParser = require("body-parser")
var app = express() var app = express()
var uploads = multer({ storage: multer.memoryStorage() })
var PORT = process.env.PORT || 8080 var PORT = process.env.PORT || 8080
var directory = process.env.FILES_DIR var directory = process.env.FILES_DIR
var passwd = process.env.PASSWORD
var baseHTML = fs.readFileSync(path.join(__dirname, 'resources/base.html')).toString() var baseHTML = fs.readFileSync(path.join(__dirname, 'resources/base.html')).toString()
var baseStart = baseHTML.substring(0, baseHTML.indexOf('{CONTENT}')) var baseStart = baseHTML.substring(0, baseHTML.indexOf('{CONTENT}'))
@ -22,22 +19,13 @@ if (!directory) {
return return
} }
app.use('/b', express.static(directory)) app.use(express.static(directory))
app.use(express.static(path.join(__dirname, 'static')))
app.use(bodyParser.urlencoded({ extended: false }))
app.listen(PORT, () => { app.listen(PORT, () => {
console.log("Now listening on PORT: " + PORT) console.log("Now listening on PORT: " + PORT)
if (!passwd) {
console.log("Password variable not found. Uploading from site is not available.")
} else {
console.log("Password variable found! Uploads are now available on the site.")
}
}) })
app.get("/b*", (req, res) => { app.get("/*", (req, res) => {
var file = req.params[0] var file = req.params[0]
var absPath = path.join(directory, file) var absPath = path.join(directory, file)
@ -66,31 +54,3 @@ app.get("/b*", (req, res) => {
res.end() res.end()
}) })
app.get("/", (req, res) => {
res.redirect("/b")
})
if (passwd) {
app.get("/dashboard.html", (req, res) => {
var html = fs.readFileSync(path.join(__dirname, 'resources/dashboard.html')).toString()
while (html.includes("{DIRECTORY}")) {
html = html.replace("{DIRECTORY}", req.query.folder)
}
res.send(html)
})
app.post("/upload", uploads.single('file'), (req, res) => {
var file = req.file
fs.writeFileSync(path.join(__dirname, req.body.directory, file.originalname), file.buffer)
res.redirect(req.body.directory)
})
app.post("/mkdir", bodyParser.urlencoded({ extended: false }), (req, res) => {
fs.mkdirSync(path.join(__dirname, req.body.directory, req.body.name))
res.redirect(req.body.directory)
})
}

View file

@ -1,26 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
</head>
<body>
<h2>Upload</h2>
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" readonly value="{DIRECTORY}" name="directory">
<input type="password" placeholder="Password" name="password">
<input type="file" name="file">
<input type="submit">
</form>
<h2>Make Directory</h2>
<form action="/mkdir" method="post">
<input type="text" readonly value="{DIRECTORY}" name="directory">
<input type="password" placeholder="Password" name="password">
<input type="text" name="name" placeholder="folderName">
<input type="submit">
</form>
</body>
</html>