- 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.' })
+ .end()
+ }
+
+ 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()
+ }