1
0
Fork 0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2026-03-04 11:41:36 +00:00

Tor check bug fixes; recognise december blocking

This commit is contained in:
Cadence Ember 2021-01-19 01:45:22 +13:00
parent df61faeb3b
commit 934e6baf06
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
6 changed files with 41 additions and 9 deletions

View file

@ -280,6 +280,7 @@ function fetchTimelinePage(userID, after) {
}))
return requestCache.getOrFetchPromise(`page/${userID}/${after}`, () => {
return switcher.request("timeline_graphql", `https://www.instagram.com/graphql/query/?${p.toString()}`, async res => {
if (res.status === 302) throw constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER
if (res.status === 429) throw constants.symbols.RATE_LIMITED
}).then(g => g.json()).then(root => {
if (root.data.user === null) {
@ -317,6 +318,7 @@ function fetchIGTVPage(userID, after) {
return requestCache.getOrFetchPromise(`igtv/${userID}/${after}`, () => {
// assuming this uses the same bucket as timeline, which may not be the case
return switcher.request("timeline_graphql", `https://www.instagram.com/graphql/query/?${p.toString()}`, async res => {
if (res.status === 302) throw constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER
if (res.status === 429) throw constants.symbols.RATE_LIMITED
}).then(g => g.json()).then(root => {
/** @type {import("./types").PagedEdges<import("./types").TimelineEntryN2>} */
@ -347,6 +349,7 @@ function verifyUserPair(userID, username) {
}))
return requestCache.getOrFetchPromise("userID/"+userID, () => {
return switcher.request("reel_graphql", `https://www.instagram.com/graphql/query/?${p.toString()}`, async res => {
if (res.status === 302) throw constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER
if (res.status === 429) throw constants.symbols.RATE_LIMITED
return res
}).then(res => res.json()).then(root => {
@ -402,6 +405,7 @@ function fetchShortcodeData(shortcode) {
p.set("variables", JSON.stringify({shortcode}))
return requestCache.getOrFetchPromise("shortcode/"+shortcode, () => {
return switcher.request("post_graphql", `https://www.instagram.com/graphql/query/?${p.toString()}`, async res => {
if (res.status === 302) throw constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER
if (res.status === 429) throw constants.symbols.RATE_LIMITED
}).then(res => res.json()).then(root => {
/** @type {import("./types").TimelineEntryN3} */

View file

@ -29,10 +29,10 @@ let constants = {
enabled: true, // If false, everything else in this block has no effect.
password: null, // If `null`, Bibliogram will run its own Tor process instead.
for: {
user_html: true, // User HTML page seems to have less forgiving rates, and Tor always fails, so it's disabled by default.
timeline_graphql: true,
post_graphql: true,
reel_graphql: true
user_html: true,
timeline_graphql: false,
post_graphql: false,
reel_graphql: false
}
},
request_backend: "node-fetch", // one of: "node-fetch", "got"
@ -262,6 +262,7 @@ let constants = {
NOT_FOUND: Symbol("NOT_FOUND"),
INSTAGRAM_DEMANDS_LOGIN: Symbol("INSTAGRAM_DEMANDS_LOGIN"),
RATE_LIMITED: Symbol("RATE_LIMITED"),
INSTAGRAM_BLOCK_TYPE_DECEMBER: Symbol("INSTAGRAM_BLOCK_TYPE_DECEMBER"),
ENDPOINT_OVERRIDDEN: Symbol("ENDPOINT_OVERRIDDEN"),
NO_ASSISTANTS_AVAILABLE: Symbol("NO_ASSISTANTS_AVAILABLE"),
QUOTA_REACHED: Symbol("QUOTA_REACHED"),

View file

@ -17,18 +17,18 @@ class TorManager {
}
async request(url, test) {
let result = null
let done = false
let g
while (!done) {
const req = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"})
g = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"})
try {
result = await test(req)
done = true
await g.check(test)
break
} catch (e) {
await this.newCircuit()
}
}
return result
return g
}
newCircuit() {