currentTime is now required
This commit is contained in:
parent
74c8d5bf2d
commit
eeb838faf2
5 changed files with 9 additions and 16 deletions
|
@ -114,8 +114,7 @@ function createWebsocketTrackerServer (app: express.Application) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: typings
|
return wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request))
|
||||||
return wss.handleUpgrade(request, socket as any, head, ws => wss.emit('connection', ws, request))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't destroy socket, we have Socket.IO too
|
// Don't destroy socket, we have Socket.IO too
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { isVideoTimeValid } from '@server/helpers/custom-validators/video-view'
|
||||||
import { getCachedVideoDuration } from '@server/lib/video'
|
import { getCachedVideoDuration } from '@server/lib/video'
|
||||||
import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer'
|
import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer'
|
||||||
import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
|
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'
|
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
|
||||||
|
|
||||||
const getVideoLocalViewerValidator = [
|
const getVideoLocalViewerValidator = [
|
||||||
|
@ -32,7 +32,6 @@ const videoViewValidator = [
|
||||||
isValidVideoIdParam('videoId'),
|
isValidVideoIdParam('videoId'),
|
||||||
|
|
||||||
body('currentTime')
|
body('currentTime')
|
||||||
.optional() // TODO: remove optional in a few versions, introduced in 4.2
|
|
||||||
.customSanitizer(toIntOrNull)
|
.customSanitizer(toIntOrNull)
|
||||||
.custom(isIntOrNull),
|
.custom(isIntOrNull),
|
||||||
|
|
||||||
|
@ -43,13 +42,7 @@ const videoViewValidator = [
|
||||||
const video = res.locals.onlyImmutableVideo
|
const video = res.locals.onlyImmutableVideo
|
||||||
const { duration } = await getCachedVideoDuration(video.id)
|
const { duration } = await getCachedVideoDuration(video.id)
|
||||||
|
|
||||||
if (!exists(req.body.currentTime)) { // TODO: remove in a few versions, introduced in 4.2
|
if (!isVideoTimeValid(req.body.currentTime, duration)) {
|
||||||
req.body.currentTime = Math.min(duration ?? 0, 30)
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentTime: number = req.body.currentTime
|
|
||||||
|
|
||||||
if (!isVideoTimeValid(currentTime, duration)) {
|
|
||||||
return res.fail({
|
return res.fail({
|
||||||
status: HttpStatusCode.BAD_REQUEST_400,
|
status: HttpStatusCode.BAD_REQUEST_400,
|
||||||
message: 'Current time is invalid'
|
message: 'Current time is invalid'
|
||||||
|
|
|
@ -43,8 +43,9 @@ describe('Test videos views', function () {
|
||||||
|
|
||||||
describe('When viewing a video', async 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', async function () {
|
||||||
it('Should fail without current time')
|
await servers[0].views.view({ id: videoId, currentTime: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
||||||
|
})
|
||||||
|
|
||||||
it('Should fail with an invalid current time', async function () {
|
it('Should fail with an invalid current time', async function () {
|
||||||
await servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
await servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
||||||
|
|
|
@ -546,7 +546,7 @@ describe('Test videos filter', function () {
|
||||||
|
|
||||||
expect(foundVideo).to.not.be.undefined
|
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) {
|
for (const path of paths) {
|
||||||
const videos = await listVideos({ server: servers[0], path, excludeAlreadyWatched: true })
|
const videos = await listVideos({ server: servers[0], path, excludeAlreadyWatched: true })
|
||||||
|
|
|
@ -6,7 +6,7 @@ export class ViewsCommand extends AbstractCommand {
|
||||||
|
|
||||||
view (options: OverrideCommandOptions & {
|
view (options: OverrideCommandOptions & {
|
||||||
id: number | string
|
id: number | string
|
||||||
currentTime?: number
|
currentTime: number
|
||||||
viewEvent?: VideoViewEvent
|
viewEvent?: VideoViewEvent
|
||||||
xForwardedFor?: string
|
xForwardedFor?: string
|
||||||
}) {
|
}) {
|
||||||
|
@ -19,7 +19,7 @@ export class ViewsCommand extends AbstractCommand {
|
||||||
path,
|
path,
|
||||||
xForwardedFor,
|
xForwardedFor,
|
||||||
fields: {
|
fields: {
|
||||||
currentTime: currentTime ?? 1,
|
currentTime,
|
||||||
viewEvent
|
viewEvent
|
||||||
},
|
},
|
||||||
implicitToken: false,
|
implicitToken: false,
|
||||||
|
|
Loading…
Reference in a new issue