mirror of
https://github.com/comatory/fb2iCal
synced 2025-01-14 09:26:16 +01:00
27 lines
768 B
JavaScript
27 lines
768 B
JavaScript
const crawl = require('./crawler')
|
|
const parseUsingLDJSONData = require('./ldjson-parser')
|
|
const parseUsingDOM = require('./dom-parser')
|
|
const generateICS = require('./ics-generator')
|
|
const { createParserError, getNormalizedUrl } = require('../utils')
|
|
|
|
const retrieveICS = async (URLparameter, { logger }) => {
|
|
try {
|
|
const url = getNormalizedUrl(URLparameter)
|
|
const html = await crawl(url, { logger })
|
|
const LDJSONEventData = parseUsingLDJSONData(html, { logger })
|
|
const eventData = LDJSONEventData || parseUsingDOM(html, url, { logger })
|
|
|
|
if (!eventData) {
|
|
throw createParserError()
|
|
return
|
|
}
|
|
|
|
const icsFile = await generateICS(eventData)
|
|
return icsFile
|
|
} catch (err) {
|
|
throw err
|
|
}
|
|
}
|
|
|
|
module.exports = retrieveICS
|