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

refactor retrieving ICS file

This commit is contained in:
Ondrej Synacek
2019-10-23 20:37:06 +02:00
parent 52b86953aa
commit a41992d53b
7 changed files with 91 additions and 64 deletions

View File

@@ -18,9 +18,44 @@ const createParserError = () => {
return err
}
// NOTE: Using mobile facebook URL because it usually
// contains stringified JSON with event information
const createMobileURL = (originalURL) => {
const urlWithProtocol = originalURL.includes('http') ?
originalURL :
`https://${originalURL}`
const url = new URL(urlWithProtocol)
return `${url.protocol}//mobile.facebook.com${url.port}${url.pathname}${url.hash}`
}
// NOTE: Detect whether URL parameter contains
// number or http address
const createURL = (param) => {
if (checkURLFormat(param)) {
return param
}
if (checkNumberURLParameter(param)) {
return `https://facebook.com/events/${param}`
}
return ''
}
const getNormalizedUrl = (URLparameter) => {
const fbURL = createURL(URLparameter)
const mobileUrl = createMobileURL(fbURL)
return mobileUrl
}
module.exports = {
checkValidURL,
checkURLFormat,
checkNumberURLParameter,
createParserError,
createMobileURL,
createURL,
getNormalizedUrl,
}