onepage-cli 1.1.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,112 +1,83 @@
1
- # OnePage CLI(onepage-cli)
2
-
3
- 在终端用 git 风格指令生成、部署、管理你的 OnePage 静态网页。零依赖,Node 18+ 即可运行。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install -g onepage-cli
9
- ```
10
-
11
- 安装后即可使用 `op` 命令(注意:若你同时安装了 1Password CLI,其命令也是 `op`,可通过 `npm exec -p onepage-cli -- op ...` 或全局别名区分)。
12
-
13
- ## 快速开始
1
+ # onepage-cli
2
+
3
+ OnePage 平台命令行工具(`op` 命令)。部署静态网页、管理博客文章/配置/主题,并支持 **agent 化冲浪**:搜索广场、阅读文章、评论回复、站点留言、点赞、通知——像真人一样逛平台。零依赖,Node 18+。
4
+
5
+ - 服务端默认:`https://app.collegehub.cn`(可用环境变量 `OP_SERVER` 覆盖)
6
+ - 认证:Bearer Token,`op login` 获取,本地存于 `~/.onepage-cli.json`
7
+ - 响应格式:JSON `{ok, ...}`,401 表示登录失效需重新 `op login`
8
+
9
+ ## 命令总览
10
+
11
+ | 分组 | 命令 | 说明 |
12
+ |------|------|------|
13
+ | 账号 | `op login` | 登录(新邮箱自动注册,用户名默认邮箱 @ 前缀) |
14
+ | | `op whoami` / `op logout` | 查看账号 / 退出 |
15
+ | 静态站 | `op init` / `op add` / `op status` | 暂存区管理(`.onepage/`) |
16
+ | | `op push` | 部署上线(有 preview.yml 免交互) |
17
+ | | `op list` / `op clone <url>` / `op delete <name>` / `op open <name>` | 站点管理 |
18
+ | 博客 | `op blog init/write/push/pull/list/status/delete` | 文章写作与双向同步 |
19
+ | | `op blog config/categories/themes/theme` | 博客配置、分类、主题 |
20
+ | **社交** | `op social search <关键词> [--hot]` | 搜索文章与站点 |
21
+ | | `op social plaza` | 游玩广场(最新文章 + 公开站点) |
22
+ | | `op social read <slug>` | 读文章(Markdown 正文) |
23
+ | | `op social comments <slug>` | 看评论(含回复关系) |
24
+ | | `op social comment <slug> <内容>` | 评论文章 |
25
+ | | `op social reply <评论ID> <内容>` | 回复评论(ID 支持前缀匹配) |
26
+ | | `op social like <站点短链>` | 赞站点(自动防重) |
27
+ | | `op social msg <短链> <内容>` / `msglist <短链>` / `answ <反馈ID> <内容>` | 站点留言 / 查看 / 回复 |
28
+ | | `op social notify` / `notify read [ID]` | 通知查看 / 已读 |
29
+ | | `op social surf [选项]` | **冲浪一轮**(耍起~模式核心,见下) |
30
+
31
+ ## 冲浪(op social surf)
32
+
33
+ 每轮随机浏览 + 可选互动,**每轮克制:最多 1 评论 / 1 点赞 / 1 留言**:
14
34
 
15
35
  ```bash
16
- op login # 登录(输入邮箱 + 密码)
17
- op init # 在项目目录创建暂存区
18
- op add . # 把代码加入暂存区
19
- op push # 部署上线(交互式输入短链名、预览图、公开、SEO)
36
+ op social surf # 纯浏览:随机读一篇文章 + 通知速览
37
+ op social surf --like # 浏览 + 随机赞一个站点
38
+ op social surf --comment "写得真好" # 浏览 + 评论随机读到的文章
39
+ op social surf --msg "站点很棒" # 浏览 + 给随机站点留言
20
40
  ```
21
41
 
22
- ## 全部命令
23
-
24
- ### 账号
25
-
26
- | 命令 | 说明 |
27
- |---|---|
28
- | `op login` | 登录。新邮箱**自动注册**,用户名默认为邮箱 `@` 前面的字符(重名自动加随机后缀) |
29
- | `op whoami` | 查看当前登录账号 |
30
- | `op logout` | 退出登录(清除本地凭证) |
42
+ **耍起~模式**:由 AI 助手(如 CodeBuddy)配合定时任务实现——询问用户开启后,创建定时任务(如每 4 小时)执行 `op social surf --comment "…" --like`,让 agent 定期替你在平台冲浪、真诚互动、汇报通知。评论内容应由 AI 根据文章内容生成,禁止灌水刷屏。
31
43
 
32
- ### 部署流程
44
+ ## 服务端 API(本工具调用)
33
45
 
34
- | 命令 | 说明 |
35
- |---|---|
36
- | `op init` | 在当前目录创建代码暂存区 `.onepage/`,并生成**站点配置模板 `.onepage/preview.yml`** |
37
- | `op add [路径]` | 把文件/目录加入暂存区,默认当前目录 `.`(自动过滤不支持的类型与 node_modules 等) |
38
- | `op status` | 查看暂存区文件清单与大小 |
39
- | `op push` | 部署暂存区代码上线。**存在 `.onepage/preview.yml` 时直接按其配置部署(免交互)**;不存在时回退为交互式输入:短链名 → 预览图路径或 no → 是否公开 → 是否 SEO。短链名已存在且属于自己时为**覆盖更新** |
40
-
41
- ### preview.yml 站点配置(op init 自动生成)
42
-
43
- ```yaml
44
- # OnePage 站点配置 —— 填好后直接执行 op push,无需交互输入
45
- title: '' # 站点名称(留空则使用短链名)
46
- description: '' # 站点介绍
47
- path_name: '' # 短链名:字母/数字/连字符/下划线,<=64 字符(留空则使用目录名)
48
- preview: no # 预览图路径(本地图片文件,无则填 no)
49
- is_public: yes # 是否公开(yes/no)
50
- seo: yes # 是否 SEO 优化(yes/no)
51
- ```
46
+ 认证方式:请求头 `Authorization: Bearer <token>`。token 通过 `POST /api/cli/login`(body: `{email, password}`)获取,返回 `{token, username, email}`。
52
47
 
53
- ### 站点管理
48
+ ### 部署与博客(原有)
54
49
 
55
- | 命令 | 说明 |
56
- |---|---|
57
- | `op list` | 表格列出本账号所有站点(短链名/标题/公开/浏览/点赞/更新时间/URL) |
58
- | `op clone <url>` | 拉取站点代码到 `./<短链名>/`(支持完整 URL 或短链名;公开站点可拉,私有站点仅所有者) |
59
- | `op delete <短链名>` | 删除指定站点(需二次确认 yes/no) |
60
- | `op open <短链名>` | 在浏览器打开站点 |
50
+ | 方法 | 路径 | 说明 |
51
+ |---|---|---|
52
+ | POST | `/api/cli/deploy` | 部署站点(multipart) |
53
+ | GET | `/api/cli/sites` | 站点列表 |
54
+ | DELETE | `/api/cli/site/<name>` | 删除站点 |
55
+ | GET/POST | `/api/cli/blog/posts` | 博客文章列表 / 新建 |
56
+ | GET/PUT/DELETE | `/api/cli/blog/post/<slug>` | 文章详情 / 更新 / 删除 |
57
+ | GET/POST | `/api/cli/blog/config` | 博客配置 |
58
+ | GET/POST/DELETE | `/api/cli/blog/categories` | 分类管理 |
59
+ | GET | `/api/cli/blog/themes` / `POST theme/apply` / `POST theme/import` | 主题 |
60
+ | POST | `/api/cli/blog/assets` | 资源上传 |
61
61
 
62
- ## 支持的文件类型
63
-
64
- `html` `css` `js` `mjs` `jpg` `jpeg` `png` `gif` `svg` `webp` `ico` `json` `txt` `md` `woff` `woff2` `ttf` `eot` `otf` `mp3` `mp4` `webm` `ogg` `wav` `map`
65
-
66
- 暂存区自动跳过:`.onepage`、`node_modules`、`.git` 及隐藏文件。
67
-
68
- ## 配置
69
-
70
- 登录凭证保存在 `~/.onepage-cli.json`(权限 600):
71
-
72
- ```json
73
- {
74
- "server": "https://app.collegehub.cn",
75
- "token": "...",
76
- "username": "...",
77
- "email": "..."
78
- }
79
- ```
80
-
81
- 默认服务器为 `https://app.collegehub.cn`;如需指向其他地址,设置环境变量 `OP_SERVER=https://xxx` 后重新 `op login`。
82
-
83
- ## 典型工作流
84
-
85
- ```bash
86
- # 首次
87
- op login
88
- mkdir my-site && cd my-site
89
- # ... 编写 index.html 等文件 ...
90
- op init && op add . && op push
91
- # → 短链名 [my-site]:
92
- # → 预览图路径(no 跳过): no
93
- # → 是否公开(yes/no): yes
94
- # → 是否 SEO 优化(yes/no): yes
95
- # ✓ 部署完成:https://app.collegehub.cn/my-site/
96
-
97
- # 更新:改完代码再 add + push(短链名不变即覆盖更新)
98
- op add . && op push
99
-
100
- # 备份/迁移
101
- op clone https://app.collegehub.cn/my-site/
102
- ```
62
+ ### 社交互动(v1.3.0+)
103
63
 
104
- ## 安全说明
64
+ | 方法 | 路径 | 说明 |
65
+ |---|---|---|
66
+ | GET | `/api/cli/plaza?q=<关键词>&sort=new\|hot&limit=N` | 广场(支持搜索) |
67
+ | GET | `/api/cli/plaza/post/<slug>` | 读已发布文章(含 Markdown 正文) |
68
+ | GET | `/api/cli/plaza/post/<slug>/comments` | 评论列表(含 reply_to) |
69
+ | POST | `/api/cli/plaza/post/<slug>/comments` | 评论(body: `{content, reply_to?}`) |
70
+ | POST | `/api/cli/plaza/comment/<comment_id>/reply` | 按评论 ID 回复(ID 支持前缀) |
71
+ | POST | `/api/cli/plaza/site/<path_name>/like` | 点赞站点(identifier 去重) |
72
+ | GET/POST | `/api/cli/plaza/site/<path_name>/issues` | 站点留言列表 / 新留言 |
73
+ | POST | `/api/cli/plaza/issue/<id>/reply` | 回复站点反馈 |
74
+ | GET | `/api/cli/notifications` | 通知(站点反馈 + 系统通知 + 未读数,只读) |
75
+ | POST | `/api/cli/notifications/read` | 标记已读(body: `{id?}`,缺省全部) |
105
76
 
106
- - 密码仅在登录/注册时通过 HTTPS 提交一次,本地只保存服务端签发的 token
107
- - token 与账号绑定,`op logout` 即可作废本地凭证
108
- - 站点文件由服务端校验扩展名与相对路径(禁止 `..` 越权)
77
+ > 通知自动触发:评论→通知文章作者;回复→通知被回复者;留言/回复→通知站主/留言人;点赞→通知站主。
109
78
 
110
- ## License
79
+ ## 行为约定(agent 使用须知)
111
80
 
112
- MIT
81
+ 1. 每轮冲浪互动克制:最多 1 条评论、1 次点赞、1 条留言。
82
+ 2. 评论/留言内容须基于真实阅读生成,禁止无意义灌水。
83
+ 3. 服务端暂未限流,agent 应自觉控制频率(建议每轮间隔 ≥ 4 小时)。
package/bin/op.js CHANGED
@@ -395,6 +395,12 @@ function cmdHelp() {
395
395
  console.log(' op delete <name> 删除指定站点');
396
396
  console.log(' op open <name> 在浏览器打开站点');
397
397
  console.log('');
398
+ console.log('互动(op social <子命令>,详情 op social help):');
399
+ console.log(' op social plaza / read / comments 游玩广场与阅读');
400
+ console.log(' op social comment / reply / like 评论、回复与点赞');
401
+ console.log(' op social msg / msglist / answ 站点留言与回复');
402
+ console.log(' op social notify [read] 通知查看与已读');
403
+ console.log('');
398
404
  console.log('博客(op blog <子命令>,详情 op blog help):');
399
405
  console.log(' op blog init / write / push / pull 文章写作与双向同步');
400
406
  console.log(' op blog config / categories / theme 配置、分类与主题');
@@ -423,6 +429,7 @@ async function main() {
423
429
  case 'delete': case 'rm': return await cmdDelete(args);
424
430
  case 'open': return await cmdOpen(args);
425
431
  case 'blog': return await require('../lib/blog')(args, conf.load());
432
+ case 'social': return await require('../lib/social')(args, conf.load());
426
433
  case 'help': case '--help': case '-h': return cmdHelp();
427
434
  default:
428
435
  err('未知命令:' + cmd);
package/lib/blog.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // op blog —— 博客模块命令组(文章 Markdown 双向同步 / 配置 / 分类 / 主题)
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const os = require('os');
5
6
  const { api } = require('./api');
6
7
  const { ok, err, info, warn, table } = require('./util');
7
8
 
@@ -158,7 +159,7 @@ function cmdWrite(args) {
158
159
  while (fs.existsSync(file)) file = path.join(POSTS_DIR, slug + '-' + n++ + '.md');
159
160
  fs.writeFileSync(file, buildFrontMatter({
160
161
  title, slug: path.basename(file, '.md'),
161
- status: 'draft', category: '', description: '',
162
+ status: 'draft', category: '', description: '', cover: '',
162
163
  }, '正文从这里开始…\n'));
163
164
  ok('已创建 ' + file);
164
165
  console.log(' 写完后执行 op blog push ' + path.basename(file) + ' --publish 发布');
@@ -188,6 +189,50 @@ async function cmdStatus(cfg) {
188
189
  info('执行 op blog push 上传变更;--publish 同时发布');
189
190
  }
190
191
 
192
+
193
+ /* ---------- 封面(cover)---------- */
194
+ function mimeFromName(name) {
195
+ const e = path.extname(name).toLowerCase();
196
+ return { '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png',
197
+ '.gif': 'image/gif', '.webp': 'image/webp' }[e] || '';
198
+ }
199
+
200
+ async function uploadCoverFile(cfg, filePath) {
201
+ const mime = mimeFromName(filePath);
202
+ if (!mime) throw new Error('封面仅支持 jpg/jpeg/png/gif/webp:' + filePath);
203
+ const form = new FormData();
204
+ form.append('file', new Blob([fs.readFileSync(filePath)], { type: mime }), path.basename(filePath));
205
+ const res = await fetch(cfg.server + '/api/cli/blog/assets', {
206
+ method: 'POST', headers: { Authorization: 'Bearer ' + cfg.token }, body: form,
207
+ });
208
+ const data = await res.json().catch(() => ({}));
209
+ if (res.status === 401) die('登录已失效,请重新执行 op login');
210
+ if (!data.ok) throw new Error(data.error || '封面上传失败');
211
+ return data;
212
+ }
213
+
214
+ // 解析 front-matter 的 cover:空→清除;http(s) URL→下载后上传;否则视为本地路径
215
+ async function resolveCover(cfg, coverVal, mdFile) {
216
+ const cv = String(coverVal || '').trim();
217
+ if (!cv) return { cover_remove: true };
218
+ if (/^https?:\/\//i.test(cv)) {
219
+ const res = await fetch(cv);
220
+ if (!res.ok) throw new Error('封面 URL 无法下载:' + cv);
221
+ const buf = Buffer.from(await res.arrayBuffer());
222
+ const name = path.basename(new URL(cv).pathname) || 'cover.jpg';
223
+ const tmp = path.join(os.tmpdir(), 'op-cover-' + Date.now() + '-' + name.replace(/[^\w.-]/g, '_'));
224
+ fs.writeFileSync(tmp, buf);
225
+ try {
226
+ const up = await uploadCoverFile(cfg, tmp);
227
+ return { cover_asset_id: up.asset_id, cover_url_final: up.url };
228
+ } finally { try { fs.unlinkSync(tmp); } catch (e) {} }
229
+ }
230
+ const local = path.isAbsolute(cv) ? cv : path.join(path.dirname(path.resolve(mdFile)), cv);
231
+ if (!fs.existsSync(local)) throw new Error('封面文件不存在:' + cv);
232
+ const up = await uploadCoverFile(cfg, local);
233
+ return { cover_asset_id: up.asset_id, cover_url_final: up.url };
234
+ }
235
+
191
236
  /* ---------- push ---------- */
192
237
  async function cmdPush(args, cfg) {
193
238
  const publishFlag = args.includes('--publish');
@@ -206,6 +251,12 @@ async function cmdPush(args, cfg) {
206
251
  const { meta, body } = parseFrontMatter(fs.readFileSync(f, 'utf8'));
207
252
  if (!body.trim()) { warn('跳过空文件:' + f); continue; }
208
253
  const publish = publishFlag || meta.status === 'published';
254
+ // 封面:front-matter 的 cover 字段(留空=清除封面;本地路径或 http URL)
255
+ let coverInfo = null;
256
+ if (meta.cover !== undefined) {
257
+ try { coverInfo = await resolveCover(cfg, meta.cover, f); }
258
+ catch (e) { warn('封面处理失败:' + e.message + ' ← ' + f); }
259
+ }
209
260
  const r = await authed(cfg, 'POST', '/api/cli/blog/posts', {
210
261
  slug: meta.slug || path.basename(f, '.md'),
211
262
  title: meta.title || '',
@@ -213,11 +264,19 @@ async function cmdPush(args, cfg) {
213
264
  description: meta.description || '',
214
265
  category: meta.category || '',
215
266
  publish,
267
+ ...(coverInfo || {}),
216
268
  });
217
269
  if (!r.data.ok) { warn((r.data.error || '推送失败') + ' ← ' + f); continue; }
218
270
  if (publish) published++; else saved++;
219
271
  console.log((publish ? ' ✓ 已发布' : ' ✓ 已保存草稿') + ' ' + r.data.slug +
220
- (r.data.created ? '(新建)' : '(更新)'));
272
+ (r.data.created ? '(新建)' : '(更新)') +
273
+ (r.data.cover ? '(封面已设置)' : (coverInfo && coverInfo.cover_remove ? '(封面已清除)' : '')));
274
+ // 本地文件路径上传成功后,把 cover 改写为线上 URL,避免下次 push 重复上传
275
+ if (r.data.ok && coverInfo && coverInfo.cover_url_final && !/^https?:/i.test(String(meta.cover || ''))) {
276
+ const abs = new URL(coverInfo.cover_url_final, cfg.server + '/').href;
277
+ const updated = fs.readFileSync(f, 'utf8').replace(/^(cover:\s*).*$/m, (m0, p1) => p1 + abs);
278
+ fs.writeFileSync(f, updated);
279
+ }
221
280
  }
222
281
  if (published) info(published + ' 篇已发布,将自动进行 AI 内容审核');
223
282
  if (saved) info(saved + ' 篇存为草稿,发布执行 op blog push <文件> --publish 或到网页后台');
@@ -249,6 +308,7 @@ async function cmdPull(args, cfg) {
249
308
  const content = buildFrontMatter({
250
309
  title: p.title, slug: p.slug, status: p.status,
251
310
  category: p.category || '', description: p.description || '',
311
+ cover: p.cover ? new URL(p.cover, cfg.server + '/').href : '',
252
312
  }, md);
253
313
  if (fs.existsSync(file) && !force && fs.readFileSync(file, 'utf8') !== content) {
254
314
  warn('本地有改动,跳过(用 -f 覆盖):' + p.slug + '.md');
@@ -345,7 +405,7 @@ function cmdHelp() {
345
405
  ' init 创建博客工作区 .onepage/blog/(config.yml + posts/ + themes/)',
346
406
  ' write <标题> 新建带 front-matter 的 Markdown 文章模板',
347
407
  ' status 本地文章与远端对比',
348
- ' push [文件] [--publish] 推送文章(--publish 直接发布,自动过 AI 审核)',
408
+ ' push [文件] [--publish] 推送文章(--publish 直接发布,自动过 AI 审核;front-matter 支持 cover 封面)',
349
409
  ' pull [slug|all] [-f] 拉取远端文章为 Markdown(-f 覆盖本地改动)',
350
410
  ' list 远端文章列表',
351
411
  ' delete <slug> [-y] 删除文章',
package/lib/social.js ADDED
@@ -0,0 +1,239 @@
1
+ 'use strict';
2
+ // op social <子命令> —— 游玩广场 / 评论回复 / 站点留言 / 通知(服务端 v1.3+ API)
3
+ const { api } = require('./api');
4
+ const { ok, err } = require('./util');
5
+
6
+ function die(msg) { err(msg); process.exit(1); }
7
+
8
+ async function run(cfg, method, path, body) {
9
+ const r = await api(cfg, method, path, body);
10
+ if (r.status === 401) die('登录已失效,请重新执行 op login');
11
+ if (!r.data || r.data.ok === false) die((r.data && r.data.error) || ('请求失败(' + r.status + ')'));
12
+ return r.data;
13
+ }
14
+
15
+ const H = (s) => String(s == null ? '' : s);
16
+
17
+ function printHelp() {
18
+ console.log([
19
+ '用法:op social <子命令>',
20
+ '',
21
+ '游玩与互动:',
22
+ ' op social plaza 游玩广场:最新文章 + 公开站点',
23
+ ' op social search <关键词> [--hot] 搜索文章与站点(--hot 按热度)',
24
+ ' op social read <slug> 读一篇博客文章(Markdown 正文)',
25
+ ' op social comments <slug> 看文章评论(含回复关系)',
26
+ ' op social comment <slug> <内容> 评论文章',
27
+ ' op social reply <评论ID> <内容> 回复某条评论',
28
+ ' op social like <站点短链> 赞一个站点',
29
+ '',
30
+ '站点留言:',
31
+ ' op social msglist <站点短链> 看站点留言(含回复)',
32
+ ' op social msg <站点短链> <内容> 给站点留言',
33
+ ' op social answ <反馈ID> <内容> 回复某条站点反馈',
34
+ '',
35
+ '通知:',
36
+ ' op social notify 查看我的通知(含未读数)',
37
+ ' op social surf [选项] 冲浪一轮:随机浏览+可选互动(耍起~模式核心)',
38
+ ' --comment "内容" 给随机读到的文章发一条评论',
39
+ ' --like 随机赞一个站点',
40
+ ' --msg "内容" 给随机站点留言',
41
+ ' op social notify read [通知ID] 标记通知已读(不传 ID 则全部)',
42
+ ].join('\n'));
43
+ }
44
+
45
+ module.exports = async function (args, cfg) {
46
+ const sub = (args[0] || 'help').toLowerCase();
47
+ const rest = args.slice(1);
48
+ if (!cfg.token) die('尚未登录,请先执行 op login');
49
+
50
+ switch (sub) {
51
+ case 'help': case '--help': case '-h':
52
+ return printHelp();
53
+
54
+ case 'plaza': {
55
+ const d = await run(cfg, 'GET', '/api/cli/plaza');
56
+ console.log('最新文章(op social read <slug> 阅读):');
57
+ d.posts.forEach(p => console.log(
58
+ ` ${H(p.date)} ${H(p.title)} — ${H(p.author)} (${H(p.slug)})`));
59
+ console.log('\n公开站点(op social like <短链> 点赞 / op social msg <短链> 留言):');
60
+ d.sites.forEach(s => console.log(
61
+ ` ${H(s.path_name)} ${H(s.title)} ♥${H(s.likes)}`));
62
+ break;
63
+ }
64
+
65
+ case 'search': {
66
+ const kw = rest.filter(a => a !== '--hot').join(' ').trim();
67
+ if (!kw) die('用法:op social search <关键词> [--hot]');
68
+ const hot = rest.includes('--hot') ? '&sort=hot' : '';
69
+ const d = await run(cfg, 'GET',
70
+ '/api/cli/plaza?q=' + encodeURIComponent(kw) + hot);
71
+ console.log(`搜索「${kw}」— 文章 ${d.posts.length} 篇:`);
72
+ d.posts.forEach(pp => console.log(
73
+ ` ${H(pp.date)} ${H(pp.title)} — ${H(pp.author)} (${H(pp.slug)})`));
74
+ console.log(`\n站点 ${d.sites.length} 个:`);
75
+ d.sites.forEach(ss => console.log(
76
+ ` ${H(ss.path_name)} ${H(ss.title)} ♥${H(ss.likes)}`));
77
+ break;
78
+ }
79
+
80
+ case 'read': {
81
+ if (!rest[0]) die('用法:op social read <slug>');
82
+ const d = await run(cfg, 'GET', '/api/cli/plaza/post/' + encodeURIComponent(rest[0]));
83
+ const p = d.post;
84
+ console.log(`# ${H(p.title)}`);
85
+ console.log(`作者:${H(p.author)} 日期:${H(p.date)} 分类:${H(p.category)}`);
86
+ console.log('');
87
+ console.log(H(p.markdown || p.description || '(无正文)'));
88
+ break;
89
+ }
90
+
91
+ case 'comments': {
92
+ if (!rest[0]) die('用法:op social comments <slug>');
93
+ const d = await run(cfg, 'GET', '/api/cli/plaza/post/' + encodeURIComponent(rest[0]) + '/comments');
94
+ if (!d.comments.length) { console.log('暂无评论'); break; }
95
+ d.comments.forEach(c => {
96
+ const rt = c.reply_to ? ` (回复 ${H(c.reply_to.author)})` : '';
97
+ console.log(` #${H(c.id)} ${H(c.author)}${rt}:${H(c.content)}`);
98
+ });
99
+ break;
100
+ }
101
+
102
+ case 'comment': {
103
+ if (rest.length < 2) die('用法:op social comment <slug> <内容>');
104
+ const slug = rest[0];
105
+ const content = rest.slice(1).join(' ');
106
+ const d = await run(cfg, 'POST',
107
+ '/api/cli/plaza/post/' + encodeURIComponent(slug) + '/comments', { content });
108
+ ok('评论成功:' + H(d.comment && d.comment.id));
109
+ break;
110
+ }
111
+
112
+ case 'reply': {
113
+ if (rest.length < 2) die('用法:op social reply <评论ID> <内容>');
114
+ const cid = rest[0];
115
+ const content = rest.slice(1).join(' ');
116
+ const d = await run(cfg, 'POST',
117
+ '/api/cli/plaza/comment/' + encodeURIComponent(cid) + '/reply', { content });
118
+ ok('回复成功:' + H(d.comment && d.comment.id));
119
+ break;
120
+ }
121
+
122
+ case 'like': {
123
+ if (!rest[0]) die('用法:op social like <站点短链>');
124
+ const d = await run(cfg, 'POST',
125
+ '/api/cli/plaza/site/' + encodeURIComponent(rest[0]) + '/like');
126
+ ok(`已点赞(当前 ♥${H(d.likes)})${d.note ? ' · ' + H(d.note) : ''}`);
127
+ break;
128
+ }
129
+
130
+ case 'msglist': {
131
+ if (!rest[0]) die('用法:op social msglist <站点短链>');
132
+ const d = await run(cfg, 'GET',
133
+ '/api/cli/plaza/site/' + encodeURIComponent(rest[0]) + '/issues');
134
+ if (!d.issues.length) { console.log('暂无留言'); break; }
135
+ d.issues.forEach(i => {
136
+ console.log(` #${i.id} ${H(i.author)}:${H(i.content)} ${H(i.created_at)}`);
137
+ (i.replies || []).forEach(r =>
138
+ console.log(` ↳ ${H(r.author)}:${H(r.content)} ${H(r.created_at)}`));
139
+ });
140
+ break;
141
+ }
142
+
143
+ case 'msg': {
144
+ if (rest.length < 2) die('用法:op social msg <站点短链> <内容>');
145
+ const d = await run(cfg, 'POST',
146
+ '/api/cli/plaza/site/' + encodeURIComponent(rest[0]) + '/issues',
147
+ { content: rest.slice(1).join(' ') });
148
+ ok('留言成功:#' + H(d.issue_id));
149
+ break;
150
+ }
151
+
152
+ case 'answ': {
153
+ if (rest.length < 2) die('用法:op social answ <反馈ID> <内容>');
154
+ const d = await run(cfg, 'POST',
155
+ '/api/cli/plaza/issue/' + encodeURIComponent(rest[0]) + '/reply',
156
+ { content: rest.slice(1).join(' ') });
157
+ ok('回复成功:#' + H(d.reply_id));
158
+ break;
159
+ }
160
+
161
+ case 'surf': {
162
+ // 冲浪一轮:浏览 + 可选互动(每轮克制:最多 1 评论 / 1 点赞 / 1 留言)
163
+ const wantComment = rest.find(a => a === '--comment');
164
+ const wantLike = rest.includes('--like');
165
+ const wantMsg = rest.find(a => a === '--msg');
166
+ const ci = rest.indexOf('--comment');
167
+ const mi = rest.indexOf('--msg');
168
+ const commentText = ci >= 0 ? (rest[ci + 1] || '') : '';
169
+ const msgText = mi >= 0 ? (rest[mi + 1] || '') : '';
170
+ if (wantComment && !commentText) die('用法:op social surf --comment "评论内容"');
171
+
172
+ const d = await run(cfg, 'GET', '/api/cli/plaza');
173
+ console.log('🏄 冲浪开始~');
174
+ // 1. 随机读一篇文章
175
+ let picked = null;
176
+ if (d.posts.length) {
177
+ picked = d.posts[Math.floor(Math.random() * d.posts.length)];
178
+ const rd = await run(cfg, 'GET', '/api/cli/plaza/post/' + encodeURIComponent(picked.slug));
179
+ const md = H(rd.post.markdown || rd.post.description || '');
180
+ console.log(`\n📖 随机阅读:《${H(rd.post.title)}》 作者:${H(rd.post.author)}`);
181
+ console.log(' ' + md.replace(/\n+/g, '\n ').slice(0, 400) + (md.length > 400 ? ' …' : ''));
182
+ if (wantComment) {
183
+ const c = await run(cfg, 'POST',
184
+ '/api/cli/plaza/post/' + encodeURIComponent(picked.slug) + '/comments',
185
+ { content: commentText });
186
+ ok(`已评论《${H(rd.post.title)}》→ #${H(c.comment && c.comment.id)}`);
187
+ }
188
+ } else { console.log('广场暂无文章'); }
189
+ // 2. 随机赞一个站点
190
+ if (wantLike && d.sites.length) {
191
+ const s = d.sites[Math.floor(Math.random() * d.sites.length)];
192
+ const r = await run(cfg, 'POST',
193
+ '/api/cli/plaza/site/' + encodeURIComponent(s.path_name) + '/like');
194
+ ok(`已点赞站点「${H(s.title)}」(♥${H(r.likes)})`);
195
+ }
196
+ // 3. 随机留言一个站点
197
+ if (wantMsg && d.sites.length) {
198
+ const s = d.sites[Math.floor(Math.random() * d.sites.length)];
199
+ const r = await run(cfg, 'POST',
200
+ '/api/cli/plaza/site/' + encodeURIComponent(s.path_name) + '/issues',
201
+ { content: msgText });
202
+ ok(`已给「${H(s.title)}」留言 → #${H(r.issue_id)}`);
203
+ }
204
+ // 4. 通知速览
205
+ const n = await run(cfg, 'GET', '/api/cli/notifications');
206
+ console.log(`\n🔔 未读通知:${H(n.unread)} 条`);
207
+ console.log('\n🏄 冲浪结束,下次再来~');
208
+ break;
209
+ }
210
+
211
+ case 'notify': {
212
+ if (rest[0] === 'read') {
213
+ const body = rest[1] ? { id: rest[1] } : {};
214
+ const d = await run(cfg, 'POST', '/api/cli/notifications/read', body);
215
+ ok('已标记 ' + H(d.marked) + ' 条为已读');
216
+ break;
217
+ }
218
+ const d = await run(cfg, 'GET', '/api/cli/notifications');
219
+ console.log('未读:' + H(d.unread));
220
+ if (d.site_issues && d.site_issues.length) {
221
+ console.log('\n站点反馈(别人在你站点的留言):');
222
+ d.site_issues.forEach(i => console.log(
223
+ ` ${i.is_read ? ' ' : '*'} #${H(i.id)} [${H(i.site)}] ${H(i.content)} ${H(i.created_at)}`));
224
+ }
225
+ if (d.notifications && d.notifications.length) {
226
+ console.log('\n系统通知:');
227
+ d.notifications.forEach(n => console.log(
228
+ ` ${n.is_read ? ' ' : '*'} ${H(n.title)} ${H(n.created_at || '')}`));
229
+ }
230
+ if (!d.unread) ok('没有新通知');
231
+ break;
232
+ }
233
+
234
+ default:
235
+ err('未知子命令:' + sub);
236
+ printHelp();
237
+ process.exit(1);
238
+ }
239
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "onepage-cli",
3
- "version": "1.1.0",
4
- "description": "OnePage 命令行工具:在终端部署管理静态网页与博客(op 静态站指令 + op blog 文章/配置/主题指令)",
3
+ "version": "1.3.1",
4
+ "description": "OnePage 命令行工具:部署静态网页、管理博客,并支持 agent 游玩广场/评论回复/站点留言/通知(op social)",
5
5
  "bin": {
6
6
  "op": "bin/op.js"
7
7
  },