@iflyrpa/actions 4.0.0-beta.4 → 4.0.0-beta.8

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/bundle.js CHANGED
@@ -8733,10 +8733,8 @@ var __webpack_exports__ = {};
8733
8733
  navigator: ()=>_navigator,
8734
8734
  origin: ()=>utils_origin
8735
8735
  });
8736
- var package_namespaceObject = {
8737
- i8: "0.1.0"
8738
- };
8739
- var package_namespaceObject_0 = JSON.parse('{"i8":"3.0.7-beta.3"}');
8736
+ var package_namespaceObject = JSON.parse('{"i8":"1.0.0-beta.0"}');
8737
+ var package_namespaceObject_0 = JSON.parse('{"i8":"4.0.0-beta.7"}');
8740
8738
  const external_node_fs_namespaceObject = require("node:fs");
8741
8739
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
8742
8740
  const external_node_http_namespaceObject = require("node:http");
@@ -8777,6 +8775,7 @@ var __webpack_exports__ = {};
8777
8775
  }
8778
8776
  });
8779
8777
  }
8778
+ const DOWNLOAD_BASE_TIMEOUT = 60000;
8780
8779
  async function downloadImage(url, savePath, retries = 3) {
8781
8780
  const RETRYABLE_CODES = new Set([
8782
8781
  "ECONNRESET",
@@ -8784,20 +8783,25 @@ var __webpack_exports__ = {};
8784
8783
  "EAI_AGAIN",
8785
8784
  "ENOTFOUND"
8786
8785
  ]);
8787
- try {
8788
- return await downloadImageOnce(url, savePath);
8789
- } catch (err) {
8790
- var _err_extra;
8791
- const errCode = (null == err ? void 0 : err.code) ?? (null == err ? void 0 : null === (_err_extra = err.extra) || void 0 === _err_extra ? void 0 : _err_extra.code);
8792
- if (retries > 0 && (RETRYABLE_CODES.has(errCode) || (null == err ? void 0 : err.code) === 500)) {
8793
- console.warn(`downloadImage 失败,剩余重试次数 ${retries},url: ${url},原因:`, (null == err ? void 0 : err.message) ?? err);
8786
+ const maxAttempts = retries;
8787
+ let lastErr;
8788
+ for(let attempt = 1; attempt <= maxAttempts; attempt++){
8789
+ const timeout = attempt * DOWNLOAD_BASE_TIMEOUT;
8790
+ try {
8791
+ return await downloadImageOnce(url, savePath, timeout);
8792
+ } catch (err) {
8793
+ var _err_extra;
8794
+ lastErr = err;
8795
+ const errCode = (null == err ? void 0 : err.code) ?? (null == err ? void 0 : null === (_err_extra = err.extra) || void 0 === _err_extra ? void 0 : _err_extra.code);
8796
+ const retryable = RETRYABLE_CODES.has(errCode) || (null == err ? void 0 : err.code) === 500;
8797
+ if (attempt >= maxAttempts || !retryable) throw err;
8798
+ console.warn(`downloadImage 失败,已尝试 ${attempt}/${maxAttempts} 次,下次超时 ${(attempt + 1) * DOWNLOAD_BASE_TIMEOUT / 1000}s,url: ${url},原因:`, (null == err ? void 0 : err.message) ?? err);
8794
8799
  await new Promise((r)=>setTimeout(r, 1000));
8795
- return downloadImage(url, savePath, retries - 1);
8796
8800
  }
8797
- throw err;
8798
8801
  }
8802
+ throw lastErr;
8799
8803
  }
8800
- async function downloadImageOnce(url, savePath) {
8804
+ async function downloadImageOnce(url, savePath, timeout = DOWNLOAD_BASE_TIMEOUT) {
8801
8805
  await ensureFile(savePath);
8802
8806
  return new Promise((resolve, reject)=>{
8803
8807
  const handleResponse = (response)=>{
@@ -8879,11 +8883,24 @@ var __webpack_exports__ = {};
8879
8883
  };
8880
8884
  const requestFn = url.startsWith("http://") ? external_node_http_namespaceObject.get : external_node_https_namespaceObject.get;
8881
8885
  const req = requestFn(url, handleResponse);
8882
- req.setTimeout(60000, ()=>{
8886
+ let remoteAddress = "";
8887
+ req.on("socket", (socket)=>{
8888
+ socket.on("connect", ()=>{
8889
+ remoteAddress = `${socket.remoteAddress ?? ""}:${socket.remotePort ?? ""}`;
8890
+ });
8891
+ if (socket.remoteAddress) remoteAddress = `${socket.remoteAddress}:${socket.remotePort ?? ""}`;
8892
+ });
8893
+ req.setTimeout(timeout, ()=>{
8883
8894
  req.destroy();
8895
+ const remoteInfo = remoteAddress || "未建立连接";
8896
+ console.warn(`图片下载超时 (${timeout / 1000}s),远端IP: ${remoteInfo},Url:${url}`);
8884
8897
  reject({
8885
8898
  code: 500,
8886
- message: `图片下载超时 (${url}),请检查网络连接或稍后重试!`
8899
+ message: `图片下载超时 (${timeout / 1000}s) Url:${url},请检查网络连接或稍后重试! 远端ip: ${remoteInfo}`,
8900
+ extra: {
8901
+ url,
8902
+ remoteAddress: remoteInfo
8903
+ }
8887
8904
  });
8888
8905
  });
8889
8906
  req.on("error", handleError);
@@ -30619,16 +30636,35 @@ var __webpack_exports__ = {};
30619
30636
  }, "微信账号有效性检测完成!");
30620
30637
  };
30621
30638
  const XhsSessionCheck = async (_task, params)=>{
30639
+ const logger = _task.logger;
30640
+ const startedAt = Date.now();
30622
30641
  const check = {
30623
30642
  isValidSession: false,
30624
30643
  isValidWebSession: false
30625
30644
  };
30645
+ const cookieNames = params.cookies.map((it)=>it.name);
30646
+ logger?.info("[XhsSessionCheck] 开始执行小红书账号有效性检测", {
30647
+ accountId: params.accountId,
30648
+ proxyLoc: params.proxyLoc,
30649
+ localIP: params.localIP,
30650
+ willUseProxyAgent: !!params.localIP,
30651
+ cookieCount: params.cookies.length,
30652
+ cookieNames,
30653
+ hasA1: cookieNames.includes("a1"),
30654
+ hasWebSession: cookieNames.includes("web_session")
30655
+ });
30626
30656
  const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
30627
- if (!a1Cookie) return {
30628
- code: 414,
30629
- message: "账号数据异常,请重新绑定账号后重试。",
30630
- data: check
30631
- };
30657
+ if (!a1Cookie) {
30658
+ logger?.warn("[XhsSessionCheck] 缺失关键 cookie a1,提前返回", {
30659
+ accountId: params.accountId,
30660
+ cookieNames
30661
+ });
30662
+ return {
30663
+ code: 414,
30664
+ message: "账号数据异常,请重新绑定账号后重试。",
30665
+ data: check
30666
+ };
30667
+ }
30632
30668
  const headers = {
30633
30669
  cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
30634
30670
  referer: "https://creator.xiaohongshu.com/new/home?source=official"
@@ -30656,6 +30692,7 @@ var __webpack_exports__ = {};
30656
30692
  return acc;
30657
30693
  }, {});
30658
30694
  const loginBaseXsHeader = sessionCheck_xsEncrypt.signHeadersGet(loginBasePath, recordCookie, "xhs-pc-web", null);
30695
+ const baseInfoStart = Date.now();
30659
30696
  const _baseInfo = http.api({
30660
30697
  method: "get",
30661
30698
  baseURL: "https://creator.xiaohongshu.com",
@@ -30665,7 +30702,28 @@ var __webpack_exports__ = {};
30665
30702
  retries: 3,
30666
30703
  retryDelay: 20,
30667
30704
  timeout: 3000
30668
- }).catch((e)=>e.data);
30705
+ }).then((res)=>{
30706
+ logger?.info("[XhsSessionCheck] creator base 接口请求成功", {
30707
+ accountId: params.accountId,
30708
+ duration: Date.now() - baseInfoStart,
30709
+ code: res?.code,
30710
+ msg: res?.msg,
30711
+ proxyInfo: http.proxyInfo
30712
+ });
30713
+ return res;
30714
+ }).catch((e)=>{
30715
+ logger?.warn("[XhsSessionCheck] creator base 接口请求失败", {
30716
+ accountId: params.accountId,
30717
+ duration: Date.now() - baseInfoStart,
30718
+ code: e?.code,
30719
+ message: e?.message,
30720
+ data: e?.data,
30721
+ extra: e?.extra,
30722
+ proxyInfo: http.proxyInfo
30723
+ });
30724
+ return e.data;
30725
+ });
30726
+ const webSessionStart = Date.now();
30669
30727
  const _web_session = http.api({
30670
30728
  method: "get",
30671
30729
  url: "https://edith.xiaohongshu.com/api/sns/web/unread_count"
@@ -30673,6 +30731,26 @@ var __webpack_exports__ = {};
30673
30731
  retries: 3,
30674
30732
  retryDelay: 20,
30675
30733
  timeout: 3000
30734
+ }).then((res)=>{
30735
+ logger?.info("[XhsSessionCheck] edith unread_count 接口请求成功", {
30736
+ accountId: params.accountId,
30737
+ duration: Date.now() - webSessionStart,
30738
+ code: res?.code,
30739
+ msg: res?.msg,
30740
+ proxyInfo: http.proxyInfo
30741
+ });
30742
+ return res;
30743
+ }).catch((e)=>{
30744
+ logger?.warn("[XhsSessionCheck] edith unread_count 接口请求失败", {
30745
+ accountId: params.accountId,
30746
+ duration: Date.now() - webSessionStart,
30747
+ code: e?.code,
30748
+ message: e?.message,
30749
+ data: e?.data,
30750
+ extra: e?.extra,
30751
+ proxyInfo: http.proxyInfo
30752
+ });
30753
+ throw e;
30676
30754
  });
30677
30755
  const [baseInfo, web_session] = await Promise.all([
30678
30756
  _baseInfo,
@@ -30680,8 +30758,18 @@ var __webpack_exports__ = {};
30680
30758
  ]);
30681
30759
  if (baseInfo?.code === 0) check.isValidSession = true;
30682
30760
  if (0 === web_session.code) check.isValidWebSession = true;
30683
- baseInfo?.code, web_session.code;
30761
+ const _isSuccess = baseInfo?.code === web_session.code;
30684
30762
  const message = `小红书账号有效性检测成功${_task.debug ? ` ${http.proxyInfo}` : ""}`;
30763
+ logger?.info("[XhsSessionCheck] 检测完成", {
30764
+ accountId: params.accountId,
30765
+ totalDuration: Date.now() - startedAt,
30766
+ baseInfoCode: baseInfo?.code,
30767
+ webSessionCode: web_session?.code,
30768
+ isValidSession: check.isValidSession,
30769
+ isValidWebSession: check.isValidWebSession,
30770
+ codeAligned: _isSuccess,
30771
+ proxyInfo: http.proxyInfo
30772
+ });
30685
30773
  return success(check, message);
30686
30774
  };
30687
30775
  const BjhSessionCheck = async (_task, params)=>{
@@ -34811,10 +34899,13 @@ var __webpack_exports__ = {};
34811
34899
  ].filter(Boolean).join(" ");
34812
34900
  const message = `图文发布失败,原因:${details}${task.debug ? ` ${http.proxyInfo}` : ""}`;
34813
34901
  task.logger.warn(`TaskId:${task.taskId},检测到需要验证,准备返回验证信息`);
34902
+ let decisionObj = {};
34903
+ if (decision) decisionObj = decision;
34814
34904
  const mockData = {
34815
34905
  state: types_TaskState.FAILED,
34816
34906
  error: message,
34817
34907
  result: {
34908
+ ...decisionObj,
34818
34909
  data: decision,
34819
34910
  uploadedImgList: JSON.stringify(publishData.item.common.images)
34820
34911
  }
@@ -34844,10 +34935,13 @@ var __webpack_exports__ = {};
34844
34935
  const message = `图文发布${isSuccess ? "成功" : `失败,原因:${publishResult.status_msg} ${decision?.verify_title} ${decision?.verify_desc}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
34845
34936
  const data = isSuccess ? publishResult.item_id || "" : "";
34846
34937
  if (!isSuccess) {
34938
+ let decisionObj = {};
34939
+ if (decision) decisionObj = decision;
34847
34940
  await updateTaskState?.({
34848
34941
  state: types_TaskState.FAILED,
34849
34942
  error: message,
34850
34943
  result: {
34944
+ ...decisionObj,
34851
34945
  data: decision,
34852
34946
  uploadedImgList: JSON.stringify(publishData.item.common.images)
34853
34947
  }