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){
|
if(res.headers && res.headers['set-cookie'] && cookies_added){
|
||||||
res.headers['set-cookie'].forEach((x) => {
|
res.headers['set-cookie'].forEach((x) => {
|
||||||
x.split(';').forEach((x) => {
|
x.split(';').forEach((x) => {
|
||||||
const [key, value] = x.split('=');
|
const arr = x.split('=')
|
||||||
if (!value) return;
|
if(arr.length <= 1 ) return;
|
||||||
|
const key = arr.shift()?.trim() as string
|
||||||
|
const value = arr.join('=').trim()
|
||||||
setCookie(key, value);
|
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: '));
|
let cookies = res.head.filter((x) => x.toLocaleLowerCase().startsWith('set-cookie: '));
|
||||||
cookies.forEach((x) => {
|
cookies.forEach((x) => {
|
||||||
x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => {
|
x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => {
|
||||||
let [key, value] = y.split('=');
|
const arr = y.split('=')
|
||||||
if (!value)
|
if(arr.length <= 1 ) return;
|
||||||
return;
|
const key = arr.shift()?.trim() as string
|
||||||
|
const value = arr.join('=').trim()
|
||||||
setCookie(key, value);
|
setCookie(key, value);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -183,10 +183,10 @@ export function authorization(): void {
|
|||||||
console.log('Cookies has been added successfully.');
|
console.log('Cookies has been added successfully.');
|
||||||
let cookie: Object = {};
|
let cookie: Object = {};
|
||||||
cook.split(';').forEach((x) => {
|
cook.split(';').forEach((x) => {
|
||||||
let [ key, value ] = x.split('=')
|
const arr = x.split('=')
|
||||||
if(!value) return;
|
if(arr.length <= 1 ) return;
|
||||||
key = key.trim()
|
const key = arr.shift()?.trim() as string
|
||||||
value = value.trim()
|
const value = arr.join('=').trim()
|
||||||
Object.assign(cookie, { [key] : value })
|
Object.assign(cookie, { [key] : value })
|
||||||
})
|
})
|
||||||
fs.writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
|
fs.writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user