1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-22 16:17:29 +00:00

Instance owners can disable RSS

RSS is still enabled by default, but will be disabled on bibliogram.art.
This commit is contained in:
Cadence Fish 2020-02-01 16:15:12 +13:00
parent 94ed25adad
commit 341aade87c
No known key found for this signature in database
GPG Key ID: 81015DF9AA8607E1
8 changed files with 80 additions and 35 deletions

View File

@ -9,6 +9,10 @@ let constants = {
website_origin: "http://localhost:10407", website_origin: "http://localhost:10407",
// Things that server owners _could_ change if they want to. // Things that server owners _could_ change if they want to.
settings: {
rss_enabled: true
},
caching: { caching: {
image_cache_control: `public, max-age=${7*24*60*60}`, image_cache_control: `public, max-age=${7*24*60*60}`,
resource_cache_time: 30*60*1000, resource_cache_time: 30*60*1000,

View File

@ -41,7 +41,7 @@ module.exports = [
}, },
{ {
route: "/api/stats/2.0", methods: ["GET"], code: async ({url}) => { route: "/api/stats/2.0", methods: ["GET"], code: async ({url}) => {
const versions = ["1.0", "1.1"] const versions = ["1.0", "1.1", "1.2"]
const features = [ const features = [
"PAGE_PROFILE", "PAGE_PROFILE",
"PAGE_POST", "PAGE_POST",
@ -60,6 +60,15 @@ module.exports = [
availableVersions: versions, availableVersions: versions,
features, features,
history: history.export() history: history.export()
}],
["1.2", {
version: "1.2",
availableVersions: versions,
features,
history: history.export(),
settings: {
rssEnabled: constants.settings.rss_enabled
}
}] }]
]) ])
).get(url.searchParams.get("bv") || versions[0]) ).get(url.searchParams.get("bv") || versions[0])

View File

@ -1,27 +1,49 @@
const constants = require("../../lib/constants") const constants = require("../../lib/constants")
const {fetchUser} = require("../../lib/collectors") const {fetchUser, requestCache} = require("../../lib/collectors")
const {render} = require("pinski/plugins") const {render} = require("pinski/plugins")
const {pugCache} = require("../passthrough")
module.exports = [ module.exports = [
{route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: ({fill}) => { {route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: ({fill}) => {
return fetchUser(fill[0]).then(async user => { if (constants.settings.rss_enabled) {
const content = await user.timeline.fetchFeed() return fetchUser(fill[0]).then(async user => {
const xml = content.xml() const content = await user.timeline.fetchFeed()
return { const xml = content.xml()
statusCode: 200, return {
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed statusCode: 200,
content: xml 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) { }).catch(error => {
return render(404, "pug/friendlyerror.pug", { if (error === constants.symbols.NOT_FOUND) {
statusCode: 404, return render(404, "pug/friendlyerror.pug", {
title: "Not found", statusCode: 404,
message: "This user doesn't exist." title: "Not found",
}) message: "This user doesn't exist.",
} else { withInstancesLink: false
throw error })
} } 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
}))
}
}} }}
] ]

View File

@ -17,7 +17,8 @@ module.exports = [
statusCode: 400, statusCode: 400,
title: "Bad request", title: "Bad request",
message: "Expected a username", message: "Expected a username",
explanation: "Write /u/{username} or /u?u={username}." explanation: "Write /u/{username} or /u?u={username}.",
withInstancesLink: false
}) })
} }
} }
@ -30,13 +31,14 @@ module.exports = [
if (typeof page === "number" && !isNaN(page) && page >= 1) { if (typeof page === "number" && !isNaN(page) && page >= 1) {
await user.timeline.fetchUpToPage(page - 1) await user.timeline.fetchUpToPage(page - 1)
} }
return render(200, "pug/user.pug", {url, user}) return render(200, "pug/user.pug", {url, user, constants})
}).catch(error => { }).catch(error => {
if (error === constants.symbols.NOT_FOUND) { if (error === constants.symbols.NOT_FOUND) {
return render(404, "pug/friendlyerror.pug", { return render(404, "pug/friendlyerror.pug", {
statusCode: 404, statusCode: 404,
title: "Not found", title: "Not found",
message: "This user doesn't exist." message: "This user doesn't exist.",
withInstancesLink: false
}) })
} else if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN) { } else if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN) {
return { return {
@ -75,7 +77,8 @@ module.exports = [
return render(404, "pug/friendlyerror.pug", { return render(404, "pug/friendlyerror.pug", {
statusCode: 404, statusCode: 404,
title: "Not found", title: "Not found",
message: "This user doesn't exist." message: "This user doesn't exist.",
withInstancesLink: false
}) })
} else { } else {
throw error throw error
@ -94,7 +97,8 @@ module.exports = [
statusCode: 400, statusCode: 400,
title: "Bad request", title: "Bad request",
message: "Expected a shortcode", message: "Expected a shortcode",
explanation: "Write /p/{shortcode} or /p?p={shortcode}." explanation: "Write /p/{shortcode} or /p?p={shortcode}.",
withInstancesLink: false
}) })
} }
} }
@ -111,7 +115,8 @@ module.exports = [
return render(404, "pug/friendlyerror.pug", { return render(404, "pug/friendlyerror.pug", {
statusCode: 404, statusCode: 404,
title: "Not found", title: "Not found",
message: "Somehow, you reached a post that doesn't exist." message: "Somehow, you reached a post that doesn't exist.",
withInstancesLink: false
}) })
} else { } else {
throw error throw error

View File

@ -12,8 +12,7 @@ html
title= `Blocked | Bibliogram` title= `Blocked | Bibliogram`
link(rel="stylesheet" type="text/css" href="/static/css/main.css") link(rel="stylesheet" type="text/css" href="/static/css/main.css")
body.error-page body.error-page
+error(503, "Blocked by Instagram") +error(503, "Blocked by Instagram", true)
| Instagram is refusing to provide data to this server. Try again later to see if the block has been lifted. | Instagram is refusing to provide data to this server. Try again later to see if the block has been lifted.
| This error has been cached. The internal cache will expire in #{expiresMinutes} minutes. | This error has been cached. The internal cache will expire in #{expiresMinutes} minutes.
| |
a(href="https://github.com/cloudrac3r/bibliogram/wiki/Instances") You could try browsing Bibliogram on another instance.

View File

@ -1,4 +1,4 @@
//- Needs title, message, statusCode ?explanation //- Needs title, message, statusCode, ?explanation, withInstancesLink
include includes/error.pug include includes/error.pug
@ -12,6 +12,6 @@ html
title= `${title} | Bibliogram` title= `${title} | Bibliogram`
link(rel="stylesheet" type="text/css" href="/static/css/main.css") link(rel="stylesheet" type="text/css" href="/static/css/main.css")
body.error-page body.error-page
+error(statusCode, message) +error(statusCode, message, withInstancesLink)
if explanation if explanation
=explanation =explanation

View File

@ -1,7 +1,10 @@
mixin error(statusCode, message) mixin error(statusCode, message, withInstancesLink)
h1.code= statusCode h1.code= statusCode
p.message= message p.message= message
if block if block || withInstancesLink
p.explanation p.explanation
block if block
block
if withInstancesLink
a(href="https://github.com/cloudrac3r/bibliogram/wiki/Instances") You could try browsing Bibliogram on another instance.
a(href="javascript:history.back()").back ← Go back? a(href="javascript:history.back()").back ← Go back?

View File

@ -1,3 +1,5 @@
//- Needs user, url, constants
include includes/timeline_page.pug include includes/timeline_page.pug
include includes/next_page_button.pug include includes/next_page_button.pug
@ -30,7 +32,8 @@ html
div.profile-counter #[span(data-numberformat=user.following).count #{numberFormat(user.following)}] following div.profile-counter #[span(data-numberformat=user.following).count #{numberFormat(user.following)}] following
div.profile-counter #[span(data-numberformat=user.followedBy).count #{numberFormat(user.followedBy)}] followed by div.profile-counter #[span(data-numberformat=user.followedBy).count #{numberFormat(user.followedBy)}] followed by
div.links div.links
a(rel="alternate" type="application/rss+xml" href=`/u/${user.data.username}/rss.xml`) RSS if constants.settings.rss_enabled
a(rel="alternate" type="application/rss+xml" href=`/u/${user.data.username}/rss.xml`) RSS
a(rel="noreferrer noopener" href=`https://www.instagram.com/${user.data.username}`) instagram.com a(rel="noreferrer noopener" href=`https://www.instagram.com/${user.data.username}`) instagram.com
- const hasPosts = !user.data.is_private && user.timeline.pages.length && user.timeline.pages[0].length - const hasPosts = !user.data.is_private && user.timeline.pages.length && user.timeline.pages[0].length