weaver-e9-assistant-cli 1.0.0 → 1.1.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/dist/auth.js CHANGED
@@ -162,15 +162,25 @@ export async function cmdAuthStatus(cfg, args) {
162
162
  process.env.E9_NO_REAUTH = '1';
163
163
  try {
164
164
  const api = await createApiFromProfile(cfg);
165
- const r = await api.get('/api/blog/at/getAtAllList', { name: 'e9check' });
166
- const j = r?.json;
167
- const msg = String(j?.msg ?? '');
168
- if (r && r.status === 200 && j && j.status !== false)
169
- console.log(' 鉴权有效性 ✅ cookie/token 可用,能取数据');
170
- else if (r && (r.status === 401 || r.status === 403 || /登录信息超时|无效认证|E9AIAgent/.test(msg)))
171
- console.log(' 鉴权有效性 ⚠ 鉴权失效(cookie/token 已过期),需重新登录或导入');
165
+ const authFail = (j) => /登录信息超时|无效认证|认证失败|E9AIAgent/i.test(String(j?.msg ?? ''));
166
+ const probeOk = (r) => r && r.status === 200 && r.json && r.json.status !== false && !authFail(r.json);
167
+ // ① token 通道探测:aiAgentToken 头(仅当 token 存在)
168
+ if (session.data.token) {
169
+ const tr = await api.get('/api/blog/at/getAtAllList', { name: 'e9check' });
170
+ console.log(` token 通道 ${probeOk(tr) ? '✅ 有效' : '⚠ 已失效(将自动回退 cookie 通道)'}`);
171
+ }
172
+ else {
173
+ console.log(' token 通道 (未申请 aiAgentToken,纯 cookie 模式)');
174
+ }
175
+ // ② cookie 通道探测:直接带 Cookie 头请求(不依赖 token,判 errorCode 002)
176
+ const cr = await fetch(ep.baseUrl + '/api/blog/at/getAtAllList?name=e9check', {
177
+ headers: { 'Cookie': cfg.cookie, 'User-Agent': 'Mozilla/5.0', 'X-Requested-With': 'XMLHttpRequest' },
178
+ }).catch(() => null);
179
+ const cj = cr ? await cr.json().catch(() => null) : null;
180
+ if (cr && cj && cj.status !== false && !authFail(cj))
181
+ console.log(' cookie 通道 ✅ 有效');
172
182
  else
173
- console.log(` 鉴权有效性 ⚠ 响应异常 HTTP ${r?.status} msg=${msg.slice(0, 80)}`);
183
+ console.log(' cookie 通道 ⚠ 已过期(走 cookie 的接口如卡片/邮件附件/微博关注会报 errorCode 002,需 `e9 auth token-login` 刷新)');
174
184
  }
175
185
  catch (e) {
176
186
  console.log(` 鉴权有效性 ⚠ 探测请求失败:${e.message}`);
package/dist/blog.js CHANGED
@@ -331,7 +331,13 @@ export async function recallBlog(cfg, opts = {}) {
331
331
  opType,
332
332
  });
333
333
  const j = r.json || {};
334
- return { sent: true, endpoint: { baseUrl: ep.baseUrl }, blogId: opts.blogId, opType, response: r, ok: j.api_status === '1' || j.api_status === true || j.status === '1' };
334
+ // 修复 #1:实际 API 响应为 {blogDiscussVo:{...isReCalled:2}}(无 api_status/status 字段),
335
+ // 旧判断全不匹配导致「实际撤回成功但误报失败」。成功以 blogDiscussVo.isReCalled(1/2) 或 delStatus 为准。
336
+ const jr = j.blogDiscussVo ?? j;
337
+ const isRecalled = jr?.isReCalled === 1 || jr?.isReCalled === '1' || jr?.isReCalled === 2 || jr?.isReCalled === '2';
338
+ const ok = isRecalled || jr?.delStatus === '1' || jr?.delStatus === 1
339
+ || j.api_status === '1' || j.api_status === true || j.status === '1' || j.status === 1;
340
+ return { sent: true, endpoint: { baseUrl: ep.baseUrl }, blogId: opts.blogId, opType, response: r, ok };
335
341
  }
336
342
  // ─── 删除微博评论/回复 ───────────────────────────────────
337
343
  // 修复 #4 补充:E9 微博正文不可删,但评论可删。POST /api/blog/base/deleteBlogReplay。
@@ -373,11 +379,68 @@ export async function getMsgRemindList(cfg) {
373
379
  items: (j.remindList || []).map((it) => ({
374
380
  id: stringify(it.id), content: stringify(it.content),
375
381
  creator: stringify(it.creator), createDate: stringify(it.createDate),
376
- type: stringify(it.type), raw: it,
382
+ type: stringify(it.type),
383
+ // 关注申请专用字段(抓包实证):remindid=申请人 userid、relatedid=当前登录者、remindType=1
384
+ remindid: stringify(it.remindid),
385
+ relatedid: stringify(it.relatedid),
386
+ remindType: stringify(it.remindType ?? it.remindtype),
387
+ raw: it,
377
388
  })),
378
389
  raw: j,
379
390
  };
380
391
  }
392
+ // ─── 微博关注(attentionOpt + dealMsgRemind)────────────────
393
+ /**
394
+ * 发起/取消关注(抓包实证:POST /api/blog/base/attentionOpt)。
395
+ * body: attentionStatus=3(申请关注)/4(取消?) & islower=0 & userId=<目标userid> & type=(必须为空串)。
396
+ * 响应 attnInfo.attentionStatus=4 表示申请已发出,等待对方同意;1=已是好友(互关)。
397
+ * ⚠ 此接口走 cookie 通道(token 通道实测 no-op),cookie 过期时报 errorCode 002。
398
+ */
399
+ export async function attentionOpt(cfg, opts = {}) {
400
+ const ep = endpointFor(cfg);
401
+ if (!opts.send)
402
+ return { sent: false, endpoint: { baseUrl: ep.baseUrl }, userId: opts.userId, attentionStatus: opts.attentionStatus ?? 3 };
403
+ const base = ep.baseUrl.replace(/\/+$/, '');
404
+ const r = await fetch(`${base}/api/blog/base/attentionOpt`, {
405
+ method: 'POST',
406
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', Cookie: ep.cookie, 'X-Requested-With': 'XMLHttpRequest', Referer: `${base}/spa/blog/static/index.html` },
407
+ body: new URLSearchParams({
408
+ attentionStatus: String(opts.attentionStatus ?? 3),
409
+ islower: '0',
410
+ userId: String(opts.userId ?? ''),
411
+ type: '', // 必须为空串,传 '1' 会静默 no-op(抓包实证)
412
+ }).toString(),
413
+ });
414
+ let j = null;
415
+ try { j = await r.json(); } catch { j = null; }
416
+ const attnStatus = j?.attnInfo?.attentionStatus ?? j?.attentionStatus;
417
+ const ok = attnStatus === '4' || attnStatus === 4 || j?.status === '1' || j?.status === 1 || j?.api_status === true;
418
+ return { sent: true, endpoint: { baseUrl: ep.baseUrl }, userId: opts.userId, attentionStatus: opts.attentionStatus ?? 3, attnStatus, raw: j, ok };
419
+ }
420
+ /**
421
+ * 处理关注申请(同意/忽略)。抓包实证:POST /api/blog/base/dealMsgRemind。
422
+ * body: id=<提醒记录id> & relatedId=<申请人userid> & opt=1(同意)/0(忽略)。
423
+ * 提醒记录 id 从 getMsgRemindList 获取(remindid=申请人、remindType=1=关注申请)。
424
+ * ⚠ 走 cookie 通道。返回 {"status":"1"} 表示处理成功。
425
+ */
426
+ export async function dealMsgRemind(cfg, opts = {}) {
427
+ const ep = endpointFor(cfg);
428
+ if (!opts.send)
429
+ return { sent: false, endpoint: { baseUrl: ep.baseUrl }, id: opts.id, relatedId: opts.relatedId, opt: opts.opt ?? 1 };
430
+ const base = ep.baseUrl.replace(/\/+$/, '');
431
+ const r = await fetch(`${base}/api/blog/base/dealMsgRemind`, {
432
+ method: 'POST',
433
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', Cookie: ep.cookie, 'X-Requested-With': 'XMLHttpRequest', Referer: `${base}/spa/blog/static/index.html` },
434
+ body: new URLSearchParams({
435
+ id: String(opts.id ?? ''),
436
+ relatedId: String(opts.relatedId ?? ''),
437
+ opt: String(opts.opt ?? 1),
438
+ }).toString(),
439
+ });
440
+ let j = null;
441
+ try { j = await r.json(); } catch { j = null; }
442
+ return { sent: true, endpoint: { baseUrl: ep.baseUrl }, id: opts.id, relatedId: opts.relatedId, opt: opts.opt ?? 1, raw: j, ok: j?.status === '1' || j?.status === 1 };
443
+ }
381
444
  // ─── 微博默认模板 ────────────────────────────────────────
382
445
  export async function getDefaultTemplate(cfg) {
383
446
  const api = await createApiFromProfile(cfg);