#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 => { str.split('; ').forEach(cookie => {
const key = cookie.split('=')[0]; const key = cookie.split('=')[0];
const value = cookie.split('=').splice(1).join('='); const value = cookie.split('=').splice(1).join('=');
obj[key] = decodeURIComponent(value) obj[key] = value
}) })
return new Cookie(obj) return new Cookie(obj)
} }
toString() { 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() { toJSON() {
return this.toString() return this.toString()

View file

@ -49,11 +49,13 @@ export function getCookie(service) {
export function updateCookie(cookie, headers) { export function updateCookie(cookie, headers) {
if (!cookie) return; if (!cookie) return;
const parsed = parseSetCookie(splitCookiesString(headers.get('set-cookie'))), const parsed = parseSetCookie(
values = {} splitCookiesString(headers.get('set-cookie')),
{ decodeValues: false }
), values = {}
cookie.unset(parsed.filter(c => c.expires < new Date()).map(c => c.name)); 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); cookie.set(values);
if (Object.keys(values).length) dirty = true if (Object.keys(values).length) dirty = true

View file

@ -23,6 +23,9 @@ export default async function(obj) {
'User-Agent': genericUserAgent, 'User-Agent': genericUserAgent,
'X-Ig-App-Id': '936619743392459', 'X-Ig-App-Id': '936619743392459',
'X-Asbd-Id': '129477', '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-Dest': 'empty',
'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin', 'Sec-Fetch-Site': 'same-origin',
@ -32,6 +35,11 @@ export default async function(obj) {
cookie 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); updateCookie(cookie, data.headers);
data = (await data.json()).data; data = (await data.json()).data;
} catch (e) { } catch (e) {