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