Save more info in unlisted video endpoint

This commit is contained in:
Ajay Ramachandran 2021-06-23 23:58:33 -04:00
parent 15b3cb20b3
commit c5245cb8e2
2 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,15 @@
BEGIN TRANSACTION;
DROP TABLE "unlistedVideos";
CREATE TABLE IF NOT EXISTS "unlistedVideos" (
"videoID" TEXT NOT NULL,
"year" TEXT NOT NULL,
"views" TEXT NOT NULL,
"channelID" TEXT NOT NULL,
"timeSubmitted" INTEGER NOT NULL
);
UPDATE "config" SET value = 16 WHERE key = 'version';
COMMIT;

View file

@ -12,6 +12,9 @@ import { Logger } from '../utils/logger';
export function addUnlistedVideo(req: Request, res: Response) {
const videoID = req.body.videoID;
const year = req.body.year || 0;
const views = req.body.views || 0;
const channelID = req.body.channelID || "Unknown";
if (videoID === undefined || typeof(videoID) !== "string" || videoID.length !== 11) {
res.status(400).send("Invalid parameters");
@ -20,7 +23,7 @@ export function addUnlistedVideo(req: Request, res: Response) {
try {
const timeSubmitted = Date.now();
db.prepare('run', `INSERT INTO "unlistedVideos" ("videoID", "timeSubmitted") values (?, ?)`, [videoID, timeSubmitted]);
db.prepare('run', `INSERT INTO "unlistedVideos" ("videoID", "year", "views", "channelID", "timeSubmitted") values (?, ?, ?, ?, ?)`, [videoID, year, views, channelID, timeSubmitted]);
} catch (err) {
Logger.error(err);
res.sendStatus(500);