diff --git a/README.md b/README.md index 1ceefa8..76186d3 100644 --- a/README.md +++ b/README.md @@ -1 +1,16 @@ -# router app template +# 社交路由功能模块 + +## 小红书 + +自动获取和上传 + +[代理浏览器](https://git.xiongxiao.me/media/social-xhs-api-server) + +### 功能 + +#### 获取评论 + +#### 获取笔记信息 + +#### 返回笔记信息 + diff --git a/src/agent/xhs.ts b/src/agent/xhs.ts index 1f53cb1..75906a6 100644 --- a/src/agent/xhs.ts +++ b/src/agent/xhs.ts @@ -1,7 +1,6 @@ import { nanoid } from 'nanoid'; import { agent } from './agent.ts'; import { ai } from './ai.ts'; -import { cmdList } from './analyze/cmd.ts'; /** * 清除文本中的@信息 * @param text @@ -11,14 +10,36 @@ const clearAtInfo = (text: string = '') => { return newText.trim(); }; +/** + * 从文本中提取标签信息, 如 #标签 + * @param text + */ +export const pickTagsInfo = (text: string = '') => { + if (!text) { + return { + tags: [], + text: '', + }; + } + const _tags = text.match(/#([\u4e00-\u9fa5\w]+)/g) || []; + const validTags = _tags.map((tag) => tag.replace(/#/g, '')).filter((tag) => tag.trim() !== ''); + const noTagsText = text.replace(/#([\u4e00-\u9fa5\w]+)/g, '').trim(); + return { + tags: validTags, + text: noTagsText, + }; +}; + agent .route({ path: 'xhs', }) .define(async (ctx) => { - const { text = '' } = ctx.query || {}; + const { text = '', note = '', hasNote } = ctx.query || {}; const id = nanoid(); const no_at_text = clearAtInfo(text); + const pickNote = pickTagsInfo(note); + const no_tags_text = pickNote.text; const some_text = no_at_text.length > 20 ? no_at_text.slice(0, 20) : no_at_text; const hasCmd = some_text.includes('指令'); if (hasCmd) { @@ -36,6 +57,8 @@ agent ...cmd.action, payload: { text: no_at_text, + note: no_tags_text, + hasNote: hasNote || false, }, }); ctx.body = res.body || '';