generated from tailored/router-db-template
add db module
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { getApiInfo } from './xhs-api/api.ts';
|
||||
import { XhsClient as XhsClientBase } from '@kevisual/xhs-core';
|
||||
import { Mention, CommonentInfo } from './xhs-type/mention.ts';
|
||||
|
||||
@@ -13,17 +14,29 @@ type SignInfo = {
|
||||
a1: string;
|
||||
web_session?: string;
|
||||
};
|
||||
type SignResponse = {
|
||||
a1: string;
|
||||
sign: {
|
||||
b1: string;
|
||||
b1b1: string;
|
||||
['x-s']: string;
|
||||
['x-t']: string;
|
||||
};
|
||||
[key: string]: any;
|
||||
};
|
||||
type SignOptions = {
|
||||
signUrl?: string;
|
||||
};
|
||||
export const getSign = async (signInfo: SignInfo, options?: SignOptions) => {
|
||||
export const getSign = async (signInfo: SignInfo, options?: SignOptions): Promise<SignResponse> => {
|
||||
const { uri, data, a1, web_session } = signInfo;
|
||||
// console.log('getSign', uri, data, a1, web_session);
|
||||
// let signUri = new URL(uri, 'http://light.xiongxiao.me:5006').pathname;
|
||||
// signUri = '/api/sns/web/v2/user/me';
|
||||
try {
|
||||
let signUrl = options?.signUrl || 'http://light.xiongxiao.me:5006/sign';
|
||||
// signUrl = 'http://localhost:5005/sign'
|
||||
let signUrl = options?.signUrl || 'http://localhost:5005/sign';
|
||||
// signUrl = 'http://localhost:5005/sign';
|
||||
// const urlA1 = ''http://light.xiongxiao.me:5006/a1';
|
||||
// const urlA1 = 'http://localhost:5005/a1';
|
||||
const signs = await fetch(signUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -52,18 +65,27 @@ export class XhsClient extends XhsClientBase {
|
||||
constructor(opts: XhsOptions) {
|
||||
super(opts as any);
|
||||
}
|
||||
printResult(msg: string, response: any) {
|
||||
getApiInfo = getApiInfo;
|
||||
printResult(msg: string, data: any) {
|
||||
if (msg === 'response') {
|
||||
console.log('url', response.url);
|
||||
if (response.response) {
|
||||
console.log('status', response.response.status);
|
||||
console.log('data', response.response.data);
|
||||
console.log('url', data.url);
|
||||
console.log('status', data?.response?.status);
|
||||
if (data.response) {
|
||||
console.log('data', data.response.data);
|
||||
}
|
||||
} else if (msg === 'request') {
|
||||
// console.log('request', response);
|
||||
console.log('request', data);
|
||||
} else if (msg === 'html') {
|
||||
// console.log('html', response);
|
||||
}
|
||||
switch (msg) {
|
||||
case 'get':
|
||||
console.log('get', data);
|
||||
break;
|
||||
case 'sign':
|
||||
console.log('sign', data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取未读消息
|
||||
@@ -71,7 +93,7 @@ export class XhsClient extends XhsClientBase {
|
||||
*/
|
||||
async getUnread(): Promise<Result<UnreadCount>> {
|
||||
const url = '/api/sns/web/unread_count';
|
||||
const response = await this.get(url);
|
||||
const response = await this.get(url, null, { needSign: false });
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -103,6 +125,12 @@ export class XhsClient extends XhsClientBase {
|
||||
const response = await super.getUserInfoFromHtml(userId);
|
||||
return response as ReturnData;
|
||||
}
|
||||
/**
|
||||
* 这个接口不能多用,否则会出现封控406错误
|
||||
* @param num
|
||||
* @param cursor
|
||||
* @returns
|
||||
*/
|
||||
async getFollowNotifications(num = 10, cursor = '') {
|
||||
const url = '/api/sns/web/v1/you/connections';
|
||||
type Connection = {
|
||||
@@ -129,18 +157,14 @@ export class XhsClient extends XhsClientBase {
|
||||
* @uri /api/sns/web/v1/you/mentions
|
||||
* @returns
|
||||
*/
|
||||
async getMention(num = 10): Promise<Result<Mention>> {
|
||||
async getMention(num = 20): Promise<Result<Mention>> {
|
||||
const url = '/api/sns/web/v1/you/mentions';
|
||||
const response = await this.get(
|
||||
url,
|
||||
{ num },
|
||||
{ num: 20, cursor: '' },
|
||||
{
|
||||
sign: this.sign.bind(this),
|
||||
// headers: {
|
||||
// 'x-s':
|
||||
// 'XYW_eyJzaWduU3ZuIjoiNTYiLCJzaWduVHlwZSI6IngyIiwiYXBwSWQiOiJsb2dpbiIsInNpZ25WZXJzaW9uIjoiMSIsInBheWxvYWQiOiJiNGJmMGI2MDVkZTlkOWMyY2RlNTI2YmVjNjM2ZmIxMjkxYzUxMTIyYWQyOTk5MzIyMzNjMmU0OTEzMWFmYzgzY2FmOGQzZDIzMTA0Y2RlNWUzZDZlZDczMDg0MmUzYzAxOTNkY2FjZjEyZjk1NTMzZGQzY2ZkMGFmOTg5MGZmMDIwNWI0MmQwOTNiYmJjMGNkZWU3MzdmOGE2MmRkYWVlYjZhMjcxZDViNjZkNGRjYjA1NDg2MGZhNTllN2M5MjE0ZDE2OTJjYWQyZjZmNzE1NThmYWQ3YjQxZjlhZTNiYjA1ZDExN2YzYWI2ZjRjYzY5MzcyMzRhOTY1OTkxYzMwMWY2YjI1MzY4MTZiNzM1YzhmMWEzOTk2ODhkMWU0NDFiODljYTNlNzQ3YWNlN2M2MGIzZDlhZWQwZDVlZDZlNGFhMDE5MmQ5YzZjNDE1M2IxM2RjODAwYjUzZTQxYWEzOTU4MjJhMzYyMmJjODEwYmY4MzA3MjkwMjY2ZDUzNmQwMjdkMTJlOWEwMzhlZmY1YWU4OTM5NDVlNDhmYmY2MCJ9',
|
||||
// 'x-t': '1746097556685',
|
||||
// },
|
||||
needSign: true,
|
||||
},
|
||||
);
|
||||
return response;
|
||||
@@ -148,15 +172,25 @@ export class XhsClient extends XhsClientBase {
|
||||
async sign(uri: string, data: any, config: any) {
|
||||
let headers = config?.headers || {};
|
||||
const cookieDist = this.getCookieMap();
|
||||
const apiInfo = this.getApiInfo(uri);
|
||||
if (apiInfo && !apiInfo?.needSign) {
|
||||
return config || {};
|
||||
}
|
||||
const web_session = cookieDist['web_session'];
|
||||
const a1 = cookieDist['a1'];
|
||||
const res = await getSign({ uri, data, a1, web_session }, this.signConfig);
|
||||
if (res) {
|
||||
headers['x-s'] = res?.['x-s'];
|
||||
headers['x-t'] = res?.['x-t'];
|
||||
const _sign = res.sign;
|
||||
this.printResult('sign', { uri, apiInfo, res });
|
||||
const xs = _sign?.['x-s'];
|
||||
const xt = _sign?.['x-t'];
|
||||
const b1 = _sign?.['b1'];
|
||||
if (res && xs) {
|
||||
headers['x-s'] = xs;
|
||||
headers['x-t'] = xt;
|
||||
// headers['x-s-common'] = this.getXCommon(a1, b1, xs, xt);
|
||||
config.headers = headers;
|
||||
} else {
|
||||
console.log('get sign error');
|
||||
console.log('get sign error', res);
|
||||
throw new Error('get sign error');
|
||||
}
|
||||
return config;
|
||||
|
||||
Reference in New Issue
Block a user