From c60b82d40a7df61ede69099666834329ffc16a6d Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 20 Jul 2021 12:38:45 -0400 Subject: [PATCH] Only treat video as changed duration if both submitted and api agree --- src/routes/postSkipSegments.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index dd132f8..a70c49e 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -319,7 +319,8 @@ export async function postSkipSegments(req: Request, res: Response): Promise val === service)) { service = Service.YouTube; } - let videoDuration: VideoDuration = (parseFloat(req.query.videoDuration || req.body.videoDuration) || 0) as VideoDuration; + const videoDurationParam: VideoDuration = (parseFloat(req.query.videoDuration || req.body.videoDuration) || 0) as VideoDuration; + let videoDuration = videoDurationParam; let segments = req.body.segments as IncomingSegment[]; if (segments === undefined) { @@ -387,15 +388,16 @@ export async function postSkipSegments(req: Request, res: Response): Promise 2)) { + if (!videoDurationParam || (apiVideoDuration && Math.abs(videoDurationParam - apiVideoDuration) > 2)) { // If api duration is far off, take that one instead (it is only precise to seconds, not millis) videoDuration = apiVideoDuration || 0 as VideoDuration; } - if (videoDurationChanged(videoDuration)) { + // Only treat as difference if both the api duration and submitted duration have changed + if (videoDurationChanged(videoDuration) && (!videoDurationParam || videoDurationChanged(videoDurationParam))) { // Hide all previous submissions for (const submission of previousSubmissions) { await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1 WHERE "UUID" = ?`, [submission.UUID]);