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
Cadence Fish 341aade87c
Instance owners can disable RSS
RSS is still enabled by default, but will be disabled on bibliogram.art.
2020-02-01 16:15:12 +13:00

50 lines
1.5 KiB
JavaScript

const constants = require("../../lib/constants")
const {fetchUser, requestCache} = require("../../lib/collectors")
const {render} = require("pinski/plugins")
const {pugCache} = require("../passthrough")
module.exports = [
{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
}))
}
}}
]