From eeb838faf2ac3cb3bd42f68fafb4f78af4547a09 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 28 Jul 2023 16:11:52 +0200 Subject: [PATCH] currentTime is now required --- server/controllers/tracker.ts | 3 +-- server/middlewares/validators/videos/video-view.ts | 11 ++--------- server/tests/api/check-params/views.ts | 5 +++-- server/tests/api/videos/videos-common-filters.ts | 2 +- shared/server-commands/videos/views-command.ts | 4 ++-- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/server/controllers/tracker.ts b/server/controllers/tracker.ts index 53eab73ac..9a8aa88bc 100644 --- a/server/controllers/tracker.ts +++ b/server/controllers/tracker.ts @@ -114,8 +114,7 @@ function createWebsocketTrackerServer (app: express.Application) { return } - // FIXME: typings - return wss.handleUpgrade(request, socket as any, head, ws => wss.emit('connection', ws, request)) + return wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request)) } // Don't destroy socket, we have Socket.IO too diff --git a/server/middlewares/validators/videos/video-view.ts b/server/middlewares/validators/videos/video-view.ts index 6e2d4505d..a2f61f4ba 100644 --- a/server/middlewares/validators/videos/video-view.ts +++ b/server/middlewares/validators/videos/video-view.ts @@ -4,7 +4,7 @@ import { isVideoTimeValid } from '@server/helpers/custom-validators/video-view' import { getCachedVideoDuration } from '@server/lib/video' import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' -import { exists, isIdValid, isIntOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' +import { isIdValid, isIntOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' const getVideoLocalViewerValidator = [ @@ -32,7 +32,6 @@ const videoViewValidator = [ isValidVideoIdParam('videoId'), body('currentTime') - .optional() // TODO: remove optional in a few versions, introduced in 4.2 .customSanitizer(toIntOrNull) .custom(isIntOrNull), @@ -43,13 +42,7 @@ const videoViewValidator = [ const video = res.locals.onlyImmutableVideo const { duration } = await getCachedVideoDuration(video.id) - if (!exists(req.body.currentTime)) { // TODO: remove in a few versions, introduced in 4.2 - req.body.currentTime = Math.min(duration ?? 0, 30) - } - - const currentTime: number = req.body.currentTime - - if (!isVideoTimeValid(currentTime, duration)) { + if (!isVideoTimeValid(req.body.currentTime, duration)) { return res.fail({ status: HttpStatusCode.BAD_REQUEST_400, message: 'Current time is invalid' diff --git a/server/tests/api/check-params/views.ts b/server/tests/api/check-params/views.ts index 84d31c509..11416ccb8 100644 --- a/server/tests/api/check-params/views.ts +++ b/server/tests/api/check-params/views.ts @@ -43,8 +43,9 @@ describe('Test videos views', function () { describe('When viewing a video', async function () { - // TODO: implement it when we'll remove backward compatibility in REST API - it('Should fail without current time') + it('Should fail without current time', async function () { + await servers[0].views.view({ id: videoId, currentTime: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) it('Should fail with an invalid current time', async function () { await servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts index f68560b06..fac0f5dc5 100644 --- a/server/tests/api/videos/videos-common-filters.ts +++ b/server/tests/api/videos/videos-common-filters.ts @@ -546,7 +546,7 @@ describe('Test videos filter', function () { expect(foundVideo).to.not.be.undefined } - await servers[0].views.view({ id, token: servers[0].accessToken }) + await servers[0].views.view({ id, currentTime: 1, token: servers[0].accessToken }) for (const path of paths) { const videos = await listVideos({ server: servers[0], path, excludeAlreadyWatched: true }) diff --git a/shared/server-commands/videos/views-command.ts b/shared/server-commands/videos/views-command.ts index 01113f798..bdb8daaa4 100644 --- a/shared/server-commands/videos/views-command.ts +++ b/shared/server-commands/videos/views-command.ts @@ -6,7 +6,7 @@ export class ViewsCommand extends AbstractCommand { view (options: OverrideCommandOptions & { id: number | string - currentTime?: number + currentTime: number viewEvent?: VideoViewEvent xForwardedFor?: string }) { @@ -19,7 +19,7 @@ export class ViewsCommand extends AbstractCommand { path, xForwardedFor, fields: { - currentTime: currentTime ?? 1, + currentTime, viewEvent }, implicitToken: false,