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]);