mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 16:17:29 +00:00
Preserve history error kind
This commit is contained in:
parent
2419fbf08b
commit
5ed035a432
@ -91,7 +91,7 @@ function fetchUserFromHTML(username) {
|
||||
if (history.store.has("user")) {
|
||||
const entry = history.store.get("user")
|
||||
if (!entry.lastRequestSuccessful && Date.now() < entry.lastRequestAt + blockedCacheConfig.time) {
|
||||
return Promise.reject(constants.symbols.RATE_LIMITED)
|
||||
return Promise.reject(entry.kind || constants.symbols.RATE_LIMITED)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -148,7 +148,7 @@ function fetchUserFromHTML(username) {
|
||||
}
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.INSTAGRAM_DEMANDS_LOGIN || error === constants.symbols.RATE_LIMITED) {
|
||||
history.report("user", false)
|
||||
history.report("user", false, error)
|
||||
}
|
||||
throw error
|
||||
})
|
||||
@ -230,7 +230,7 @@ function fetchUserFromCombined(userID, username) {
|
||||
return {user, quotaUsed}
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.RATE_LIMITED) {
|
||||
history.report("reel", false)
|
||||
history.report("reel", false, error)
|
||||
}
|
||||
throw error
|
||||
})
|
||||
@ -277,7 +277,7 @@ function fetchTimelinePage(userID, after) {
|
||||
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)
|
||||
return Promise.reject(entry.kind || constants.symbols.RATE_LIMITED)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -305,7 +305,7 @@ function fetchTimelinePage(userID, after) {
|
||||
return timeline
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.RATE_LIMITED || error === constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER) {
|
||||
history.report("timeline", false)
|
||||
history.report("timeline", false, error)
|
||||
}
|
||||
throw error
|
||||
})
|
||||
@ -337,7 +337,7 @@ function fetchIGTVPage(userID, after) {
|
||||
return timeline
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.RATE_LIMITED || error === constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER) {
|
||||
history.report("igtv", false)
|
||||
history.report("igtv", false, error)
|
||||
}
|
||||
throw error
|
||||
})
|
||||
@ -441,7 +441,7 @@ function fetchShortcodeData(shortcode) {
|
||||
}
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.RATE_LIMITED || error === constants.symbols.INSTAGRAM_BLOCK_TYPE_DECEMBER) {
|
||||
history.report("post", false)
|
||||
history.report("post", false, error)
|
||||
}
|
||||
throw error
|
||||
})
|
||||
|
@ -7,7 +7,7 @@ class RequestHistory {
|
||||
*/
|
||||
constructor(tracked) {
|
||||
this.tracked = new Set(tracked)
|
||||
/** @type {Map<string, {lastRequestAt: number | null, lastRequestSuccessful: boolean | null}>} */
|
||||
/** @type {Map<string, {lastRequestAt: number | null, lastRequestSuccessful: boolean | null, kind?: any}>} */
|
||||
this.store = new Map()
|
||||
for (const key of tracked) {
|
||||
this.store.set(key, {
|
||||
@ -20,12 +20,14 @@ class RequestHistory {
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {boolean} success
|
||||
* @param {any} [kind]
|
||||
*/
|
||||
report(key, success) {
|
||||
report(key, success, kind) {
|
||||
if (!this.tracked.has(key)) throw new Error(`Trying to report key ${key}, but is not tracked`)
|
||||
const entry = this.store.get(key)
|
||||
entry.lastRequestAt = Date.now()
|
||||
entry.lastRequestSuccessful = success
|
||||
entry.kind = kind
|
||||
if (constants.caching.db_request_history) {
|
||||
db.prepare("INSERT INTO RequestHistory (type, success, timestamp) VALUES (?, ?, ?)").run(key, +entry.lastRequestSuccessful, entry.lastRequestAt)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user