generated from tailored/router-db-template
temp
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { app, xhsServices } from '@kevisual/xhs/app.ts';
|
||||
|
||||
import { Parse } from '@kevisual/xhs/libs/parse.ts';
|
||||
import { Mention } from '@kevisual/xhs/libs/xhs-type/mention.ts';
|
||||
const sleep = (ms: number) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
};
|
||||
app
|
||||
.route({
|
||||
path: 'mention',
|
||||
@@ -7,11 +11,9 @@ app
|
||||
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 = {
|
||||
@@ -20,6 +22,19 @@ app
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
app
|
||||
.route({
|
||||
path: 'mention',
|
||||
key: 'postRead',
|
||||
description: '标记为已读',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const type = ctx.query.type || 'mentions';
|
||||
const client = xhsServices.getClient();
|
||||
const res = await client.postRead(type);
|
||||
ctx.body = res.data;
|
||||
})
|
||||
.addTo(app);
|
||||
app
|
||||
.route({
|
||||
path: 'mention',
|
||||
@@ -58,14 +73,19 @@ app
|
||||
key: 'addComment',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { node_id, comment_id, content } = ctx.query;
|
||||
const { note_id, comment_id, content } = ctx.query;
|
||||
const client = xhsServices.getClient();
|
||||
const res = await client.postComment({
|
||||
note_id: node_id,
|
||||
note_id: note_id,
|
||||
comment_id: comment_id,
|
||||
content,
|
||||
});
|
||||
ctx.body = res.data;
|
||||
if (res.code === 0) {
|
||||
ctx.body = res.data;
|
||||
} else {
|
||||
console.log('添加评论失败', res.code);
|
||||
ctx.throw(res.code, '添加评论失败');
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
app
|
||||
@@ -84,6 +104,28 @@ app
|
||||
const num = ctx.query.num;
|
||||
const client = xhsServices.getClient();
|
||||
const res = await client.getMention(num);
|
||||
ctx.body = res.data;
|
||||
if (res.code === 0) {
|
||||
const mentionList = res.data.message_list;
|
||||
const handleMention: any[] = [];
|
||||
for (const mention of mentionList) {
|
||||
const mention_id = mention.id;
|
||||
const note_id = mention.item_info.id;
|
||||
const xsec_token = mention.item_info.xsec_token;
|
||||
let comment: any = Parse.getComment(mention);
|
||||
// console.log('note_id', note_id, 'xsec_token', xsec_token, comment);
|
||||
handleMention.push({
|
||||
mention_id,
|
||||
note_id,
|
||||
xsec_token,
|
||||
comment,
|
||||
mention,
|
||||
});
|
||||
}
|
||||
console.log('获取提及列表成功', res.code, res.data?.message_list?.length);
|
||||
ctx.body = handleMention;
|
||||
} else {
|
||||
console.log('获取提及列表失败', res.code);
|
||||
ctx.throw(res.code, '获取提及列表失败');
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user