Show if blocked in /api/stats
This is experimental and is not listed in /api/stats:features yet.
This commit is contained in:
@@ -2,23 +2,29 @@ const constants = require("./constants")
|
||||
const {request} = require("./utils/request")
|
||||
const {extractSharedData} = require("./utils/body")
|
||||
const {TtlCache, RequestCache} = require("./cache")
|
||||
require("./testimports")(constants, request, extractSharedData, RequestCache)
|
||||
const RequestHistory = require("./structures/RequestHistory")
|
||||
require("./testimports")(constants, request, extractSharedData, RequestCache, RequestHistory)
|
||||
|
||||
const requestCache = new RequestCache(constants.caching.resource_cache_time)
|
||||
/** @type {import("./cache").TtlCache<import("./structures/TimelineEntry")>} */
|
||||
const timelineEntryCache = new TtlCache(constants.caching.resource_cache_time)
|
||||
const history = new RequestHistory(["user", "timeline", "post"])
|
||||
|
||||
function fetchUser(username) {
|
||||
return requestCache.getOrFetch("user/"+username, () => {
|
||||
return request(`https://www.instagram.com/${username}/`).then(res => {
|
||||
if (res.status === 302) throw constants.symbols.INSTAGRAM_DEMANDS_LOGIN
|
||||
else if (res.status === 404) throw constants.symbols.NOT_FOUND
|
||||
else return res.text().then(text => {
|
||||
if (res.status === 302) {
|
||||
history.report("user", false)
|
||||
throw constants.symbols.INSTAGRAM_DEMANDS_LOGIN
|
||||
} else if (res.status === 404) {
|
||||
throw constants.symbols.NOT_FOUND
|
||||
} else return res.text().then(text => {
|
||||
// require down here or have to deal with require loop. require cache will take care of it anyway.
|
||||
// User -> Timeline -> TimelineImage -> collectors -/> User
|
||||
const User = require("./structures/User")
|
||||
const sharedData = extractSharedData(text)
|
||||
const user = new User(sharedData.entry_data.ProfilePage[0].graphql.user)
|
||||
history.report("user", true)
|
||||
return user
|
||||
})
|
||||
})
|
||||
@@ -40,10 +46,16 @@ function fetchTimelinePage(userID, after) {
|
||||
}))
|
||||
return requestCache.getOrFetchPromise("page/"+after, () => {
|
||||
return request(`https://www.instagram.com/graphql/query/?${p.toString()}`).then(res => res.json()).then(root => {
|
||||
if (!root.data) console.error("missing data:", root) //todo: please make this better.
|
||||
/** @type {import("./types").PagedEdges<import("./types").TimelineEntryN2>} */
|
||||
const timeline = root.data.user.edge_owner_to_timeline_media
|
||||
return timeline
|
||||
if (!root.data) {
|
||||
history.report("timeline", false)
|
||||
console.error("missing data from timeline request, 429?", root) //todo: please make this better.
|
||||
throw new Error("missing data from timeline request, 429?")
|
||||
} else {
|
||||
/** @type {import("./types").PagedEdges<import("./types").TimelineEntryN2>} */
|
||||
const timeline = root.data.user.edge_owner_to_timeline_media
|
||||
history.report("timeline", true)
|
||||
return timeline
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -89,13 +101,20 @@ function fetchShortcodeData(shortcode) {
|
||||
p.set("variables", JSON.stringify({shortcode}))
|
||||
return requestCache.getOrFetchPromise("shortcode/"+shortcode, () => {
|
||||
return request(`https://www.instagram.com/graphql/query/?${p.toString()}`).then(res => res.json()).then(root => {
|
||||
if (!root.data) {
|
||||
history.report("post", false)
|
||||
console.error("missing data from post request, 429?", root) //todo: please make this better.
|
||||
throw new Error("missing data from post request, 429?")
|
||||
/** @type {import("./types").TimelineEntryN3} */
|
||||
const data = root.data.shortcode_media
|
||||
if (data == null) {
|
||||
// the thing doesn't exist
|
||||
throw constants.symbols.NOT_FOUND
|
||||
} else {
|
||||
return data
|
||||
const data = root.data.shortcode_media
|
||||
if (data == null) {
|
||||
// the thing doesn't exist
|
||||
throw constants.symbols.NOT_FOUND
|
||||
} else {
|
||||
history.report("post", true)
|
||||
return data
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -108,3 +127,4 @@ module.exports.fetchShortcodeData = fetchShortcodeData
|
||||
module.exports.requestCache = requestCache
|
||||
module.exports.timelineEntryCache = timelineEntryCache
|
||||
module.exports.getOrFetchShortcode = getOrFetchShortcode
|
||||
module.exports.history = history
|
||||
|
||||
Reference in New Issue
Block a user