1
0
mirror of https://github.com/comatory/fb2iCal synced 2025-06-05 22:09:25 +02:00

allow passing FB event number as parameter

This commit is contained in:
Ondrej Synacek
2019-10-22 20:25:09 +02:00
parent 97317aeaa4
commit acebfe3658
8 changed files with 78 additions and 31 deletions

View File

@@ -1,4 +1,5 @@
const FBURLError = () => new Error('Not a valid Facebook URL!')
const { checkValidURL } = require('./utils')
const MissingURLParameter = () => new Error('Please provide valid URL or event number.')
const sendJSON = (req) => {
return req.accepts().includes('application/json')
@@ -19,27 +20,17 @@ const genericErrorHandler = (err, req, res, next) => {
.render('error', { error: err.toString() })
}
const checkFBURL = (req, res, next) => {
const checkURLParameter = (req, res, next) => {
const { url } = req.body
if (!url) {
return next(FBURLError())
if (!url || !checkValidURL(url)) {
return next(MissingURLParameter())
}
try {
const FBURL = new URL(url)
if (!(/facebook/.test(FBURL.hostname))) {
return next(FBURLError())
}
} catch (err) {
return next(err)
}
return next()
}
module.exports = {
genericErrorHandler,
checkFBURL,
checkURLParameter,
}