Allow voting and viewing with partial UUID

This commit is contained in:
Ajay
2025-01-18 02:04:27 -05:00
parent 80b1019783
commit 06f83cd8d4
3 changed files with 34 additions and 6 deletions

View File

@@ -3,14 +3,18 @@ import { Request, Response } from "express";
export async function viewedVideoSponsorTime(req: Request, res: Response): Promise<Response> {
const UUID = req.query?.UUID;
const videoID = req.query?.videoID;
if (!UUID) {
//invalid request
return res.sendStatus(400);
}
//up the view count by one
await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1 WHERE "UUID" = ?`, [UUID]);
if (!videoID) {
await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1 WHERE "UUID" = ?`, [UUID]);
} else {
await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1 WHERE "UUID" LIKE ? AND "videoID" = ?`, [`${UUID}%`, videoID]);
}
return res.sendStatus(200);
}

View File

@@ -303,9 +303,10 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
const paramUserID = getUserID(req);
const type = req.query.type !== undefined ? parseInt(req.query.type as string) : undefined;
const category = req.query.category as Category;
const videoID = req.query.videoID as VideoID;
const ip = getIP(req);
const result = await vote(ip, UUID, paramUserID, type, category);
const result = await vote(ip, UUID, paramUserID, type, videoID, category);
const response = res.status(result.status);
if (result.message) {
@@ -317,7 +318,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
}
}
export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID, type: number, category?: Category): Promise<{ status: number, message?: string, json?: unknown }> {
export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID, type: number, videoID?: VideoID, category?: Category): Promise<{ status: number, message?: string, json?: unknown }> {
// missing key parameters
if (!UUID || !paramUserID || !(type !== undefined || category)) {
return { status: 400 };
@@ -327,6 +328,14 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
return { status: 200 };
}
if (videoID && UUID.length < 60) {
// Get the full UUID
const segmentInfo: DBSegment = await db.prepare("get", `SELECT "UUID" from "sponsorTimes" WHERE "UUID" LIKE ? AND "videoID" = ?`, [`${UUID}%`, videoID]);
if (segmentInfo) {
UUID = segmentInfo.UUID;
}
}
const originalType = type;
//hash the userID