- checkErrors(req, res, () => {
- if (req.query.format !== undefined && req.query.format !== 'json') {
- return res.status(501)
- .json({ error: 'Requested format is not implemented on server.' })
- .end()
- }
+ if (areValidationErrors(req, res)) return
+
+ if (req.query.format !== undefined && req.query.format !== 'json') {
+ return res.status(501)
+ .json({ error: 'Requested format is not implemented on server.' })
+ }
+
+ const url = req.query.url as string
+
+ const isPlaylist = url.startsWith(startVideoPlaylistsURL)
+ const isVideo = isPlaylist ? false : url.startsWith(startVideosURL)
+
+ const startIsOk = isVideo || isPlaylist
+
+ const matches = watchRegex.exec(url)
+
+ if (startIsOk === false || matches === null) {
+ return res.status(400)
+ .json({ error: 'Invalid url.' })
+ }