currentTime is now required

This commit is contained in:
Chocobozzz 2023-07-28 16:11:52 +02:00
parent 74c8d5bf2d
commit eeb838faf2
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 9 additions and 16 deletions

View File

@ -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

View File

@ -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'

View File

@ -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 })

View File

@ -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 })

View File

@ -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,