General fixes

This commit is contained in:
bingus_violet 2024-04-23 13:05:34 -05:00
parent d5402f3aa4
commit c08af44759
2 changed files with 21 additions and 18 deletions

View file

@ -105,35 +105,35 @@ app.get("/*", (req, res) => {
var file = req.params[0] var file = req.params[0]
var absPath = path.join(pubDir, file) var absPath = path.join(pubDir, file)
var baseHTML = fs.readFileSync(path.join(__dirname, 'resources/base.html')).toString() var html = 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)
res.setHeader('Content-Type', 'text/html') res.setHeader('Content-Type', 'text/html')
res.setHeader("X-Accel-Buffering", "no") var addedHTML = ""
html = html.replace("{TITLE}", '/' + file)
try { try {
var dirContents = fs.readdirSync(absPath) var dirContents = fs.readdirSync(absPath)
var dirStats = fs.statSync(absPath) var dirStats = fs.statSync(absPath)
} catch (error) { } catch (error) {
res.send(baseStart.replace("{TITLE}", "404: not found!") + "<h2>404: not found!</h2>" + baseEnd) html = html.replace("{CONTENT}", "<h3>404: not found!</h3><a href='/'>Go to root</a>")
res.send(html)
return return
} }
res.write(baseStart.replace("{TITLE}", '/' + file)) addedHTML += `<h3>${dirContents.length} Files</h3>`.trim()
res.write(`<h3>${dirContents.length} Files</h3>`)
if (file != '') { if (file != '') {
res.write('<a href="../">Parent Directory</a><br>') addedHTML += '<a href="../">Parent Directory</a><br>'
} }
var dirs = [] var dirs = []
var ogFolder = file var ogFolder = file
addedHTML += "<ul>"
for (let index = 0; index < dirContents.length; index++) { for (let index = 0; index < dirContents.length; index++) {
const file = dirContents[index]; const file = dirContents[index];
var userPath = path.join(ogFolder, file) var userPath = path.join(ogFolder, file)
@ -143,9 +143,9 @@ app.get("/*", (req, res) => {
if (!fileStats.isDirectory()) { if (!fileStats.isDirectory()) {
var fileExtension = file.substring(file.lastIndexOf('.') + 1, ) var fileExtension = file.substring(file.lastIndexOf('.') + 1, )
if (videoFormats.includes(fileExtension)) { if (videoFormats.includes(fileExtension)) {
res.write(`<li><a href="/watch/${userPath}">${file}</a> | ${humanFileSize(fileStats.size)}</li>`) addedHTML += `<li><a href="/watch/${userPath}">${file}</a> | ${humanFileSize(fileStats.size)}</li>`
} else { } else {
res.write(`<li><a href="./${file}">${file}</a> | ${humanFileSize(fileStats.size)}</li>`) addedHTML += `<li><a href="./${file}">${file}</a> | ${humanFileSize(fileStats.size)}</li>`
} }
} else { } else {
@ -158,14 +158,18 @@ app.get("/*", (req, res) => {
var fileStats = fs.statSync(path.join(absPath, file)) var fileStats = fs.statSync(path.join(absPath, file))
res.write(`<li><a href="./${file}">./${file}/</a></li>`) addedHTML += `<li><a href="./${file}">./${file}/</a></li>`
} }
// res.write(`<a href="./${file}">./${file}/</a><br>`) // res.write(`<a href="./${file}">./${file}/</a><br>`)
res.write(baseEnd) addedHTML += "</ul>"
res.end() html = html.replace("{CONTENT}", addedHTML)
res.write(html, () => {
res.end()
})
}) })
process.on('uncaughtException', (err, origin) => { process.on('uncaughtException', (err, origin) => {

View file

@ -13,10 +13,9 @@
</head> </head>
<body> <body>
<h1>The Violet Archive</h1>
<div class="fadediv"> <div class="fadediv">
<ul> {CONTENT}
{CONTENT}
</ul>
</div> </div>
</body> </body>