mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 07:27:01 +03:00
routes/addUnlistedVideo: Improved
This commit is contained in:
@@ -10,24 +10,33 @@ import { Logger } from "../utils/logger";
|
|||||||
* https://support.google.com/youtube/answer/9230970
|
* https://support.google.com/youtube/answer/9230970
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function addUnlistedVideo(req: Request, res: Response): Response {
|
export async function addUnlistedVideo(req: Request, res: Response): Promise<Response> {
|
||||||
const videoID = req.body.videoID;
|
const {
|
||||||
const year = req.body.year || 0;
|
body: {
|
||||||
const views = req.body.views || 0;
|
videoID = null,
|
||||||
const channelID = req.body.channelID || "Unknown";
|
year = 0,
|
||||||
const service = getService(req.body.service);
|
views = 0,
|
||||||
|
channelID = "Unknown",
|
||||||
|
service
|
||||||
|
}
|
||||||
|
} = req;
|
||||||
|
|
||||||
if (videoID === undefined || typeof(videoID) !== "string" || videoID.length !== 11) {
|
if (typeof(videoID) !== "string" || videoID.length !== 11) {
|
||||||
return res.status(400).send("Invalid parameters");
|
return res.status(400).send("Invalid parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const timeSubmitted = Date.now();
|
const timeSubmitted = Date.now();
|
||||||
db.prepare("run", `INSERT INTO "unlistedVideos" ("videoID", "year", "views", "channelID", "timeSubmitted", "service") values (?, ?, ?, ?, ?, ?)`, [videoID, year, views, channelID, timeSubmitted, service]);
|
await db.prepare(
|
||||||
|
"run",
|
||||||
|
`INSERT INTO "unlistedVideos" ("videoID", "year", "views", "channelID", "timeSubmitted", "service") values (?, ?, ?, ?, ?, ?)`,
|
||||||
|
[videoID, year, views, channelID, timeSubmitted, getService(service)]
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.sendStatus(200);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error(err as string);
|
Logger.error(err as string);
|
||||||
return res.sendStatus(500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.sendStatus(200);
|
return res.sendStatus(500);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user