- const startIsOk = req.query.url.startsWith(urlShouldStartWith)
- const matches = videoWatchRegex.exec(req.query.url)
- if (startIsOk === false || matches === null) {
- return res.status(400)
- .json({ error: 'Invalid url.' })
- .end()
+ if (startIsOk === false || matches === null) {
+ return res.status(HttpStatusCode.BAD_REQUEST_400)
+ .json({ error: 'Invalid url.' })
+ }
+
+ const elementId = matches[1]
+ if (isIdOrUUIDValid(elementId) === false) {
+ return res.status(HttpStatusCode.BAD_REQUEST_400)
+ .json({ error: 'Invalid video or playlist id.' })
+ }
+
+ if (isVideo) {
+ const video = await fetchVideo(elementId, 'all')
+
+ if (!video) {
+ return res.status(HttpStatusCode.NOT_FOUND_404)
+ .json({ error: 'Video not found' })