/ clis / hupu / unlike.js
unlike.js
 1  import { CliError } from '@jackwener/opencli/errors';
 2  import { cli, Strategy } from '@jackwener/opencli/registry';
 3  import { postHupuJson } from './utils.js';
 4  cli({
 5      site: 'hupu',
 6      name: 'unlike',
 7      description: '取消点赞虎扑回复 (需要登录)',
 8      domain: 'bbs.hupu.com',
 9      strategy: Strategy.COOKIE, // 需要Cookie认证
10      navigateBefore: false,
11      args: [
12          {
13              name: 'tid',
14              required: true,
15              positional: true,
16              help: '帖子ID(9位数字)'
17          },
18          {
19              name: 'pid',
20              required: true,
21              positional: true,
22              help: '回复ID'
23          },
24          {
25              name: 'fid',
26              required: true,
27              help: '板块ID(如278汽车区)'
28          }
29      ],
30      columns: ['status', 'message'],
31      func: async (page, kwargs) => {
32          const { tid, pid, fid } = kwargs;
33          const url = 'https://bbs.hupu.com/pcmapi/pc/bbs/v1/reply/cancelLight';
34          // 构建请求体(与点赞相同)
35          const body = {
36              tid,
37              pid,
38              puid: '',
39              fid,
40              shumei_id: '',
41              deviceid: ''
42          };
43          try {
44              const result = await postHupuJson(page, tid, url, body, 'Unlike Hupu reply');
45              // 处理响应
46              if (result.code === 1) {
47                  return [{
48                          status: '✅ 取消点赞成功',
49                          message: ''
50                      }];
51              }
52              else if (result.code === 0 && result.msg === '你还没有点亮过这个回帖') {
53                  return [{
54                          status: '⚠️ 你还没点赞过',
55                          message: result.msg || ''
56                      }];
57              }
58              else if (result.code === 0) {
59                  return [{
60                          status: '⚠️ 操作未执行',
61                          message: result.msg || result.message || ''
62                      }];
63              }
64              else {
65                  throw new Error(`接口错误 code=${result.code}: ${result.msg || result.message}`);
66              }
67          }
68          catch (error) {
69              if (error instanceof CliError)
70                  throw error;
71              const errorMessage = error instanceof Error ? error.message : String(error);
72              throw new Error(`取消点赞失败: ${errorMessage}`);
73          }
74      },
75  });