Add description and created fields to videos
This commit is contained in:
parent
3f1648da32
commit
1cc2908933
9
index.js
9
index.js
@ -180,7 +180,7 @@ app.get("/api/logout", authorized(), (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/api/upload-video", authorized(), fileUpload({ limits: { fileSize: 2 ** 26 }, useTempFiles: true }), async (req, res) => {
|
||||
const { title } = req.body;
|
||||
const { title, description } = req.body;
|
||||
if (!title) {
|
||||
return res.status(400).json({ ok: false, error: "bad request" });
|
||||
}
|
||||
@ -229,7 +229,10 @@ app.post("/api/upload-video", authorized(), fileUpload({ limits: { fileSize: 2 *
|
||||
return;
|
||||
}
|
||||
|
||||
dbRun("INSERT INTO videos (id, user_id, title) VALUES (?, ?, ?)", id, userId, title);
|
||||
dbRun(
|
||||
"INSERT INTO videos (id, user_id, title, description, created_at) VALUES (?, ?, ?, ?, ?)",
|
||||
id, userId, title, description ?? "", new Date().toISOString()
|
||||
);
|
||||
|
||||
const index = videoQueue.indexOf(item => item.videoId === queueItem.videoId)
|
||||
videoQueue.splice(index, 1);
|
||||
@ -250,7 +253,7 @@ app.get("/api/video-info", async (req, res) => {
|
||||
const id = req.query["id"];
|
||||
|
||||
const video = await dbGet(`
|
||||
SELECT videos.id, videos.title, users.username AS author
|
||||
SELECT videos.id, videos.title, videos.description, videos.created_at, users.username AS author
|
||||
FROM videos
|
||||
JOIN users ON users.id = videos.user_id
|
||||
WHERE videos.id = ?
|
||||
|
@ -8,6 +8,8 @@ CREATE TABLE videos (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
user_id INTEGER,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id)
|
||||
);
|
||||
|
||||
|
@ -1,20 +1,39 @@
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
|
||||
--red: #c51e0e;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--red: #F4511E;
|
||||
}
|
||||
}
|
||||
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
*:focus {
|
||||
outline: 2px solid var(--red);
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0 auto;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--red);
|
||||
}
|
||||
|
||||
textarea, input {
|
||||
font-family: sans-serif;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
nav {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
@ -135,7 +154,3 @@ input::file-selector-button {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--red);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
<title>MaoTube</title>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script defer src="/header.js"></script>
|
||||
<script defer src="/helpers.js"></script>
|
||||
<script defer src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
@ -12,6 +13,8 @@
|
||||
<form id="upload-form" method="POST" action="/api/upload-video" enctype="multipart/form-data">
|
||||
<label for="title"><p>Title</p></label>
|
||||
<input type="text" name="title" id="title" required autofocus>
|
||||
<label for="description"><p>Description</p></label>
|
||||
<textarea name="description" id="description"></textarea>
|
||||
<label for="video"><p>Video</p></label>
|
||||
<input type="file" name="video" id="video" required>
|
||||
<br><br>
|
||||
@ -19,6 +22,18 @@
|
||||
<br><br>
|
||||
<a href="/queue">View upload queue</a>
|
||||
</form>
|
||||
|
||||
<noscript>
|
||||
<div class="mao-error">
|
||||
<p>javascript not enabled</p>
|
||||
<p>bottom text</p>
|
||||
</div>
|
||||
</noscript>
|
||||
|
||||
<div id="mao-error" class="mao-error hidden">
|
||||
<p id="mao-error-message"></p>
|
||||
<p>bottom text</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
@ -1,14 +1,22 @@
|
||||
document.getElementById("upload-form").addEventListener("submit", async event => {
|
||||
document.getElementById("upload-form").addEventListener("submit", event => {
|
||||
event.preventDefault();
|
||||
|
||||
const data = new FormData(event.target);
|
||||
console.log(data);
|
||||
|
||||
await fetch("/api/upload-video", {
|
||||
fetch("/api/upload-video", {
|
||||
method: "POST",
|
||||
body: data,
|
||||
});
|
||||
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
error(response.error);
|
||||
return;
|
||||
}
|
||||
|
||||
location.href = "/queue";
|
||||
})
|
||||
.catch(err => {
|
||||
error("failed to upload video");
|
||||
});
|
||||
});
|
||||
|
@ -4,6 +4,8 @@
|
||||
<meta charset="utf-8">
|
||||
<title>MaoTube</title>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script defer src="script.js"></script>
|
||||
<script defer src="/header.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>MaoTube</h1>
|
||||
@ -12,7 +14,11 @@
|
||||
<div id="video-result">
|
||||
<video id="video-player"></video>
|
||||
<h1 id="video-title"></h1>
|
||||
<span id="video-author"></span>
|
||||
<p id="video-author"></p>
|
||||
<br>
|
||||
<hr>
|
||||
<br>
|
||||
<p id="video-description"></p>
|
||||
</div>
|
||||
|
||||
<noscript>
|
||||
@ -27,8 +33,6 @@
|
||||
<p>bottom text</p>
|
||||
</div>
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
<script src="/header.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
@ -41,7 +41,8 @@ async function main() {
|
||||
}
|
||||
|
||||
document.getElementById("video-title").innerText = video.title;
|
||||
document.getElementById("video-author").innerText = "by " + video.author;
|
||||
document.getElementById("video-author").innerText = "by " + video.author + " - published " + new Date(video.created_at).toLocaleDateString();
|
||||
document.getElementById("video-description").innerText = video.description;
|
||||
|
||||
document.getElementById("video-result").style.display = "block";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user