2020-11-01 13:08:48 +01:00
|
|
|
const { getNormalizedUrl } = require('../utils')
|
|
|
|
const crawl = require('../services/crawler')
|
|
|
|
const { retrieveICS } = require('../services/ics-retriever')
|
|
|
|
|
|
|
|
const downloadHTML = (logger) => (async (req, res, next) => {
|
|
|
|
try {
|
|
|
|
const { url } = req.body
|
|
|
|
|
|
|
|
const facebookURL = getNormalizedUrl(url)
|
|
|
|
const html = await crawl(facebookURL, { logger })
|
|
|
|
|
|
|
|
res
|
|
|
|
.contentType('text/html')
|
|
|
|
.status(200)
|
|
|
|
.send(Buffer.from(html, 'utf8'))
|
|
|
|
} catch (err) {
|
|
|
|
next(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-11-15 15:13:49 +01:00
|
|
|
const download = (logger) => (async (req, res, next) => {
|
2020-11-01 13:08:48 +01:00
|
|
|
try {
|
|
|
|
const { url } = req.body
|
|
|
|
|
|
|
|
const ics = await retrieveICS(url, {
|
2020-11-15 15:13:49 +01:00
|
|
|
logger,
|
2020-11-01 13:08:48 +01:00
|
|
|
crawl,
|
|
|
|
})
|
|
|
|
|
|
|
|
res
|
|
|
|
.contentType('text/calendar')
|
|
|
|
.status(200)
|
|
|
|
.send(Buffer.from(ics, 'utf8'))
|
|
|
|
} catch (err) {
|
|
|
|
next(err)
|
|
|
|
}
|
2020-11-15 15:13:49 +01:00
|
|
|
})
|
2020-11-01 13:08:48 +01:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
downloadHTML,
|
|
|
|
download,
|
|
|
|
}
|