generated from tailored/router-db-template
test
This commit is contained in:
@@ -26,6 +26,18 @@ const transformJsonKeys = (jsonData) => {
|
||||
};
|
||||
|
||||
class XhsClient {
|
||||
proxies: string | null;
|
||||
timeout: number;
|
||||
_host: string;
|
||||
_creatorHost: string;
|
||||
_customerHost: string;
|
||||
home: string;
|
||||
userAgent: string;
|
||||
_cookie: string;
|
||||
_headers: Record<string, string>;
|
||||
signConfig?: Record<string, any> = {
|
||||
signUrl: 'http://localhost:5005/sign',
|
||||
};
|
||||
/**
|
||||
* Constructor for XhsClient
|
||||
* @param {Object} options - Configuration options
|
||||
@@ -108,7 +120,7 @@ class XhsClient {
|
||||
const cookieDict = this.getCookieMap();
|
||||
const newCookieDict = { ...cookieDict, ...data };
|
||||
const cookieStr = Object.entries(newCookieDict)
|
||||
.map(([key, value]) => {
|
||||
.map(([key, value]: [string, string]) => {
|
||||
const trimmedKey = key.trim();
|
||||
const trimmedValue = value ? value.trim() : '';
|
||||
return `${trimmedKey}=${trimmedValue}`;
|
||||
@@ -119,12 +131,12 @@ class XhsClient {
|
||||
this.cookie = cookieStr;
|
||||
}
|
||||
|
||||
async request(method, url, config = {}) {
|
||||
async request(method, url, config: any = {}) {
|
||||
try {
|
||||
delete config.sign;
|
||||
const headers = { ...this._headers, ...(config.headers || {}) };
|
||||
|
||||
const fetchOptions = {
|
||||
const fetchOptions: any = {
|
||||
method: method,
|
||||
headers: headers,
|
||||
};
|
||||
@@ -145,7 +157,7 @@ class XhsClient {
|
||||
if (response.status === 471 || response.status === 461) {
|
||||
const verifyType = response.headers.get('verifytype');
|
||||
const verifyUuid = response.headers.get('verifyuuid');
|
||||
throw new NeedVerifyError(`出现验证码,请求失败,Verifytype: ${verifyType},Verifyuuid: ${verifyUuid}`, response, verifyType, verifyUuid);
|
||||
throw new NeedVerifyError(`出现验证码,请求失败,Verifytype: ${verifyType},Verifyuuid: ${verifyUuid}`, response, verifyType);
|
||||
}
|
||||
|
||||
let data;
|
||||
@@ -197,7 +209,7 @@ class XhsClient {
|
||||
* @param {*} config
|
||||
* @returns
|
||||
*/
|
||||
async requestSign(uri, data = null, config = {}, method = 'GET') {
|
||||
async requestSign(uri, data = null, config: any = {}, method = 'GET') {
|
||||
const needSign = config.needSign ?? true;
|
||||
if (needSign && config.sign) {
|
||||
await config.sign(uri, data, config, method);
|
||||
@@ -324,7 +336,7 @@ class XhsClient {
|
||||
if (stateMatch) {
|
||||
const state = stateMatch[1].replace(/undefined/g, '""');
|
||||
if (state !== '{}') {
|
||||
const noteDict = transformJsonKeys(JSON.parse(state));
|
||||
const noteDict = transformJsonKeys(JSON.parse(state)) as any;
|
||||
return { code: 0, data: noteDict.note.note_detail_map[noteId].note };
|
||||
}
|
||||
}
|
||||
@@ -375,32 +387,6 @@ class XhsClient {
|
||||
return this.get(uri, params);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @uri /api/sns/web/v1/search/notes
|
||||
* @param {string} keyword 关键词
|
||||
* @param {number} page 页码
|
||||
* @param {number} pageSize 分页查询的数量
|
||||
* @param {string} sort 搜索的类型,分为: general, popularity_descending, time_descending
|
||||
* @param {number} noteType 笔记类型
|
||||
* @returns
|
||||
*/
|
||||
async getNoteByKeyword(keyword, page = 1, pageSize = 20, sort = SearchSortType.GENERAL, noteType = SearchNoteType.ALL) {
|
||||
const uri = '/api/sns/web/v1/search/notes';
|
||||
const data = {
|
||||
keyword: keyword,
|
||||
page: page,
|
||||
page_size: pageSize,
|
||||
search_id: getSearchId(),
|
||||
sort: sort.value,
|
||||
note_type: noteType.value,
|
||||
image_formats: ['jpg', 'webp', 'avif'],
|
||||
ext_flags: [],
|
||||
};
|
||||
|
||||
return this.post(uri, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取笔记评论
|
||||
* @uri /api/sns/web/v2/comment/page
|
||||
@@ -504,8 +490,9 @@ class XhsClient {
|
||||
if (stateMatch) {
|
||||
const state = stateMatch[1].replace(/"undefined"/g, '"_"').replace(/\bundefined\b/g, '""');
|
||||
if (state !== '{}') {
|
||||
const parsedState = JSON.parse(state);
|
||||
const userBasicInfo = transformJsonKeys(parsedState).user.user_page_data.basic_info;
|
||||
const parsedState = JSON.parse(state) as any;
|
||||
const data = transformJsonKeys(parsedState) as any
|
||||
const userBasicInfo =data.user.user_page_data.basic_info;
|
||||
return userBasicInfo;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ type XhsSign = {
|
||||
signUrl?: string;
|
||||
};
|
||||
export class XhsClient extends XhsClientBase {
|
||||
signConfig?: XhsSign;
|
||||
declare signConfig?: XhsSign;
|
||||
constructor(opts: XhsOptions) {
|
||||
super(opts as any);
|
||||
}
|
||||
@@ -181,7 +181,7 @@ export class XhsClient extends XhsClientBase {
|
||||
needSign: true,
|
||||
},
|
||||
);
|
||||
return response;
|
||||
return response as any;
|
||||
}
|
||||
async sign(uri: string, data: any, config: any, method?: 'GET' | 'POST') {
|
||||
let headers = config?.headers || {};
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts", "src/libs/client-base.js",
|
||||
"src/**/*.ts", "src/libs/client-base.ts",
|
||||
],
|
||||
"exclude": [],
|
||||
}
|
||||
Reference in New Issue
Block a user