generated from tailored/router-template
update
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
"types": "app.d.ts",
|
||||
"scripts": {
|
||||
"build": "bun run bun.config.mjs",
|
||||
"postbuild": "dts -i src/index.ts -o app.d.ts",
|
||||
"postbuild2": "dts -i src/index.ts -o app.d.ts",
|
||||
"cmd": "tsx src/test/command.ts ",
|
||||
"dts": "dts -i src/index.js -o app.d.ts"
|
||||
},
|
||||
|
||||
@@ -75,17 +75,31 @@ app
|
||||
.define(async (ctx) => {
|
||||
const { note_id, comment_id, content } = ctx.query;
|
||||
const client = xhsServices.getClient();
|
||||
const res = await client.postComment({
|
||||
note_id: note_id,
|
||||
comment_id: comment_id,
|
||||
content,
|
||||
});
|
||||
if (res.code === 0) {
|
||||
ctx.body = res.data;
|
||||
// content 300个字内,超过cai fen
|
||||
const textArr: string[] = [];
|
||||
if (content.length > 300) {
|
||||
const num = Math.ceil(content.length / 300);
|
||||
for (let i = 0; i < num; i++) {
|
||||
textArr.push(content.slice(i * 300, (i + 1) * 300));
|
||||
}
|
||||
} else {
|
||||
console.log('添加评论失败', res.code);
|
||||
ctx.throw(res.code, '添加评论失败');
|
||||
textArr.push(content);
|
||||
}
|
||||
const resArr: any[] = [];
|
||||
for (const text of textArr) {
|
||||
const res = await client.postComment({
|
||||
note_id: note_id,
|
||||
comment_id: comment_id,
|
||||
content: text,
|
||||
});
|
||||
if (res.code === 0) {
|
||||
resArr.push(res.data);
|
||||
} else {
|
||||
console.log('添加评论失败', res.code);
|
||||
ctx.throw(res.code, '添加评论失败');
|
||||
}
|
||||
}
|
||||
ctx.body = resArr;
|
||||
})
|
||||
.addTo(app);
|
||||
app
|
||||
|
||||
Reference in New Issue
Block a user