1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2025-12-16 11:08:49 +00:00

Rewrite feeds

This commit is contained in:
Cadence Fish
2020-02-18 13:39:20 +13:00
parent b10432aa38
commit 5201a6612b
16 changed files with 118 additions and 65 deletions

View File

@@ -4,15 +4,29 @@ const {render} = require("pinski/plugins")
const {pugCache} = require("../passthrough")
module.exports = [
{route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: ({fill}) => {
{route: `/u/(${constants.external.username_regex})/(rss|atom)\\.xml`, methods: ["GET"], code: ({fill}) => {
if (constants.settings.rss_enabled) {
const kind = fill[1]
return fetchUser(fill[0], true).then(async user => {
const content = await user.timeline.fetchFeed()
const xml = content.xml()
const feed = await user.timeline.fetchFeed()
if (kind === "rss") {
var data = {
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed,
content: feed.rss2()
}
} else if (kind === "atom") {
var data = {
contentType: "application/atom+xml", // see https://en.wikipedia.org/wiki/Atom_(standard)#Including_in_HTML
content: feed.atom1()
}
}
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
contentType: data.contentType,
headers: {
"Cache-Control": `max-age=${userRequestCache.getTtl("user/"+user.data.username, 1000)}`
},
content: data.content
}
}).catch(error => {
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
@@ -40,8 +54,8 @@ module.exports = [
} else {
return Promise.resolve(render(403, "pug/friendlyerror.pug", {
statusCode: 403,
title: "RSS disabled",
message: "RSS is disabled on this instance.",
title: "Feeds disabled",
message: "Feeds are disabled on this instance.",
withInstancesLink: true
}))
}

View File

@@ -58,7 +58,7 @@ module.exports = [
if (typeof page === "number" && !isNaN(page) && page >= 1) {
await user.timeline.fetchUpToPage(page - 1)
}
return render(200, "pug/user.pug", {url, user, constants})
return render(200, "pug/user.pug", {url, user, constants, website_origin: constants.website_origin})
}).catch(error => {
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
return render(404, "pug/friendlyerror.pug", {