Save user agent for dearrow

This commit is contained in:
Ajay 2025-04-17 01:05:34 -04:00
parent ed5a397a30
commit 3d596f4528
2 changed files with 14 additions and 4 deletions

View file

@ -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;

View file

@ -19,6 +19,7 @@ import axios from "axios";
import { getMaxResThumbnail } from "../utils/youtubeApi"; import { getMaxResThumbnail } from "../utils/youtubeApi";
import { getVideoDetails } from "../utils/getVideoDetails"; import { getVideoDetails } from "../utils/getVideoDetails";
import { canSubmitDeArrow } from "../utils/permissions"; import { canSubmitDeArrow } from "../utils/permissions";
import { parseUserAgent } from "../utils/userAgent";
enum BrandingType { enum BrandingType {
Title, Title,
@ -39,6 +40,7 @@ interface ExistingVote {
export async function postBranding(req: Request, res: Response) { export async function postBranding(req: Request, res: Response) {
const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration, wasWarned, casualMode } = req.body as BrandingSubmission; const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration, wasWarned, casualMode } = req.body as BrandingSubmission;
const service = getService(req.body.service); const service = getService(req.body.service);
const userAgent = req.body.userAgent ?? parseUserAgent(req.get("user-agent")) ?? "";
if (!videoID || !userID || userID.length < 30 || !service if (!videoID || !userID || userID.length < 30 || !service
|| ((!title || !title.title) || ((!title || !title.title)
@ -109,8 +111,8 @@ export async function postBranding(req: Request, res: Response) {
throw new Error("Title submission doesn't exist"); 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 (?, ?, ?, ?, ?, ?, ?, ?, ?)`, 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]); [videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, casualMode ? 1 : 0, userAgent]);
const verificationValue = await getVerificationValue(hashedUserID, isVip); const verificationValue = await getVerificationValue(hashedUserID, isVip);
await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, 0, ?, ?, ?);`, 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"); throw new Error("Thumbnail submission doesn't exist");
} }
await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID", "casualMode") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, 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]); [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, ?, ?)`, await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, ?)`,
[UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0]); [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0]);