@iflyrpa/actions 4.0.0-beta.2 → 4.0.0-beta.6

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/index.js CHANGED
@@ -5489,7 +5489,7 @@ var __webpack_exports__ = {};
5489
5489
  });
5490
5490
  const package_json_namespaceObject = require("@iflyrpa/share/package.json");
5491
5491
  var package_json_default = /*#__PURE__*/ __webpack_require__.n(package_json_namespaceObject);
5492
- var package_namespaceObject = JSON.parse('{"i8":"4.0.0-beta.1"}');
5492
+ var package_namespaceObject = JSON.parse('{"i8":"4.0.0-beta.5"}');
5493
5493
  const share_namespaceObject = require("@iflyrpa/share");
5494
5494
  const external_node_fs_namespaceObject = require("node:fs");
5495
5495
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
@@ -5594,6 +5594,13 @@ var __webpack_exports__ = {};
5594
5594
  }
5595
5595
  };
5596
5596
  if (foundError) Object.assign(errorResponse, foundError);
5597
+ if (error.response?.status === 403) {
5598
+ this.logger?.warn(`[403 详细信息] URL: ${error.config?.url}`);
5599
+ this.logger?.warn(`[403 响应头] ${JSON.stringify(error.response?.headers || {})}`);
5600
+ this.logger?.warn(`[403 响应体] ${JSON.stringify(error.response?.data || null)}`);
5601
+ const verifyDecision = error.response?.headers?.["x-tt-verify-passport-decision"];
5602
+ if (verifyDecision) this.logger?.warn(`[403 验证决策] x-tt-verify-passport-decision: ${verifyDecision}`);
5603
+ }
5597
5604
  if (error.response?.data) {
5598
5605
  if ("object" == typeof error.response.data) {
5599
5606
  const serverError = error.response.data;
@@ -14483,21 +14490,13 @@ var __webpack_exports__ = {};
14483
14490
  console.log("拦截器收到响应:", JSON.stringify(response.data));
14484
14491
  task.logger.info(`拦截器收到响应response.headers: ${JSON.stringify(response.headers)} `);
14485
14492
  task.logger.info(`拦截器收到响应response.data: ${JSON.stringify(response.data)} `);
14486
- task.logger.info(`拦截器收到响应response.data类型: ${typeof response.data}, 值: ${JSON.stringify(response.data)}`);
14487
14493
  decision = parseVerifyPassportDecision(response.headers["x-tt-verify-passport-decision"]);
14488
- task.logger.info(`解析后的decision: ${JSON.stringify(decision)}`);
14489
14494
  if (needsVerification(decision)) {
14490
- task.logger.info(`检测到需要验证,decision.account_flow: ${decision?.account_flow}`);
14491
- task.logger.info("拦截器即将return,不抛错");
14492
- return;
14493
- }
14494
- task.logger.info("不需要验证,继续检查response.data");
14495
- if (!response || !response.data) {
14496
- task.logger.info("response或response.data为空,拦截器return");
14495
+ task.logger.info(`需要验证: ${JSON.stringify(decision)}`);
14497
14496
  return;
14498
14497
  }
14498
+ if (!response || !response.data) return;
14499
14499
  const responseData = response.data;
14500
- task.logger.info(`responseData.status_code: ${responseData?.status_code}`);
14501
14500
  if (response && responseData?.status_code && 0 !== responseData.status_code) {
14502
14501
  const errorCode = 4 === responseData.status_code ? 500 : responseData.status_code;
14503
14502
  if (4 === responseData.status_code) task.logger.warn(`抖音服务器错误 status_code: 4,映射为 500 触发重试。原始响应: ${JSON.stringify(responseData)}`);
@@ -14594,9 +14593,33 @@ var __webpack_exports__ = {};
14594
14593
  retryDelay: 2000
14595
14594
  });
14596
14595
  task.logger.info("========== api调用完成 ==========");
14597
- task.logger.info(`publishResult类型: ${typeof publishResult}, 值: ${JSON.stringify(publishResult)}`);
14598
- task.logger.info(`decision值: ${JSON.stringify(decision)}`);
14599
- task.logger.info(`needsVerification(decision): ${needsVerification(decision)}`);
14596
+ task.logger.info(`decision值: ${JSON.stringify(decision)}, needsVerification(decision): ${needsVerification(decision)}`);
14597
+ if (needsVerification(decision)) {
14598
+ const details = [
14599
+ publishResult.status_msg,
14600
+ decision?.verify_title,
14601
+ decision?.verify_desc
14602
+ ].filter(Boolean).join(" ");
14603
+ const message = `图文发布失败,原因:${details}${task.debug ? ` ${http.proxyInfo}` : ""}`;
14604
+ task.logger.warn(`TaskId:${task.taskId},检测到需要验证,准备返回验证信息`);
14605
+ let decisionObj = {};
14606
+ if (decision) decisionObj = decision;
14607
+ const mockData = {
14608
+ state: share_namespaceObject.TaskState.FAILED,
14609
+ error: message,
14610
+ result: {
14611
+ ...decisionObj,
14612
+ data: decision,
14613
+ uploadedImgList: JSON.stringify(publishData.item.common.images)
14614
+ }
14615
+ };
14616
+ await updateTaskState?.(mockData);
14617
+ return {
14618
+ code: 0,
14619
+ data: mockData,
14620
+ message: "操作成功"
14621
+ };
14622
+ }
14600
14623
  task.logger.info("不需要验证,继续正常流程");
14601
14624
  reportLogger({
14602
14625
  token: params.huiwenToken || "",
@@ -14615,10 +14638,13 @@ var __webpack_exports__ = {};
14615
14638
  const message = `图文发布${isSuccess ? "成功" : `失败,原因:${publishResult.status_msg} ${decision?.verify_title} ${decision?.verify_desc}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
14616
14639
  const data = isSuccess ? publishResult.item_id || "" : "";
14617
14640
  if (!isSuccess) {
14641
+ let decisionObj = {};
14642
+ if (decision) decisionObj = decision;
14618
14643
  await updateTaskState?.({
14619
14644
  state: share_namespaceObject.TaskState.FAILED,
14620
14645
  error: message,
14621
14646
  result: {
14647
+ ...decisionObj,
14622
14648
  data: decision,
14623
14649
  uploadedImgList: JSON.stringify(publishData.item.common.images)
14624
14650
  }
@@ -15293,15 +15319,41 @@ var __webpack_exports__ = {};
15293
15319
  }
15294
15320
  task.logger?.info("准备发布...");
15295
15321
  await page.waitForTimeout(1000);
15296
- const response = await new Promise((resolve, reject)=>{
15322
+ const result = await new Promise((resolve, reject)=>{
15297
15323
  const handleResponse = async (res)=>{
15298
15324
  if (res.url().includes("/web/api/media/aweme/create_v2")) {
15299
15325
  task.logger?.info("匹配到发布接口响应");
15326
+ let decision = null;
15327
+ try {
15328
+ const headers = await res.allHeaders();
15329
+ decision = parseVerifyPassportDecision(headers["x-tt-verify-passport-decision"]);
15330
+ } catch (error) {
15331
+ task.logger?.warn(`解析验证决策头失败: ${error}`);
15332
+ }
15300
15333
  const jsonResponse = await res.json();
15301
15334
  task.logger?.info(`发布接口响应数据: ${JSON.stringify(jsonResponse)}`);
15302
15335
  page.off("response", handleResponse);
15303
- if (jsonResponse?.status_code === 0) resolve(jsonResponse?.data?.item_id || jsonResponse?.item_id || "");
15304
- else reject(new Error(jsonResponse?.status_msg || "发布失败"));
15336
+ if (needsVerification(decision)) {
15337
+ task.logger?.warn("检测到需要二次验证,文章未真正发布");
15338
+ resolve({
15339
+ itemId: "",
15340
+ decision
15341
+ });
15342
+ return;
15343
+ }
15344
+ if (jsonResponse?.status_code !== 0) {
15345
+ reject(new Error(jsonResponse?.status_msg || "发布失败"));
15346
+ return;
15347
+ }
15348
+ const itemId = jsonResponse?.data?.item_id || jsonResponse?.item_id || "";
15349
+ if (!itemId) {
15350
+ reject(new Error(jsonResponse?.status_msg || "发布异常:未返回作品ID,文章可能未真正发布"));
15351
+ return;
15352
+ }
15353
+ resolve({
15354
+ itemId,
15355
+ decision: null
15356
+ });
15305
15357
  }
15306
15358
  };
15307
15359
  page.on("response", handleResponse);
@@ -15323,20 +15375,42 @@ var __webpack_exports__ = {};
15323
15375
  await page.close();
15324
15376
  return null;
15325
15377
  });
15326
- if (!response && "" !== response) return {
15378
+ if (!result) return {
15327
15379
  code: 414,
15328
15380
  message: "发布失败",
15329
15381
  data: ""
15330
15382
  };
15331
- task.logger?.info(`✓ 发布成功,item_id: ${response}`);
15383
+ if (needsVerification(result.decision)) {
15384
+ const decision = result.decision;
15385
+ const details = [
15386
+ decision?.verify_title,
15387
+ decision?.verify_desc
15388
+ ].filter(Boolean).join(" ");
15389
+ const message = `发布失败,需要二次验证${details ? `:${details}` : ""}`;
15390
+ task.logger?.warn(message);
15391
+ await updateTaskState?.({
15392
+ state: share_namespaceObject.TaskState.FAILED,
15393
+ error: message,
15394
+ result: {
15395
+ data: decision
15396
+ }
15397
+ });
15398
+ await page.close();
15399
+ return {
15400
+ code: 414,
15401
+ message,
15402
+ data: ""
15403
+ };
15404
+ }
15405
+ task.logger?.info(`✓ 发布成功,item_id: ${result.itemId}`);
15332
15406
  await updateTaskState?.({
15333
15407
  state: share_namespaceObject.TaskState.SUCCESS,
15334
15408
  result: {
15335
- response
15409
+ response: result.itemId
15336
15410
  }
15337
15411
  });
15338
15412
  await page.close();
15339
- return (0, share_namespaceObject.success)(response);
15413
+ return (0, share_namespaceObject.success)(result.itemId);
15340
15414
  };
15341
15415
  const DouyinPublishParamsSchema = ActionCommonParamsSchema.extend({
15342
15416
  title: schemas_string(),
@@ -16116,26 +16190,26 @@ var __webpack_exports__ = {};
16116
16190
  const http = new Http({
16117
16191
  headers: {
16118
16192
  cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
16119
- referer: "https://mp.toutiao.com/profile_v4/graphic/publish"
16193
+ referer: "https://mp.toutiao.com/profile_v4/graphic/publish",
16194
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
16195
+ }
16196
+ });
16197
+ const totalData = await http.api({
16198
+ method: "get",
16199
+ url: "https://mp.toutiao.com/mp/fe_api/home/merge_v2",
16200
+ params: {
16201
+ app_id: 1231
16202
+ }
16203
+ });
16204
+ await new Promise((r)=>setTimeout(r, 1000));
16205
+ const contentDataYesterday = await http.api({
16206
+ method: "get",
16207
+ url: "https://mp.toutiao.com/mp/agw/statistic/v2/content_stat",
16208
+ params: {
16209
+ type: 0,
16210
+ app_id: 1231
16120
16211
  }
16121
16212
  });
16122
- const [totalData, contentDataYesterday] = await Promise.all([
16123
- http.api({
16124
- method: "get",
16125
- url: "https://mp.toutiao.com/mp/fe_api/home/merge_v2",
16126
- params: {
16127
- app_id: 1231
16128
- }
16129
- }),
16130
- http.api({
16131
- method: "get",
16132
- url: "https://mp.toutiao.com/mp/agw/statistic/v2/content_stat",
16133
- params: {
16134
- type: 0,
16135
- app_id: 1231
16136
- }
16137
- })
16138
- ]);
16139
16213
  const isSuccess = !!(totalData?.data?.statistic && contentDataYesterday?.author_stat);
16140
16214
  if (!isSuccess || !totalData?.data || !contentDataYesterday?.author_stat) return types_errorResponse(totalData?.message || contentDataYesterday?.message || "头条号数据获取失败,请检查Cookie是否有效", 414);
16141
16215
  const ttData = {
@@ -20312,8 +20386,10 @@ var __webpack_exports__ = {};
20312
20386
  tuwen_wtt_trans_flag: params.settingInfo?.toutiaoTransWtt ? "2" : "0",
20313
20387
  info_source: sourceData,
20314
20388
  ...location ? {
20315
- city: location.label,
20316
- city_code: location.value
20389
+ manual_selected_city: JSON.stringify({
20390
+ city: location.label,
20391
+ city_code: location.value
20392
+ })
20317
20393
  } : null,
20318
20394
  ...params.settingInfo?.toutiaoCollectionId ? {
20319
20395
  want_join_collection_id: params.settingInfo.toutiaoCollectionId
@@ -20363,6 +20439,12 @@ var __webpack_exports__ = {};
20363
20439
  claim_exclusive: toutiaoExclusive ? toutiaoExclusive : toutiaoOriginal?.includes("exclusive") ? 1 : 0
20364
20440
  };
20365
20441
  task._timerRecord.PrePublish = Date.now();
20442
+ task.logger.info(`[toutiaoPublish] ${"draft" === params.saveType ? "同步草稿" : "发布文章"}参数`, {
20443
+ saveType: params.saveType,
20444
+ title: params.title,
20445
+ extra: extraData,
20446
+ publishData
20447
+ });
20366
20448
  const msToken = params.cookies.find((it)=>"msToken" === it.name)?.value;
20367
20449
  let publishOption = {};
20368
20450
  if (msToken) {
@@ -21558,8 +21640,8 @@ var __webpack_exports__ = {};
21558
21640
  headers
21559
21641
  });
21560
21642
  const proxyHttp = new Http(...args);
21561
- proxyHttp.addResponseInterceptor((response)=>{
21562
- const responseData = response.data;
21643
+ const baseRespFinder = (response)=>{
21644
+ const responseData = response?.data;
21563
21645
  const msgType = "draft" === params.saveType ? "同步" : "发布";
21564
21646
  if (response && responseData?.base_resp && 0 !== responseData.base_resp.ret && !ignoreErrno.includes(responseData.base_resp.ret)) {
21565
21647
  const errmsg = weixinPublish_mock_errnoMap[responseData.base_resp.ret] || response.config.defaultErrorMsg || responseData.base_resp.err_msg || `文章${msgType}异常,请稍后重试。`;
@@ -21569,7 +21651,9 @@ var __webpack_exports__ = {};
21569
21651
  data: responseData
21570
21652
  };
21571
21653
  }
21572
- });
21654
+ };
21655
+ http.addResponseInterceptor(baseRespFinder);
21656
+ proxyHttp.addResponseInterceptor(baseRespFinder);
21573
21657
  await http.api({
21574
21658
  method: "get",
21575
21659
  url: "https://mp.weixin.qq.com/cgi-bin/appmsgpublish",