mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 08:07:30 +00:00
Apply settings to error pages
This commit is contained in:
parent
518403e91e
commit
753b4f4ea4
@ -1,10 +1,12 @@
|
||||
const {render} = require("pinski/plugins")
|
||||
const constants = require("../../lib/constants")
|
||||
const {getSettings} = require("./utils/getsettings")
|
||||
|
||||
module.exports = [
|
||||
{route: "/404", methods: ["*"], code: async ({url}) => {
|
||||
{route: "/404", methods: ["*"], code: async ({req, url}) => {
|
||||
const path = url.searchParams.get("pathname")
|
||||
const couldBeUsername = path && path.match(`^/${constants.external.username_regex}(?:/channel)?$`)
|
||||
return render(404, "pug/404.pug", {path, couldBeUsername})
|
||||
const settings = getSettings(req)
|
||||
return render(404, "pug/404.pug", {settings, path, couldBeUsername})
|
||||
}}
|
||||
]
|
||||
|
@ -27,8 +27,8 @@ module.exports = [
|
||||
},
|
||||
{
|
||||
route: "/privacy", methods: ["GET"], code: async ({req}) => {
|
||||
if (constants.has_privacy_policy && pugCache.has("pug/privacy.pug")) {
|
||||
const settings = getSettings(req)
|
||||
if (constants.has_privacy_policy && pugCache.has("pug/privacy.pug")) {
|
||||
return render(200, "pug/privacy.pug", {settings})
|
||||
} else {
|
||||
return render(404, "pug/friendlyerror.pug", {
|
||||
@ -37,7 +37,8 @@ module.exports = [
|
||||
message: "No privacy policy",
|
||||
explanation:
|
||||
"The owner of this instance has not actually written a privacy policy."
|
||||
+"\nIf you own this instance, please read the file stored at /src/site/pug/privacy.pug.template."
|
||||
+"\nIf you own this instance, please read the file stored at /src/site/pug/privacy.pug.template.",
|
||||
settings
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -68,6 +69,7 @@ module.exports = [
|
||||
return Promise.resolve(redirect(`/u/${fill[0].toLowerCase()}`, 301))
|
||||
}
|
||||
|
||||
const settings = getSettings(req)
|
||||
const params = url.searchParams
|
||||
return fetchUser(fill[0]).then(async user => {
|
||||
const page = +params.get("page")
|
||||
@ -75,9 +77,6 @@ module.exports = [
|
||||
await user.timeline.fetchUpToPage(page - 1)
|
||||
}
|
||||
const followerCountsAvailable = !(user.constructor.name === "ReelUser" && user.following === 0 && user.followedBy === 0)
|
||||
|
||||
const settings = getSettings(req)
|
||||
|
||||
return render(200, "pug/user.pug", {
|
||||
url,
|
||||
user,
|
||||
@ -92,7 +91,8 @@ module.exports = [
|
||||
statusCode: 404,
|
||||
title: "Not found",
|
||||
message: "This user doesn't exist.",
|
||||
withInstancesLink: false
|
||||
withInstancesLink: false,
|
||||
settings
|
||||
})
|
||||
} else if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN || error === constants.symbols.RATE_LIMITED) {
|
||||
return {
|
||||
@ -105,11 +105,12 @@ module.exports = [
|
||||
website_origin: constants.website_origin,
|
||||
username: fill[0],
|
||||
expiresMinutes: userRequestCache.getTtl("user/"+fill[0], 1000*60),
|
||||
getStaticURL
|
||||
getStaticURL,
|
||||
settings
|
||||
})
|
||||
}
|
||||
} else if (error === constants.symbols.extractor_results.AGE_RESTRICTED) {
|
||||
return render(403, "pug/age_gated.pug")
|
||||
return render(403, "pug/age_gated.pug", {settings})
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
@ -194,11 +195,11 @@ module.exports = [
|
||||
},
|
||||
{
|
||||
route: `/p/(${constants.external.shortcode_regex})`, methods: ["GET"], code: ({req, fill}) => {
|
||||
const settings = getSettings(req)
|
||||
return getOrFetchShortcode(fill[0]).then(async post => {
|
||||
await post.fetchChildren()
|
||||
await post.fetchExtendedOwnerP() // serial await is okay since intermediate fetch result is cached
|
||||
if (post.isVideo()) await post.fetchVideoURL()
|
||||
const settings = getSettings(req)
|
||||
return render(200, "pug/post.pug", {
|
||||
title: getPageTitle(post),
|
||||
post,
|
||||
@ -211,7 +212,8 @@ module.exports = [
|
||||
statusCode: 404,
|
||||
title: "Not found",
|
||||
message: "Somehow, you reached a post that doesn't exist.",
|
||||
withInstancesLink: false
|
||||
withInstancesLink: false,
|
||||
settings
|
||||
})
|
||||
} else {
|
||||
throw error
|
||||
|
Loading…
Reference in New Issue
Block a user