1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-16 21:27:30 +00:00
bibliogram/src/site/api/feed.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-01-14 14:38:33 +00:00
const constants = require("../../lib/constants")
const {fetchUser, requestCache} = require("../../lib/collectors")
2020-01-14 14:38:33 +00:00
const {render} = require("pinski/plugins")
const {pugCache} = require("../passthrough")
2020-01-14 14:38:33 +00:00
module.exports = [
2020-01-27 06:03:28 +00:00
{route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: ({fill}) => {
if (constants.settings.rss_enabled) {
return fetchUser(fill[0]).then(async user => {
const content = await user.timeline.fetchFeed()
const xml = content.xml()
return {
statusCode: 200,
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed
content: xml
}
}).catch(error => {
if (error === constants.symbols.NOT_FOUND) {
return render(404, "pug/friendlyerror.pug", {
statusCode: 404,
title: "Not found",
message: "This user doesn't exist.",
withInstancesLink: false
})
} else if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN) {
return {
statusCode: 503,
contentType: "text/html",
headers: {
"Retry-After": requestCache.getTtl("user/"+fill[0], 1000)
},
content: pugCache.get("pug/blocked.pug").web({
expiresMinutes: requestCache.getTtl("user/"+fill[0], 1000*60)
})
}
} else {
throw error
}
})
} else {
return Promise.resolve(render(403, "pug/friendlyerror.pug", {
statusCode: 403,
title: "RSS disabled",
message: "RSS is disabled on this instance.",
withInstancesLink: true
}))
}
2020-01-14 14:38:33 +00:00
}}
]