mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-19 06:39:57 +00:00
#185: instagram hotfix
merge pull request #185 from dumbmoron/instagram-hotfix
This commit is contained in:
commit
fded708d05
3 changed files with 15 additions and 5 deletions
|
@ -20,13 +20,13 @@ export default class Cookie {
|
|||
str.split('; ').forEach(cookie => {
|
||||
const key = cookie.split('=')[0];
|
||||
const value = cookie.split('=').splice(1).join('=');
|
||||
obj[key] = decodeURIComponent(value)
|
||||
obj[key] = value
|
||||
})
|
||||
|
||||
return new Cookie(obj)
|
||||
}
|
||||
toString() {
|
||||
return Object.entries(this._values).map(([ name, value ]) => `${name}=${encodeURIComponent(value)}`).join('; ')
|
||||
return Object.entries(this._values).map(([ name, value ]) => `${name}=${value}`).join('; ')
|
||||
}
|
||||
toJSON() {
|
||||
return this.toString()
|
||||
|
|
|
@ -49,11 +49,13 @@ export function getCookie(service) {
|
|||
export function updateCookie(cookie, headers) {
|
||||
if (!cookie) return;
|
||||
|
||||
const parsed = parseSetCookie(splitCookiesString(headers.get('set-cookie'))),
|
||||
values = {}
|
||||
const parsed = parseSetCookie(
|
||||
splitCookiesString(headers.get('set-cookie')),
|
||||
{ decodeValues: false }
|
||||
), values = {}
|
||||
|
||||
cookie.unset(parsed.filter(c => c.expires < new Date()).map(c => c.name));
|
||||
parsed.filter(c => c.expires > new Date()).forEach(c => values[c.name] = c.value);
|
||||
parsed.filter(c => !c.expires || c.expires > new Date()).forEach(c => values[c.name] = c.value);
|
||||
|
||||
cookie.set(values);
|
||||
if (Object.keys(values).length) dirty = true
|
||||
|
|
|
@ -23,6 +23,9 @@ export default async function(obj) {
|
|||
'User-Agent': genericUserAgent,
|
||||
'X-Ig-App-Id': '936619743392459',
|
||||
'X-Asbd-Id': '129477',
|
||||
'x-ig-www-claim': cookie?._wwwClaim || '0',
|
||||
'x-csrftoken': cookie?.values()?.csrftoken,
|
||||
'x-requested-with': 'XMLHttpRequest',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
|
@ -32,6 +35,11 @@ export default async function(obj) {
|
|||
cookie
|
||||
}
|
||||
})
|
||||
|
||||
if (data.headers.get('X-Ig-Set-Www-Claim') && cookie) {
|
||||
cookie._wwwClaim = data.headers.get('X-Ig-Set-Www-Claim');
|
||||
}
|
||||
|
||||
updateCookie(cookie, data.headers);
|
||||
data = (await data.json()).data;
|
||||
} catch (e) {
|
||||
|
|
Loading…
Reference in a new issue