This commit is contained in:
2025-06-21 16:31:00 +08:00
parent a150cbc533
commit ce7cd03cb3
18 changed files with 387 additions and 29 deletions

View File

@@ -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"
},

View File

@@ -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