From 3d596f4528b256d70d40734bacd9f01b84f3a14c Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 17 Apr 2025 01:05:34 -0400 Subject: [PATCH] Save user agent for dearrow --- databases/_upgrade_sponsorTimes_44.sql | 8 ++++++++ src/routes/postBranding.ts | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 databases/_upgrade_sponsorTimes_44.sql diff --git a/databases/_upgrade_sponsorTimes_44.sql b/databases/_upgrade_sponsorTimes_44.sql new file mode 100644 index 0000000..1066c2f --- /dev/null +++ b/databases/_upgrade_sponsorTimes_44.sql @@ -0,0 +1,8 @@ +BEGIN TRANSACTION; + +ALTER TABLE "titles" ADD "userAgent" TEXT NOT NULL default ''; +ALTER TABLE "thumbnails" ADD "userAgent" TEXT NOT NULL default ''; + +UPDATE "config" SET value = 44 WHERE key = 'version'; + +COMMIT; diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index eb67598..12ae505 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -19,6 +19,7 @@ import axios from "axios"; import { getMaxResThumbnail } from "../utils/youtubeApi"; import { getVideoDetails } from "../utils/getVideoDetails"; import { canSubmitDeArrow } from "../utils/permissions"; +import { parseUserAgent } from "../utils/userAgent"; enum BrandingType { Title, @@ -39,6 +40,7 @@ interface ExistingVote { export async function postBranding(req: Request, res: Response) { const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration, wasWarned, casualMode } = req.body as BrandingSubmission; const service = getService(req.body.service); + const userAgent = req.body.userAgent ?? parseUserAgent(req.get("user-agent")) ?? ""; if (!videoID || !userID || userID.length < 30 || !service || ((!title || !title.title) @@ -109,8 +111,8 @@ export async function postBranding(req: Request, res: Response) { throw new Error("Title submission doesn't exist"); } - await db.prepare("run", `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID", "casualMode") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, - [videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, casualMode ? 1 : 0]); + await db.prepare("run", `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID", "casualMode", "userAgent") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + [videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, casualMode ? 1 : 0, userAgent]); const verificationValue = await getVerificationValue(hashedUserID, isVip); await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, 0, ?, ?, ?);`, @@ -151,8 +153,8 @@ export async function postBranding(req: Request, res: Response) { throw new Error("Thumbnail submission doesn't exist"); } - await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID", "casualMode") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, - [videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, casualMode ? 1 : 0]); + await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID", "casualMode", "userAgent") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, + [videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, casualMode ? 1 : 0, userAgent]); await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, ?)`, [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0]);