X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Foembed.ts;h=2a7dc257b277c02aa7caf57cca937de76956e369;hb=428ccb8b7a44ce60cabb7401a5464cf5fcbd4dba;hp=c9f9ea0c0708ed1e8db2d389e85290498fc5b3b5;hpb=6fad8e51c47b9d07bea99b777c1f55c10f6d576d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index c9f9ea0c0..2a7dc257b 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts @@ -9,11 +9,12 @@ import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { WEBSERVER } from '../../initializers/constants' import { areValidationErrors } from './utils' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/' const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' -const watchRegex = new RegExp('([^/]+)$') +const watchRegex = /([^/]+)$/ const isURLOptions = { require_host: true, require_tld: true @@ -36,7 +37,7 @@ const oembedValidator = [ if (areValidationErrors(req, res)) return if (req.query.format !== undefined && req.query.format !== 'json') { - return res.status(501) + return res.status(HttpStatusCode.NOT_IMPLEMENTED_501) .json({ error: 'Requested format is not implemented on server.' }) } @@ -50,13 +51,13 @@ const oembedValidator = [ const matches = watchRegex.exec(url) if (startIsOk === false || matches === null) { - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Invalid url.' }) } const elementId = matches[1] if (isIdOrUUIDValid(elementId) === false) { - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Invalid video or playlist id.' }) } @@ -64,12 +65,12 @@ const oembedValidator = [ const video = await fetchVideo(elementId, 'all') if (!video) { - return res.status(404) + return res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Video not found' }) } if (video.privacy !== VideoPrivacy.PUBLIC) { - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Video is not public' }) } @@ -81,12 +82,12 @@ const oembedValidator = [ const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(elementId, undefined) if (!videoPlaylist) { - return res.status(404) + return res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Video playlist not found' }) } if (videoPlaylist.privacy !== VideoPlaylistPrivacy.PUBLIC) { - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Playlist is not public' }) }