aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-28 16:11:52 +0200
committerChocobozzz <me@florianbigard.com>2023-07-28 16:17:37 +0200
commiteeb838faf2ac3cb3bd42f68fafb4f78af4547a09 (patch)
treec814953de92a45a81b159a9d8778581b4fc8a2af
parent74c8d5bf2d807870ed351fb2a0ee7137987aa995 (diff)
downloadPeerTube-eeb838faf2ac3cb3bd42f68fafb4f78af4547a09.tar.gz
PeerTube-eeb838faf2ac3cb3bd42f68fafb4f78af4547a09.tar.zst
PeerTube-eeb838faf2ac3cb3bd42f68fafb4f78af4547a09.zip
currentTime is now required
-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
-rw-r--r--shared/server-commands/videos/views-command.ts4
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) {
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 })
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 {
6 6
7 view (options: OverrideCommandOptions & { 7 view (options: OverrideCommandOptions & {
8 id: number | string 8 id: number | string
9 currentTime?: number 9 currentTime: number
10 viewEvent?: VideoViewEvent 10 viewEvent?: VideoViewEvent
11 xForwardedFor?: string 11 xForwardedFor?: string
12 }) { 12 }) {
@@ -19,7 +19,7 @@ export class ViewsCommand extends AbstractCommand {
19 path, 19 path,
20 xForwardedFor, 20 xForwardedFor,
21 fields: { 21 fields: {
22 currentTime: currentTime ?? 1, 22 currentTime,
23 viewEvent 23 viewEvent
24 }, 24 },
25 implicitToken: false, 25 implicitToken: false,