Create page for when graphql is blocked

This commit is contained in:
Cadence Ember 2020-07-29 00:53:29 +12:00
parent d22c728473
commit 2b5899f430
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412
3 changed files with 32 additions and 18 deletions

View File

@ -120,7 +120,7 @@ module.exports = [
withInstancesLink: false, withInstancesLink: false,
settings settings
}) })
} else if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN || error === constants.symbols.RATE_LIMITED) { } else if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN) {
return { return {
statusCode: 503, statusCode: 503,
contentType: "text/html", contentType: "text/html",
@ -136,6 +136,8 @@ module.exports = [
lang lang
}) })
} }
} else if (error === constants.symbols.RATE_LIMITED) {
return render(503, "pug/blocked_graphql.pug")
} else if (error === constants.symbols.extractor_results.AGE_RESTRICTED) { } else if (error === constants.symbols.extractor_results.AGE_RESTRICTED) {
return render(403, "pug/age_gated.pug", {settings}) return render(403, "pug/age_gated.pug", {settings})
} else if (error === constants.symbols.QUOTA_REACHED) { } else if (error === constants.symbols.QUOTA_REACHED) {
@ -219,7 +221,8 @@ module.exports = [
}, },
{ {
route: `/fragment/post/(${constants.external.shortcode_regex})`, methods: ["GET"], code: ({req, fill}) => { route: `/fragment/post/(${constants.external.shortcode_regex})`, methods: ["GET"], code: ({req, fill}) => {
return getOrFetchShortcode(fill[0]).then(async post => { const shortcode = fill[0]
return getOrFetchShortcode(shortcode).then(async post => {
await post.fetchChildren() await post.fetchChildren()
await post.fetchExtendedOwnerP() // serial await is okay since intermediate fetch result is cached await post.fetchExtendedOwnerP() // serial await is okay since intermediate fetch result is cached
if (post.isVideo()) await post.fetchVideoURL() if (post.isVideo()) await post.fetchVideoURL()
@ -233,23 +236,14 @@ module.exports = [
} }
} }
}).catch(error => { }).catch(error => {
if (error === constants.symbols.NOT_FOUND) { if (error === constants.symbols.NOT_FOUND || constants.symbols.RATE_LIMITED) {
return render(404, "pug/friendlyerror.pug", { return {
statusCode: 404,
title: "Not found",
message: "Somehow, you reached a post that doesn't exist.",
withInstancesLink: false
})
} else if (error === constants.symbols.RATE_LIMITED) {
return render(503, "pug/friendlyerror.pug", {
statusCode: 503, statusCode: 503,
title: "Post loading blocked", contentType: "application/json",
message: "Post loading blocked", content: {
explanation: redirectTo: `/p/${shortcode}`
"Instagram blocked this server for requesting too much post data." }
+"\nThis block is not permanent, and will expire soon." }
+"\nPlease wait a few minutes before trying again."
})
} else { } else {
throw error throw error
} }
@ -295,6 +289,8 @@ module.exports = [
withInstancesLink: false, withInstancesLink: false,
settings settings
}) })
} else if (error === constants.symbols.RATE_LIMITED) {
return render(503, "pug/blocked_graphql.pug")
} else { } else {
throw error throw error
} }

View File

@ -135,6 +135,10 @@ function loadPostOverlay(shortcode, stateChangeType) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const fetcher = fetchShortcodeFragment(shortcode) const fetcher = fetchShortcodeFragment(shortcode)
fetcher.then(root => { fetcher.then(root => {
if (root.redirectTo) {
window.location.assign(root.redirectTo)
return
}
shortcodeDataMap.set(shortcode, root) shortcodeDataMap.set(shortcode, root)
if (overlay.available) { if (overlay.available) {
const {title, html} = root const {title, html} = root

View File

@ -0,0 +1,14 @@
include includes/error.pug
doctype html
html
head
title= `Blocked | Bibliogram`
include includes/head
body.error-page
+error(503, "Blocked by Instagram", true)
| Instagram is temporarily refusing to provide data to this server.
| This is a graphql block, which you cannot assist with.
| Try again in a few minutes to see if the block has been lifted.
|
|