X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideos.ts;h=794e1d4f1efa199b5c55dfed9c202e0ea89ba50a;hb=HEAD;hp=e29eb4a323966373b5203471c767d024197102d9;hpb=2f061e065ab43cc0b73595b619639a92952aeeba;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index e29eb4a32..794e1d4f1 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -7,6 +7,7 @@ import { getServerActor } from '@server/models/application/application' import { ExpressPromiseHandler } from '@server/types/express-handler' import { MUserAccountId, MVideoFullLight } from '@server/types/models' import { arrayify, getAllPrivacies } from '@shared/core-utils' +import { getVideoStreamDuration } from '@shared/ffmpeg' import { HttpStatusCode, ServerErrorCode, UserRight, VideoInclude, VideoState } from '@shared/models' import { exists, @@ -37,7 +38,6 @@ import { isVideoSupportValid } from '../../../helpers/custom-validators/videos' import { cleanUpReqFiles } from '../../../helpers/express-utils' -import { getVideoStreamDuration } from '../../../helpers/ffmpeg' import { logger } from '../../../helpers/logger' import { deleteFileAndCatch } from '../../../helpers/utils' import { getVideoWithAttributes } from '../../../helpers/video' @@ -234,7 +234,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req) const video = getVideoWithAttributes(res) - if (req.body.privacy && video.isLive && video.state !== VideoState.WAITING_FOR_LIVE) { + if (video.isLive && video.privacy !== req.body.privacy && video.state !== VideoState.WAITING_FOR_LIVE) { return res.fail({ message: 'Cannot update privacy of a live that has already started' }) } @@ -489,6 +489,10 @@ const commonVideosFiltersValidator = [ query('search') .optional() .custom(exists), + query('excludeAlreadyWatched') + .optional() + .customSanitizer(toBooleanOrNull) + .isBoolean().withMessage('Should be a valid excludeAlreadyWatched boolean'), (req: express.Request, res: express.Response, next: express.NextFunction) => { if (areValidationErrors(req, res)) return @@ -520,6 +524,13 @@ const commonVideosFiltersValidator = [ } } + if (!user && exists(req.query.excludeAlreadyWatched)) { + res.fail({ + status: HttpStatusCode.BAD_REQUEST_400, + message: 'Cannot use excludeAlreadyWatched parameter when auth token is not provided' + }) + return false + } return next() } ]