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) => {
|
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) {
|
if (!title) {
|
||||||
return res.status(400).json({ ok: false, error: "bad request" });
|
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;
|
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)
|
const index = videoQueue.indexOf(item => item.videoId === queueItem.videoId)
|
||||||
videoQueue.splice(index, 1);
|
videoQueue.splice(index, 1);
|
||||||
@ -250,7 +253,7 @@ app.get("/api/video-info", async (req, res) => {
|
|||||||
const id = req.query["id"];
|
const id = req.query["id"];
|
||||||
|
|
||||||
const video = await dbGet(`
|
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
|
FROM videos
|
||||||
JOIN users ON users.id = videos.user_id
|
JOIN users ON users.id = videos.user_id
|
||||||
WHERE videos.id = ?
|
WHERE videos.id = ?
|
||||||
|
@ -8,6 +8,8 @@ CREATE TABLE videos (
|
|||||||
id TEXT PRIMARY KEY NOT NULL,
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
user_id INTEGER,
|
user_id INTEGER,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
|
description TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
FOREIGN KEY(user_id) REFERENCES users(id)
|
FOREIGN KEY(user_id) REFERENCES users(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,20 +1,39 @@
|
|||||||
*, *::before, *::after {
|
|
||||||
box-sizing: border-box;
|
|
||||||
appearance: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
|
|
||||||
--red: #c51e0e;
|
--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 {
|
body {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--red);
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea, input {
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 0.8em;
|
||||||
|
}
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
@ -135,7 +154,3 @@ input::file-selector-button {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
|
||||||
color: var(--red);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<title>MaoTube</title>
|
<title>MaoTube</title>
|
||||||
<link rel="stylesheet" href="/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
<script defer src="/header.js"></script>
|
<script defer src="/header.js"></script>
|
||||||
|
<script defer src="/helpers.js"></script>
|
||||||
<script defer src="script.js"></script>
|
<script defer src="script.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -12,6 +13,8 @@
|
|||||||
<form id="upload-form" method="POST" action="/api/upload-video" enctype="multipart/form-data">
|
<form id="upload-form" method="POST" action="/api/upload-video" enctype="multipart/form-data">
|
||||||
<label for="title"><p>Title</p></label>
|
<label for="title"><p>Title</p></label>
|
||||||
<input type="text" name="title" id="title" required autofocus>
|
<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>
|
<label for="video"><p>Video</p></label>
|
||||||
<input type="file" name="video" id="video" required>
|
<input type="file" name="video" id="video" required>
|
||||||
<br><br>
|
<br><br>
|
||||||
@ -19,6 +22,18 @@
|
|||||||
<br><br>
|
<br><br>
|
||||||
<a href="/queue">View upload queue</a>
|
<a href="/queue">View upload queue</a>
|
||||||
</form>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
document.getElementById("upload-form").addEventListener("submit", async event => {
|
document.getElementById("upload-form").addEventListener("submit", event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const data = new FormData(event.target);
|
const data = new FormData(event.target);
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
await fetch("/api/upload-video", {
|
fetch("/api/upload-video", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: data,
|
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");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
location.href = "/queue";
|
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>MaoTube</title>
|
<title>MaoTube</title>
|
||||||
<link rel="stylesheet" href="/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
|
<script defer src="script.js"></script>
|
||||||
|
<script defer src="/header.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>MaoTube</h1>
|
<h1>MaoTube</h1>
|
||||||
@ -12,7 +14,11 @@
|
|||||||
<div id="video-result">
|
<div id="video-result">
|
||||||
<video id="video-player"></video>
|
<video id="video-player"></video>
|
||||||
<h1 id="video-title"></h1>
|
<h1 id="video-title"></h1>
|
||||||
<span id="video-author"></span>
|
<p id="video-author"></p>
|
||||||
|
<br>
|
||||||
|
<hr>
|
||||||
|
<br>
|
||||||
|
<p id="video-description"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<noscript>
|
<noscript>
|
||||||
@ -27,8 +33,6 @@
|
|||||||
<p>bottom text</p>
|
<p>bottom text</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="script.js"></script>
|
|
||||||
<script src="/header.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("video-title").innerText = video.title;
|
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";
|
document.getElementById("video-result").style.display = "block";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user