generated from tailored/router-db-template
temp
This commit is contained in:
89
packages/xhs/src/routes/mentions/mention.ts
Normal file
89
packages/xhs/src/routes/mentions/mention.ts
Normal 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);
|
||||
Reference in New Issue
Block a user