Deleted accounts become 404 instead of error

Fixes #95.
This commit is contained in:
Cadence Ember 2020-07-07 22:08:19 +12:00
parent 9073aa581b
commit c3455ec183
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412
3 changed files with 19 additions and 8 deletions

View File

@ -140,7 +140,7 @@ class RequestCache extends TtlCache {
class UserRequestCache extends TtlCache {
constructor(ttl) {
super(ttl)
/** @type {Map<string, {data: T, isReel: boolean, isFailedPromise: boolean, htmlFailed: boolean, time: number}>} */
/** @type {Map<string, {data: T, isReel: boolean, isFailedPromise: boolean, htmlFailed: boolean, reelFailed: boolean, time: number}>} */
this.cache
}
@ -153,7 +153,7 @@ class UserRequestCache extends TtlCache {
const existing = this.cache.get(key)
// Preserve html failure status if now requesting as reel
const htmlFailed = isReel && existing && existing.htmlFailed
this.cache.set(key, {data, isReel, isFailedPromise: false, htmlFailed, time: Date.now()})
this.cache.set(key, {data, isReel, isFailedPromise: false, htmlFailed, reelFailed: false, time: Date.now()})
}
/**
@ -180,7 +180,7 @@ class UserRequestCache extends TtlCache {
}
}
} else { // (existing.isFailedPromise ~= true): the existing entry is a failed request
if (existing.htmlFailed && !willFetchReel) { // it's no use! the HTML attempt will fail again: abandon it.
if (existing.reelFailed || (existing.htmlFailed && !willFetchReel)) { // it's no use! the attempt will fail again; don't try.
return Promise.resolve(existing.data) // this is actually a promise rejection
}
}
@ -191,7 +191,8 @@ class UserRequestCache extends TtlCache {
}
return result
}).catch(error => {
this.cache.get(key).htmlFailed = true
if (willFetchReel) this.cache.get(key).reelFailed = true
else this.cache.get(key).htmlFailed = true
this.cache.get(key).isFailedPromise = true
throw error
})

View File

@ -206,15 +206,17 @@ function fetchUserFromCombined(userID, username) {
return res
}).then(res => res.json()).then(root => {
const result = root.data.user
if (!result) throw constants.symbols.NOT_FOUND
if (!result) {
// user ID doesn't exist.
db.prepare("DELETE FROM Users WHERE user_id = ?").run(userID) // deleting the entry makes sense to me; the username might be claimed by somebody else later
throw constants.symbols.NOT_FOUND // this should cascade down and show the user not found page
}
// require down here or have to deal with require loop. require cache will take care of it anyway.
// ReelUser -> Timeline -> TimelineEntry -> collectors -/> User
const ReelUser = require("./structures/ReelUser")
const user = new ReelUser(result.reel.user)
history.report("reel", true)
return user
}).catch(error => {
throw error
})
}).then(async user => {
// Add first timeline page
@ -274,6 +276,12 @@ function fetchTimelinePage(userID, after) {
return switcher.request("timeline_graphql", `https://www.instagram.com/graphql/query/?${p.toString()}`, async res => {
if (res.status === 429) throw constants.symbols.RATE_LIMITED
}).then(g => g.json()).then(root => {
if (root.data.user === null) {
// user ID doesn't exist.
db.prepare("DELETE FROM Users WHERE user_id = ?").run(userID) // deleting the entry makes sense to me; the username might be claimed by somebody else later
requestCache
throw constants.symbols.NOT_FOUND // this should cascade down and show the user not found page
}
/** @type {import("./types").PagedEdges<import("./types").TimelineEntryN2>} */
const timeline = root.data.user.edge_owner_to_timeline_media
history.report("timeline", true)
@ -425,6 +433,7 @@ module.exports.fetchTimelinePage = fetchTimelinePage
module.exports.fetchIGTVPage = fetchIGTVPage
module.exports.getOrCreateShortcode = getOrCreateShortcode
module.exports.fetchShortcodeData = fetchShortcodeData
module.exports.requestCache = requestCache
module.exports.userRequestCache = userRequestCache
module.exports.timelineEntryCache = timelineEntryCache
module.exports.getOrFetchShortcode = getOrFetchShortcode

View File

@ -237,7 +237,8 @@ let constants = {
},
resources: {
instances_wiki_raw: "https://raw.githubusercontent.com/wiki/cloudrac3r/bibliogram/Instances.md"
instances_wiki_raw: "https://raw.githubusercontent.com/wiki/cloudrac3r/bibliogram/Instances.md",
saved_requests_location: "https://meta.bibliogram.art/saved_requests/"
},
// My code uses this stuff. Server owners have no reason to change it.