From 1e05c04a39d75fa802c8d7e7e27dd739deb9141d Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 5 Sep 2021 22:40:40 -0400 Subject: [PATCH] Allow mute and skip segments with same times --- src/routes/postSkipSegments.ts | 4 ++-- src/utils/getSubmissionUUID.ts | 2 +- test/cases/getSubmissionUUID.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index 054fe6b..f726cfa 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -349,7 +349,7 @@ function checkInvalidFields(videoID: any, userID: any, segments: Array): Ch } async function checkEachSegmentValid(userID: string, videoID: VideoID, - segments: Array, service: string, isVIP: boolean, lockedCategoryList: Array): Promise { + segments: IncomingSegment[], service: string, isVIP: boolean, lockedCategoryList: Array): Promise { for (let i = 0; i < segments.length; i++) { if (segments[i] === undefined || segments[i].segment === undefined || segments[i].category === undefined) { @@ -406,7 +406,7 @@ async function checkEachSegmentValid(userID: string, videoID: VideoID, //check if this info has already been submitted before const duplicateCheck2Row = await db.prepare("get", `SELECT COUNT(*) as count FROM "sponsorTimes" WHERE "startTime" = ? - and "endTime" = ? and "category" = ? and "videoID" = ? and "service" = ?`, [startTime, endTime, segments[i].category, videoID, service]); + and "endTime" = ? and "category" = ? and "actionType" = ? and "videoID" = ? and "service" = ?`, [startTime, endTime, segments[i].category, segments[i].actionType, videoID, service]); if (duplicateCheck2Row.count > 0) { return { pass: false, errorMessage: "Sponsors has already been submitted before.", errorCode: 409}; } diff --git a/src/utils/getSubmissionUUID.ts b/src/utils/getSubmissionUUID.ts index 4fbd046..c62610c 100644 --- a/src/utils/getSubmissionUUID.ts +++ b/src/utils/getSubmissionUUID.ts @@ -4,5 +4,5 @@ import { ActionType, VideoID } from "../types/segments.model"; import { UserID } from "../types/user.model"; export function getSubmissionUUID(videoID: VideoID, actionType: ActionType, userID: UserID, startTime: number, endTime: number): HashedValue{ - return `3${getHash(`v3${videoID}${startTime}${endTime}${userID}`, 1)}` as HashedValue; + return `4${getHash(`${videoID}${startTime}${endTime}${userID}${actionType}`, 1)}` as HashedValue; } diff --git a/test/cases/getSubmissionUUID.ts b/test/cases/getSubmissionUUID.ts index e39cecb..e71ef9b 100644 --- a/test/cases/getSubmissionUUID.ts +++ b/test/cases/getSubmissionUUID.ts @@ -5,6 +5,6 @@ import { UserID } from "../../src/types/user.model"; describe("getSubmissionUUID", () => { it("Should return the hashed value", () => { - assert.strictEqual(getSubmissionUUID("video001" as VideoID, "skip" as ActionType, "testuser001" as UserID, 13.33337, 42.000001), "3572aa64e0a2d6352c3de14ca45f8a83d193c32635669a7ae0b40c9eb36395872"); + assert.strictEqual(getSubmissionUUID("video001" as VideoID, "skip" as ActionType, "testuser001" as UserID, 13.33337, 42.000001), "48ad47e445e67a7b963d9200037b36ec706eddcb752fdadc7bb2f061b56be6a23"); }); });