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

Change self_blocked_status to include timeline

Disabled by default, enable in the usual way.
This commit is contained in:
Cadence Ember 2021-01-30 19:29:24 +13:00
parent e1883b2d9e
commit 2419fbf08b
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17
2 changed files with 23 additions and 7 deletions

View File

@ -86,10 +86,11 @@ async function fetchUser(username, context) {
* @returns {Promise<{user: import("./structures/User"), quotaUsed: number}>} * @returns {Promise<{user: import("./structures/User"), quotaUsed: number}>}
*/ */
function fetchUserFromHTML(username) { function fetchUserFromHTML(username) {
if (constants.caching.self_blocked_status.enabled) { const blockedCacheConfig = constants.caching.self_blocked_status.user_html
if (blockedCacheConfig) {
if (history.store.has("user")) { if (history.store.has("user")) {
const entry = history.store.get("user") const entry = history.store.get("user")
if (!entry.lastRequestSuccessful && Date.now() < entry.lastRequestAt + constants.caching.self_blocked_status.time) { if (!entry.lastRequestSuccessful && Date.now() < entry.lastRequestAt + blockedCacheConfig.time) {
return Promise.reject(constants.symbols.RATE_LIMITED) return Promise.reject(constants.symbols.RATE_LIMITED)
} }
} }
@ -271,6 +272,15 @@ function fetchUserFromSaved(saved) {
* @returns {Promise<{result: import("./types").PagedEdges<import("./types").TimelineEntryN2>, fromCache: boolean}>} * @returns {Promise<{result: import("./types").PagedEdges<import("./types").TimelineEntryN2>, fromCache: boolean}>}
*/ */
function fetchTimelinePage(userID, after) { function fetchTimelinePage(userID, after) {
const blockedCacheConfig = constants.caching.self_blocked_status.timeline_graphql
if (blockedCacheConfig) {
if (history.store.has("timeline")) {
const entry = history.store.get("timeline")
if (!entry.lastRequestSuccessful && Date.now() < entry.lastRequestAt + blockedCacheConfig.time) {
return Promise.reject(constants.symbols.RATE_LIMITED)
}
}
}
const p = new URLSearchParams() const p = new URLSearchParams()
p.set("query_hash", constants.external.timeline_query_hash) p.set("query_hash", constants.external.timeline_query_hash)
p.set("variables", JSON.stringify({ p.set("variables", JSON.stringify({
@ -294,7 +304,7 @@ function fetchTimelinePage(userID, after) {
history.report("timeline", true) history.report("timeline", true)
return timeline return timeline
}).catch(error => { }).catch(error => {
if (error === constants.symbols.RATE_LIMITED) { if (error === constants.symbols.RATE_LIMITED || error === constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER) {
history.report("timeline", false) history.report("timeline", false)
} }
throw error throw error
@ -326,7 +336,7 @@ function fetchIGTVPage(userID, after) {
history.report("igtv", true) history.report("igtv", true)
return timeline return timeline
}).catch(error => { }).catch(error => {
if (error === constants.symbols.RATE_LIMITED) { if (error === constants.symbols.RATE_LIMITED || error === constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER) {
history.report("igtv", false) history.report("igtv", false)
} }
throw error throw error
@ -430,7 +440,7 @@ function fetchShortcodeData(shortcode) {
return data return data
} }
}).catch(error => { }).catch(error => {
if (error === constants.symbols.RATE_LIMITED) { if (error === constants.symbols.RATE_LIMITED || error === constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER) {
history.report("post", false) history.report("post", false)
} }
throw error throw error

View File

@ -216,8 +216,14 @@ let constants = {
cache_sweep_interval: 3*60*1000, cache_sweep_interval: 3*60*1000,
csrf_time: 60*60*1000, csrf_time: 60*60*1000,
self_blocked_status: { self_blocked_status: {
enabled: true, user_html: {
time: 2*60*60*1000, enabled: false,
time: 15*60*1000
},
timeline_graphql: {
enabled: false,
time: 24*60*60*1000
}
}, },
db_user_id: true, db_user_id: true,
db_post_n3: false, db_post_n3: false,