Cookies fixes
This commit is contained in:
parent
568624efe0
commit
e4bce76c4a
@ -171,8 +171,10 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
||||
if(res.headers && res.headers['set-cookie'] && cookies_added){
|
||||
res.headers['set-cookie'].forEach((x) => {
|
||||
x.split(';').forEach((x) => {
|
||||
const [key, value] = x.split('=');
|
||||
if (!value) return;
|
||||
const arr = x.split('=')
|
||||
if(arr.length <= 1 ) return;
|
||||
const key = arr.shift()?.trim() as string
|
||||
const value = arr.join('=').trim()
|
||||
setCookie(key, value);
|
||||
});
|
||||
})
|
||||
@ -204,9 +206,10 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
||||
let cookies = res.head.filter((x) => x.toLocaleLowerCase().startsWith('set-cookie: '));
|
||||
cookies.forEach((x) => {
|
||||
x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => {
|
||||
let [key, value] = y.split('=');
|
||||
if (!value)
|
||||
return;
|
||||
const arr = y.split('=')
|
||||
if(arr.length <= 1 ) return;
|
||||
const key = arr.shift()?.trim() as string
|
||||
const value = arr.join('=').trim()
|
||||
setCookie(key, value);
|
||||
});
|
||||
});
|
||||
|
||||
@ -183,10 +183,10 @@ export function authorization(): void {
|
||||
console.log('Cookies has been added successfully.');
|
||||
let cookie: Object = {};
|
||||
cook.split(';').forEach((x) => {
|
||||
let [ key, value ] = x.split('=')
|
||||
if(!value) return;
|
||||
key = key.trim()
|
||||
value = value.trim()
|
||||
const arr = x.split('=')
|
||||
if(arr.length <= 1 ) return;
|
||||
const key = arr.shift()?.trim() as string
|
||||
const value = arr.join('=').trim()
|
||||
Object.assign(cookie, { [key] : value })
|
||||
})
|
||||
fs.writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user