deleting videos, 404

This commit is contained in:
biglyderv 2024-11-25 14:12:44 -05:00
parent b38fb151ac
commit 62645ddd93
8 changed files with 67 additions and 5 deletions

11
client/e404.js Normal file
View file

@ -0,0 +1,11 @@
import Route from "../route.js";
import auth from "../form/auth.js";
let main = new Route([auth], async function (req, res, input) {
let { username } = input;
return res.render('404', {
username
});
});
export default main;

View file

@ -8,6 +8,7 @@ let main = new Route([comment], async function (req, res, input) {
let videoData = await db.all('SELECT * FROM video WHERE id = ?', [
req.query.id
]);
if (videoData.length == 0) return;
videoData = videoData[0];
return res.render('player', {
...input,

View file

@ -22,6 +22,10 @@ let main = new Route([comment], async function (req, res, input) {
req.query.id
]);
if (user.length == 0) {
return;
}
return res.render('user', {
...input,
id,

23
form/delete_video.js Normal file
View file

@ -0,0 +1,23 @@
import Route from "../route.js";
import initDb from "../db.js";
import { randomUUID } from 'node:crypto';
import auth from "../form/auth.js";
let db = await initDb();
// TODO: rewrite
let main = new Route([auth], async function (req, res, input) {
let { username } = input;
let { target } = req.body;
if (!target ) return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
await db.run('DELETE FROM video WHERE id = ? AND username = ?', [
target,
username
]);
return { 'message': 'Video deleted', 'success': true};
});
export default main;

View file

@ -41,6 +41,10 @@ app.get('/pfp/*', (req,res) => {
res.redirect(301,'/static/img/logo.svg')
})
app.get('*', (req,res) => {
res.redirect(301,'/client/404');
})
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})

View file

@ -5,6 +5,7 @@ import upload from "./client/upload.js";
import player from "./client/player.js";
import user from "./client/user.js";
import settings from "./client/settings.js";
import e404 from "./client/e404.js";
import loginB from "./form/login.js";
import registerB from "./form/register.js";
@ -13,6 +14,7 @@ import commentB from "./form/comment.js";
import settingsB from "./form/settings.js";
import auth from "./form/auth.js";
import auth_api from "./form/auth_api.js";
import delete_video from "./form/delete_video.js";
import follow from './form/follow.js';
const routes = {
@ -28,7 +30,8 @@ routes.client = {
upload,
video: player,
user,
settings
settings,
e404
}
routes.get = {
@ -42,7 +45,8 @@ routes.form = {
comment: commentB,
follow,
settings: settingsB,
auth_api
auth_api,
delete_video
};
async function iterate(req, res, index) {
@ -51,11 +55,18 @@ async function iterate(req, res, index) {
let cmd = req.params.route;
if (keys.indexOf(cmd) == -1) {
res.status(404).send('fail');
routesI['e404'].run(req, res, {});
return;
}
return await routesI[cmd].run(req, res, {});
let dat = await routesI[cmd].run(req, res, {});
if (!dat) {
routesI['e404'].run(req, res, {});
return;
}
return dat;
}
export default iterate;

6
views/404.ejs Normal file
View file

@ -0,0 +1,6 @@
<%- include('header.ejs') -%>
<div class='content'>
<h2>Oops!</h2>
<p>This page was not found.</p>
</div>
<%- include('footer.ejs') -%>

View file

@ -1,5 +1,5 @@
<%- include('header.ejs') -%>
<div class='content'>
<form class='content' enctype='multipart/form-data' method='POST' action='/api/form/delete_video'>
<h1>Video</h1>
<div class='video-wrapper'>
<video src='/videos/<%= videoData.id %>.webm'></video>
@ -28,6 +28,8 @@
</div>
</div>
<pre class='form-input'><%= videoData.desc %></pre>
<input class='form-input' type='submit' value="Delete">
<input name='target' hidden value="<%= id %>">
</div>
<%- include('comments.ejs') -%>
<%- include('footer.ejs') -%>