aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/tracker.ts3
-rw-r--r--server/middlewares/validators/videos/video-view.ts11
-rw-r--r--server/tests/api/check-params/views.ts5
-rw-r--r--server/tests/api/videos/videos-common-filters.ts2
4 files changed, 7 insertions, 14 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) {
114 return 114 return
115 } 115 }
116 116
117 // FIXME: typings 117 return wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request))
118 return wss.handleUpgrade(request, socket as any, head, ws => wss.emit('connection', ws, request))
119 } 118 }
120 119
121 // Don't destroy socket, we have Socket.IO too 120 // 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'
4import { getCachedVideoDuration } from '@server/lib/video' 4import { getCachedVideoDuration } from '@server/lib/video'
5import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' 5import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer'
6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
7import { exists, isIdValid, isIntOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' 7import { isIdValid, isIntOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
8import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' 8import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
9 9
10const getVideoLocalViewerValidator = [ 10const getVideoLocalViewerValidator = [
@@ -32,7 +32,6 @@ const videoViewValidator = [
32 isValidVideoIdParam('videoId'), 32 isValidVideoIdParam('videoId'),
33 33
34 body('currentTime') 34 body('currentTime')
35 .optional() // TODO: remove optional in a few versions, introduced in 4.2
36 .customSanitizer(toIntOrNull) 35 .customSanitizer(toIntOrNull)
37 .custom(isIntOrNull), 36 .custom(isIntOrNull),
38 37
@@ -43,13 +42,7 @@ const videoViewValidator = [
43 const video = res.locals.onlyImmutableVideo 42 const video = res.locals.onlyImmutableVideo
44 const { duration } = await getCachedVideoDuration(video.id) 43 const { duration } = await getCachedVideoDuration(video.id)
45 44
46 if (!exists(req.body.currentTime)) { // TODO: remove in a few versions, introduced in 4.2 45 if (!isVideoTimeValid(req.body.currentTime, duration)) {
47 req.body.currentTime = Math.min(duration ?? 0, 30)
48 }
49
50 const currentTime: number = req.body.currentTime
51
52 if (!isVideoTimeValid(currentTime, duration)) {
53 return res.fail({ 46 return res.fail({
54 status: HttpStatusCode.BAD_REQUEST_400, 47 status: HttpStatusCode.BAD_REQUEST_400,
55 message: 'Current time is invalid' 48 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 () {
43 43
44 describe('When viewing a video', async function () { 44 describe('When viewing a video', async function () {
45 45
46 // TODO: implement it when we'll remove backward compatibility in REST API 46 it('Should fail without current time', async function () {
47 it('Should fail without current time') 47 await servers[0].views.view({ id: videoId, currentTime: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
48 })
48 49
49 it('Should fail with an invalid current time', async function () { 50 it('Should fail with an invalid current time', async function () {
50 await servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 51 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 () {
546 546
547 expect(foundVideo).to.not.be.undefined 547 expect(foundVideo).to.not.be.undefined
548 } 548 }
549 await servers[0].views.view({ id, token: servers[0].accessToken }) 549 await servers[0].views.view({ id, currentTime: 1, token: servers[0].accessToken })
550 550
551 for (const path of paths) { 551 for (const path of paths) {
552 const videos = await listVideos({ server: servers[0], path, excludeAlreadyWatched: true }) 552 const videos = await listVideos({ server: servers[0], path, excludeAlreadyWatched: true })