aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/oembed.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/oembed.ts')
-rw-r--r--server/middlewares/validators/oembed.ts15
1 files changed, 8 insertions, 7 deletions
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index c9f9ea0c0..86623efcd 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -9,6 +9,7 @@ import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
9import { logger } from '../../helpers/logger' 9import { logger } from '../../helpers/logger'
10import { WEBSERVER } from '../../initializers/constants' 10import { WEBSERVER } from '../../initializers/constants'
11import { areValidationErrors } from './utils' 11import { areValidationErrors } from './utils'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
12 13
13const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/' 14const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/'
14const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' 15const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/'
@@ -36,7 +37,7 @@ const oembedValidator = [
36 if (areValidationErrors(req, res)) return 37 if (areValidationErrors(req, res)) return
37 38
38 if (req.query.format !== undefined && req.query.format !== 'json') { 39 if (req.query.format !== undefined && req.query.format !== 'json') {
39 return res.status(501) 40 return res.status(HttpStatusCode.NOT_IMPLEMENTED_501)
40 .json({ error: 'Requested format is not implemented on server.' }) 41 .json({ error: 'Requested format is not implemented on server.' })
41 } 42 }
42 43
@@ -50,13 +51,13 @@ const oembedValidator = [
50 const matches = watchRegex.exec(url) 51 const matches = watchRegex.exec(url)
51 52
52 if (startIsOk === false || matches === null) { 53 if (startIsOk === false || matches === null) {
53 return res.status(400) 54 return res.status(HttpStatusCode.BAD_REQUEST_400)
54 .json({ error: 'Invalid url.' }) 55 .json({ error: 'Invalid url.' })
55 } 56 }
56 57
57 const elementId = matches[1] 58 const elementId = matches[1]
58 if (isIdOrUUIDValid(elementId) === false) { 59 if (isIdOrUUIDValid(elementId) === false) {
59 return res.status(400) 60 return res.status(HttpStatusCode.BAD_REQUEST_400)
60 .json({ error: 'Invalid video or playlist id.' }) 61 .json({ error: 'Invalid video or playlist id.' })
61 } 62 }
62 63
@@ -64,12 +65,12 @@ const oembedValidator = [
64 const video = await fetchVideo(elementId, 'all') 65 const video = await fetchVideo(elementId, 'all')
65 66
66 if (!video) { 67 if (!video) {
67 return res.status(404) 68 return res.status(HttpStatusCode.NOT_FOUND_404)
68 .json({ error: 'Video not found' }) 69 .json({ error: 'Video not found' })
69 } 70 }
70 71
71 if (video.privacy !== VideoPrivacy.PUBLIC) { 72 if (video.privacy !== VideoPrivacy.PUBLIC) {
72 return res.status(403) 73 return res.status(HttpStatusCode.FORBIDDEN_403)
73 .json({ error: 'Video is not public' }) 74 .json({ error: 'Video is not public' })
74 } 75 }
75 76
@@ -81,12 +82,12 @@ const oembedValidator = [
81 82
82 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(elementId, undefined) 83 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(elementId, undefined)
83 if (!videoPlaylist) { 84 if (!videoPlaylist) {
84 return res.status(404) 85 return res.status(HttpStatusCode.NOT_FOUND_404)
85 .json({ error: 'Video playlist not found' }) 86 .json({ error: 'Video playlist not found' })
86 } 87 }
87 88
88 if (videoPlaylist.privacy !== VideoPlaylistPrivacy.PUBLIC) { 89 if (videoPlaylist.privacy !== VideoPlaylistPrivacy.PUBLIC) {
89 return res.status(403) 90 return res.status(HttpStatusCode.FORBIDDEN_403)
90 .json({ error: 'Playlist is not public' }) 91 .json({ error: 'Playlist is not public' })
91 } 92 }
92 93