diff --git a/.gitignore b/.gitignore index 8ad17db..48768d8 100644 --- a/.gitignore +++ b/.gitignore @@ -132,4 +132,5 @@ dist # Violet's Limbo testPath -public \ No newline at end of file +public +private \ No newline at end of file diff --git a/index.js b/index.js index 529cb20..9cbb07c 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var PORT = process.env.PORT || 8080 var directory = process.env.FILES_DIR var pubDir = path.join(directory, 'public') +var privDir = path.join(directory, 'private') function humanFileSize(bytes, si = false, dp = 1) { const thresh = si ? 1000 : 1024; @@ -38,7 +39,7 @@ if (!directory) { const videoFormats = ["mp4", "mkv", "webm"] -app.use(express.static(directory)) +app.use(express.static(privDir)) app.use(express.static(pubDir)) app.use(express.static(path.join(__dirname, 'resources'))) @@ -46,32 +47,6 @@ app.listen(PORT, () => { console.log("Now listening on PORT: " + PORT) }) -app.get("/watch/*", (req, res) => { - res.setHeader("Content-Type", "text/html") - - var video = req.params[0] - var absPath = path.join(directory, video) - if (!fs.existsSync(absPath)) { - absPath = path.join(pubDir, video) - } - - var html = fs.readFileSync(path.join(__dirname, 'resources/watch.html')).toString() - - html = html.replaceAll("{VID_PATH}", video) - - var vidTitle = video.substring(video.lastIndexOf('/') + 1, video.lastIndexOf('.')) - - var vidStats = fs.statSync(absPath) - - html = html.replaceAll("{TITLE}", vidTitle) - - html = html.replaceAll("{VID_INFO}", `Size: ${humanFileSize(vidStats.size)}`) - - html = html.replaceAll("{BACK}", "/" + video.substring(0, video.lastIndexOf("/"))) - - res.send(html) -}) - app.get("/download/*", (req, res) => { var download = req.params[0] var downloadPath = path.join(directory, download) @@ -87,6 +62,11 @@ app.get("/download/*", (req, res) => { stream.pipe(res) }) +app.get("/watch/*", (req, res) => { + console.log(req.params[0]) + res.redirect("/" + req.params[0]) +}) + app.get("/*", (req, res) => { var file = req.params[0] var absPath = path.join(pubDir, file) @@ -127,13 +107,7 @@ app.get("/*", (req, res) => { var fileStats = fs.statSync(path.join(absPath, file)) if (!fileStats.isDirectory()) { - var fileExtension = file.substring(file.lastIndexOf('.') + 1, ) - if (videoFormats.includes(fileExtension)) { - addedHTML += `
  • ${file} | ${humanFileSize(fileStats.size)} | download
  • ` - } else { - addedHTML += `
  • ${file} | ${humanFileSize(fileStats.size)} | download
  • ` - } - + addedHTML += `
  • ${file} | ${humanFileSize(fileStats.size)} | download
  • ` } else { dirs.push(file) } diff --git a/resources/watch.html b/resources/watch.html deleted file mode 100644 index 6cecfe5..0000000 --- a/resources/watch.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - {TITLE} - - - -

    {TITLE}

    -

    Back

    -

    {VID_INFO}

    -

    Download | Generate QuickURL link

    -
    - -
    - - - \ No newline at end of file