This commit is contained in:
2025-05-02 15:39:44 +08:00
parent e58adbc46b
commit ee483aa87e
32 changed files with 919 additions and 621 deletions

View File

@@ -0,0 +1,20 @@
import { app, xhsServices } from '@/app.ts';
import { Parse } from '@/libs/parse.ts';
app
.route({
path: 'fans',
key: 'init-fans',
})
.define(async (ctx) => {
const client = xhsServices.getClient();
const res = await client.getFollowNotifications();
if (res.code === 0) {
const data = res.data;
const fans = data.message_list;
const fansList = Parse.getConnects(fans);
//
} else {
ctx.body = res;
}
})
.addTo(app);

View File

@@ -0,0 +1 @@
import './mentions/index.ts'

View File

@@ -0,0 +1,2 @@
import './mention.ts'
import './unread-task.ts'

View File

@@ -0,0 +1,89 @@
import { app, xhsServices } from '@/app.ts';
app
.route({
path: 'mention',
key: 'getUnread',
description: '获取提及列表',
})
.define(async (ctx) => {
//
const client = xhsServices.getClient();
const res = await client.getUnread();
if (res.code === 0) {
const unread_count = res.data.unread_count;
ctx.body = res.data;
} else {
ctx.body = {
unread_count: 0,
};
}
})
.addTo(app);
app
.route({
path: 'mention',
key: 'getNote',
description: '获取笔记',
validator: {
node_id: {
type: 'string',
required: true,
},
xsec_token: {
type: 'string',
required: true,
},
},
isDebug: true,
})
.define(async (ctx) => {
const node_id = ctx.query.node_id;
const xsec_token = ctx.query.xsec_token;
const client = xhsServices.getClient();
try {
console.log('get note by node_id', node_id, 'xsec_token', xsec_token);
const res = await client.getNoteByIdFromHtml(node_id, xsec_token);
console.log('res====', res);
ctx.body = res;
} catch (error) {
console.log('res', error);
ctx.throw(500, '获取笔记失败');
}
})
.addTo(app);
app
.route({
path: 'mention',
key: 'addComment',
})
.define(async (ctx) => {
const { node_id, comment_id, content } = ctx.query;
const client = xhsServices.getClient();
const res = await client.postComment({
note_id: node_id,
comment_id: comment_id,
content,
});
ctx.body = res.data;
})
.addTo(app);
app
.route({
path: 'mention',
key: 'getMention',
description: '获取提及列表',
validator: {
num: {
type: 'number',
required: true,
},
},
})
.define(async (ctx) => {
const num = ctx.query.num;
const client = xhsServices.getClient();
const res = await client.getMention(num);
ctx.body = res.data;
})
.addTo(app);

View File

@@ -0,0 +1,58 @@
import { app, xhsServices } from '@/app.ts';
import { Mention } from '@/libs/xhs-type/mention.ts';
import { Parse } from '@/libs/parse.ts';
import { client } from '@/test/common.ts';
app
.route({
path: 'mention',
key: 'run-unread-task',
description: '运行未读任务',
})
.define(async (ctx) => {
const unredRes = await app.call({
path: 'mention',
key: 'getUnread',
});
console.log('unredRes', unredRes.body, unredRes.code);
if (unredRes.code === 200) {
const unread_count = unredRes.body.unread_count;
const mentionRes = await app.call({
path: 'mention',
key: 'getMention',
payload: {
num: 2,
},
});
if (mentionRes.code === 200) {
const mentionList = mentionRes.body.message_list as Mention[];
console.log('mentionList', mentionList);
for (const mention of mentionList) {
const node_id = mention.item_info.id;
const xsec_token = mention.item_info.xsec_token;
let comment: any = Parse.getComment(mention);
const user = Parse.getUser(mentionList[0]);
console.log('node_id', node_id, 'xsec_token', xsec_token, comment);
console.log('user', user);
const noteRes = await app.call({
path: 'mention',
key: 'getNote',
payload: {
node_id,
xsec_token,
},
});
const note = Parse.getNote(noteRes.body);
console.log('getNote', noteRes.body);
const note_id = note.node_id;
const comment_id = comment?.comment_id || '';
// const commentRes = await client.postComment({
// note_id: note_id,
// comment_id: comment_id,
// content: 'comment',
// });
// console.log('commentRes', commentRes);
}
}
}
})
.addTo(app);