This commit is contained in:
2025-05-05 00:01:36 +08:00
parent d6014b3c40
commit a412c09da0
20 changed files with 2911 additions and 102 deletions

View File

@@ -128,6 +128,23 @@ class XhsClient {
}
return {};
}
/**
*
* @param {*} data
*/
setCookieMap(data = {}) {
const cookieDict = this.getCookieMap();
const newCookieDict = { ...cookieDict, ...data };
const cookieStr = Object.entries(newCookieDict)
.map(([key, value]) => {
const trimmedKey = key.trim();
const trimmedValue = value ? value.trim() : '';
return `${trimmedKey}=${trimmedValue}`;
})
.join('; ');
this.axiosInstance.defaults.headers.Cookie = cookieStr;
this.cookie = cookieStr;
}
/**
* Get X-S and X-T
* @param {*} url

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
import { XhsClient } from '../src/index.js';
// import { XhsClient } from '../dist/app.mjs';
import { cookie } from './common.ts';
const client = new XhsClient({ cookie } as any);
client.setCookieMap({ a1: 'thisistest' })
console.log(client.getCookieMap());
console.log(client.cookie);

View File

@@ -0,0 +1,4 @@
import qs from 'querystring';
const r = qs.stringify({ a: 1, b: 2, c: 3 });
console.log(r); // a=1&b=2&c=3