mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
instagram: add freebind dispatcher support
This commit is contained in:
parent
4b0814a2ec
commit
e44927e5ad
1 changed files with 299 additions and 292 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue