2025-06-21 21:47:26 +08:00

62 lines
2.0 KiB
TypeScript

import { app, xhsServices } from '@kevisual/xhs/app.ts';
import { Mention } from '@kevisual/xhs/libs/xhs-type/mention.ts';
import { Parse } from '@kevisual/xhs/libs/parse.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 likes = unredRes.body.likes;
const unread = unread_count - likes;
const mentionRes = await app.call({
path: 'mention',
key: 'getMention',
payload: {
num: unread,
},
});
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);