General fixes
This commit is contained in:
parent
d5402f3aa4
commit
c08af44759
2 changed files with 21 additions and 18 deletions
34
index.js
34
index.js
|
@ -105,35 +105,35 @@ app.get("/*", (req, res) => {
|
|||
var file = req.params[0]
|
||||
var absPath = path.join(pubDir, file)
|
||||
|
||||
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)
|
||||
var html = fs.readFileSync(path.join(__dirname, 'resources/base.html')).toString()
|
||||
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
|
||||
var addedHTML = ""
|
||||
|
||||
res.setHeader("X-Accel-Buffering", "no")
|
||||
html = html.replace("{TITLE}", '/' + file)
|
||||
|
||||
try {
|
||||
var dirContents = fs.readdirSync(absPath)
|
||||
var dirStats = fs.statSync(absPath)
|
||||
} 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
|
||||
}
|
||||
|
||||
res.write(baseStart.replace("{TITLE}", '/' + file))
|
||||
|
||||
res.write(`<h3>${dirContents.length} Files</h3>`)
|
||||
addedHTML += `<h3>${dirContents.length} Files</h3>`.trim()
|
||||
|
||||
if (file != '') {
|
||||
res.write('<a href="../">Parent Directory</a><br>')
|
||||
addedHTML += '<a href="../">Parent Directory</a><br>'
|
||||
}
|
||||
|
||||
var dirs = []
|
||||
|
||||
var ogFolder = file
|
||||
|
||||
addedHTML += "<ul>"
|
||||
|
||||
for (let index = 0; index < dirContents.length; index++) {
|
||||
const file = dirContents[index];
|
||||
var userPath = path.join(ogFolder, file)
|
||||
|
@ -143,9 +143,9 @@ app.get("/*", (req, res) => {
|
|||
if (!fileStats.isDirectory()) {
|
||||
var fileExtension = file.substring(file.lastIndexOf('.') + 1, )
|
||||
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 {
|
||||
res.write(`<li><a href="./${file}">${file}</a> | ${humanFileSize(fileStats.size)}</li>`)
|
||||
addedHTML += `<li><a href="./${file}">${file}</a> | ${humanFileSize(fileStats.size)}</li>`
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -158,14 +158,18 @@ app.get("/*", (req, res) => {
|
|||
|
||||
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(baseEnd)
|
||||
addedHTML += "</ul>"
|
||||
|
||||
res.end()
|
||||
html = html.replace("{CONTENT}", addedHTML)
|
||||
|
||||
res.write(html, () => {
|
||||
res.end()
|
||||
})
|
||||
})
|
||||
|
||||
process.on('uncaughtException', (err, origin) => {
|
||||
|
|
|
@ -13,10 +13,9 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<h1>The Violet Archive</h1>
|
||||
<div class="fadediv">
|
||||
<ul>
|
||||
{CONTENT}
|
||||
</ul>
|
||||
{CONTENT}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
|
|
Loading…
Reference in a new issue