mirror of
https://github.com/comatory/fb2iCal
synced 2025-06-05 22:09:25 +02:00
move app routes to separate directory for better composition in
preparation of firebase integration
This commit is contained in:
42
lib/routes/download.js
Normal file
42
lib/routes/download.js
Normal file
@ -0,0 +1,42 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
const download = async (req, res, next) => {
|
||||
try {
|
||||
const { url } = req.body
|
||||
|
||||
const ics = await retrieveICS(url, {
|
||||
logger: appLogger,
|
||||
crawl,
|
||||
})
|
||||
|
||||
res
|
||||
.contentType('text/calendar')
|
||||
.status(200)
|
||||
.send(Buffer.from(ics, 'utf8'))
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
downloadHTML,
|
||||
download,
|
||||
}
|
16
lib/routes/error.js
Normal file
16
lib/routes/error.js
Normal file
@ -0,0 +1,16 @@
|
||||
const error = (req, res) => {
|
||||
const error = req.error || req.query.error || ''
|
||||
|
||||
res
|
||||
.status(500)
|
||||
.render('error', { error })
|
||||
}
|
||||
|
||||
const notFound = (req, res) => {
|
||||
res.status(400).render('404')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
error,
|
||||
notFound,
|
||||
}
|
9
lib/routes/index.js
Normal file
9
lib/routes/index.js
Normal file
@ -0,0 +1,9 @@
|
||||
const { error, notFound } = require('./error')
|
||||
const { download, downloadHTML } = require('./download')
|
||||
|
||||
module.exports = {
|
||||
error,
|
||||
notFound,
|
||||
download,
|
||||
downloadHTML,
|
||||
}
|
Reference in New Issue
Block a user