#185: instagram hotfix

merge pull request #185 from dumbmoron/instagram-hotfix
This commit is contained in:
wukko 2023-08-21 22:05:11 +06:00 committed by GitHub
commit fded708d05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View file

@ -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()

View file

@ -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

View file

@ -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) {