More branding & yapping

This commit is contained in:
Violet 2024-02-02 21:23:01 +00:00 committed by GitHub
parent 6971adf579
commit c17725e9b3
4 changed files with 50 additions and 8 deletions

View file

@ -30,10 +30,6 @@ function humanFileSize(bytes, si = false, dp = 1) {
return bytes.toFixed(dp) + ' ' + units[u]; return bytes.toFixed(dp) + ' ' + units[u];
} }
var baseHTML = fs.readFileSync(path.join(__dirname, 'resources/base.html')).toString()
var baseStart = baseHTML.substring(0, baseHTML.indexOf('{CONTENT}'))
var baseEnd = baseHTML.substring(baseHTML.indexOf('{CONTENT}') + 9, baseHTML.length)
if (!directory) { if (!directory) {
console.error("No directory specified! Please specify one using the environment variable FILES_DIR.") console.error("No directory specified! Please specify one using the environment variable FILES_DIR.")
return return
@ -49,12 +45,22 @@ 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)
if (file != '') {
var baseHTML = fs.readFileSync(path.join(__dirname, 'resources/base.html')).toString()
} else {
var baseHTML = fs.readFileSync(path.join(__dirname, 'resources/root.html')).toString()
}
var baseStart = baseHTML.substring(0, baseHTML.indexOf('{CONTENT}'))
var baseEnd = baseHTML.substring(baseHTML.indexOf('{CONTENT}') + 9, baseHTML.length)
res.setHeader('Content-Type', 'text/html') res.setHeader('Content-Type', 'text/html')
res.setHeader("X-Accel-Buffering", "no") res.setHeader("X-Accel-Buffering", "no")
try { try {
var dirContents = fs.readdirSync(absPath) var dirContents = fs.readdirSync(absPath)
var dirStats = fs.statSync(absPath)
} catch (error) { } catch (error) {
res.send(baseStart.replace("{TITLE}", "404: not found!") + "<h2>404: not found!</h2>" + baseEnd) res.send(baseStart.replace("{TITLE}", "404: not found!") + "<h2>404: not found!</h2>" + baseEnd)
return return
@ -62,6 +68,8 @@ app.get("/*", (req, res) => {
res.write(baseStart.replace("{TITLE}", '/' + file)) res.write(baseStart.replace("{TITLE}", '/' + file))
res.write(`<h3>${dirContents.length} Files</h3>`)
if (file != '') { if (file != '') {
res.write('<a href="../">Parent Directory</a><br>') res.write('<a href="../">Parent Directory</a><br>')
} }

View file

@ -4,7 +4,7 @@
"description": "A feature rich and customizable NodeJS program for easily displaying a directory on the web.", "description": "A feature rich and customizable NodeJS program for easily displaying a directory on the web.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "node index.js" "start": "node index.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -7,11 +8,16 @@
<link rel="stylesheet" href="https://violets-purgatory.dev/style.css"> <link rel="stylesheet" href="https://violets-purgatory.dev/style.css">
<title>{TITLE}</title> <title>{TITLE}</title>
</head> </head>
<body> <body>
<div class="fadediv">
<ul> <ul>
{CONTENT} {CONTENT}
</ul> </ul>
</div>
</body> </body>
</html> </html>

28
resources/root.html Normal file
View file

@ -0,0 +1,28 @@
<!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">
<link rel="stylesheet" href="https://violets-purgatory.dev/style.css">
<title>Violet's Clipdump</title>
</head>
<body>
<h1>Welcome to Violet's Clip dump</h1>
<div class="fadediv">
<p>Yes, you heard that right. Well its more like a File Share but "Clip dump" is still pretty accurate,
and rolls off the tongue better.<br>
Here you'll mainly find just clips of me playin games and stuff. Its not really something designed to be
"looked through"
but I decided why not. It's not very organized so be warned!</p>
<ul>
{CONTENT}
</ul>
</div>
</body>
</html>