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:
35
lib/utils.js
35
lib/utils.js
@@ -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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user