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

@@ -1,7 +1,7 @@
import { getApiInfo } from './xhs-api/api.ts';
import { XhsClient as XhsClientBase } from '@kevisual/xhs-core';
import { Mention, CommonentInfo } from './xhs-type/mention.ts';
import { Mention, CommonentInfo, ResponseMession } from './xhs-type/mention.ts';
import { pick } from 'lodash-es';
export type Result<T> = {
code: number; // 0: success
msg?: string;
@@ -44,7 +44,7 @@ export const getSign = async (signInfo: SignInfo, options?: SignOptions): Promis
},
body: JSON.stringify({
uri: uri,
data: data,
data,
a1,
web_session: web_session,
}),
@@ -71,19 +71,21 @@ export class XhsClient extends XhsClientBase {
console.log('url', data.url);
console.log('status', data?.response?.status);
if (data.response) {
console.log('data', data.response.data);
// console.log('data', data.response.data);
}
} else if (msg === 'request') {
console.log('request', data);
const { method, url } = data || {};
const headers = pick(data?.headers || {}, ['Cookie', 'x-s', 'x-t', 'x-s-common']);
// console.log('request', { headers, method, url });
} else if (msg === 'html') {
// console.log('html', response);
}
switch (msg) {
case 'get':
console.log('get', data);
// console.log('get', data);
break;
case 'sign':
console.log('sign', data);
// console.log('sign', data);
break;
}
}
@@ -157,7 +159,7 @@ export class XhsClient extends XhsClientBase {
* @uri /api/sns/web/v1/you/mentions
* @returns
*/
async getMention(num = 20): Promise<Result<Mention>> {
async getMention(num = 20): Promise<Result<ResponseMession>> {
const url = '/api/sns/web/v1/you/mentions';
const response = await this.get(
url,
@@ -184,6 +186,11 @@ export class XhsClient extends XhsClientBase {
const xs = _sign?.['x-s'];
const xt = _sign?.['x-t'];
const b1 = _sign?.['b1'];
const newA1 = _sign?.['a1'];
if (a1 !== newA1) {
this.setCookieMap({ a1: newA1 });
this.printResult('cookie change', a1);
}
if (res && xs) {
headers['x-s'] = xs;
headers['x-t'] = xt;
@@ -214,15 +221,23 @@ export class XhsClient extends XhsClientBase {
* @param comment
* @returns
*/
async postComment(comment: { note_id: string; comment_id: string; content: string }) {
async postComment(comment: { note_id: string; comment_id?: string; content: string; images_info?: any, images?: string[] }) {
const uri = '/api/sns/web/v1/comment/post';
try {
const data = {
note_id: comment.note_id,
content: comment.content,
target_comment_id: comment.comment_id,
at_users: [], //
};
if (comment.comment_id) {
data['target_comment_id'] = comment.comment_id;
}
if (comment.images_info) {
data['images_info'] = comment.images_info;
}
if (comment.images) {
data['images'] = comment.images;
}
type PostCommentResponse = {
comment: CommonentInfo;
time: number;