NO MORE WATCHING VIDEOS

This commit is contained in:
bingus_violet 2024-09-16 17:13:24 -05:00
parent 20596f374b
commit c435b38331
3 changed files with 10 additions and 70 deletions

3
.gitignore vendored
View file

@ -132,4 +132,5 @@ dist
# Violet's Limbo
testPath
public
public
private

View file

@ -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 += `<li><a href="/watch/${userPath}">${file}</a> | ${humanFileSize(fileStats.size)} | <a href="/download/${userPath}">download</a></li>`
} else {
addedHTML += `<li><a href="./${file}">${file}</a> | ${humanFileSize(fileStats.size)} | <a href="/download/${userPath}">download</a></li>`
}
addedHTML += `<li><a href="./${file}">${file}</a> | ${humanFileSize(fileStats.size)} | <a href="/download/${userPath}">download</a></li>`
} else {
dirs.push(file)
}

View file

@ -1,35 +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">
<link rel="stylesheet" href="/style.css">
<meta property="og:site_name" content="Violet's Clipdump">
<meta property="og:url" content="https://fs.violets-purgatory.dev/watch/{VID_PATH}">
<meta property="og:type" content="video.other">
<meta property="og:title" content="{TITLE} ({VID_INFO})">
<meta property="og:video" content="https://fs.violets-purgatory.dev/{VID_PATH}">
<meta property="og:video:type" content="video/mp4">
<meta property="og:video:secure_url" content="https://fs.violets-purgatory.dev/{VID_PATH}">
<meta property="og:video:height" content="720">
<meta property="og:video:width" content="1280">
<title>{TITLE}</title>
</head>
<body>
<h1>{TITLE}</h1>
<p><a href="{BACK}">Back</a></p>
<p>{VID_INFO}</p>
<p><a href="/download/{VID_PATH}">Download</a> | <a href="https://url.viois.gay/makeURL?url=https%3A%2F%2Ffs.violets-purgatory.dev%2Fwatch%2F{VID_PATH}">Generate QuickURL link</a></p>
<div class="fadediv">
<video src="/{VID_PATH}" width="100%" controls></video>
</div>
</body>
</html>