instagram: add freebind dispatcher support

This commit is contained in:
wukko 2024-05-14 22:08:32 +06:00 committed by dumbmoron
parent 4b0814a2ec
commit e44927e5ad
No known key found for this signature in database

View file

@ -41,6 +41,9 @@ const cachedDtsg = {
expiry: 0
}
export default function(obj) {
const dispatcher = obj.dispatcher;
async function findDtsgId(cookie) {
try {
if (cachedDtsg.expiry > Date.now()) return cachedDtsg.value;
@ -49,7 +52,8 @@ async function findDtsgId(cookie) {
headers: {
...commonHeaders,
cookie
}
},
dispatcher
}).then(r => r.text());
const token = data.match(/"dtsg":{"token":"(.*?)"/)[1];
@ -78,6 +82,7 @@ async function request(url, cookie, method = 'GET', requestData) {
method,
headers,
body: requestData && new URLSearchParams(requestData),
dispatcher
});
if (data.headers.get('X-Ig-Set-Www-Claim') && cookie)
@ -95,7 +100,8 @@ async function getMediaId(id, { cookie, token } = {}) {
...mobileHeaders,
...( token && { authorization: `Bearer ${token}` } ),
cookie
}
},
dispatcher
}).then(r => r.json()).catch(() => {});
return oembed?.media_id;
@ -107,7 +113,8 @@ async function requestMobileApi(mediaId, { cookie, token } = {}) {
...mobileHeaders,
...( token && { authorization: `Bearer ${token}` } ),
cookie
}
},
dispatcher
}).then(r => r.json()).catch(() => {});
return mediaInfo?.items?.[0];
@ -117,7 +124,8 @@ async function requestHTML(id, cookie) {
headers: {
...embedHeaders,
cookie
}
},
dispatcher
}).then(r => r.text()).catch(() => {});
let embedData = JSON.parse(data?.match(/"init",\[\],\[(.*?)\]\],/)[1]);
@ -333,7 +341,6 @@ async function getStory(username, id) {
return { error: 'ErrorCouldntFetch' };
}
export default function(obj) {
const { postId, storyId, username } = obj;
if (postId) return getPost(postId);
if (username && storyId) return getStory(username, storyId);