@iflyrpa/actions 1.1.8 → 1.1.10

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.cjs CHANGED
@@ -14,6 +14,8 @@ const require$$4$1 = require('assert');
14
14
  const require$$0$1 = require('tty');
15
15
  const zlib = require('zlib');
16
16
  const events$1 = require('events');
17
+ const node_buffer = require('node:buffer');
18
+ const crypto = require('node:crypto');
17
19
 
18
20
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
19
21
 
@@ -44,6 +46,7 @@ const require$$6__default = /*#__PURE__*/_interopDefaultCompat(require$$6);
44
46
  const require$$4__default$1 = /*#__PURE__*/_interopDefaultCompat(require$$4$1);
45
47
  const require$$0__default$1 = /*#__PURE__*/_interopDefaultCompat(require$$0$1);
46
48
  const zlib__default = /*#__PURE__*/_interopDefaultCompat(zlib);
49
+ const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto);
47
50
 
48
51
  function ensureFile(filePath) {
49
52
  return new Promise((resolve, reject)=>{
@@ -967,8 +970,6 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
967
970
  return axiosError;
968
971
  };
969
972
 
970
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
971
-
972
973
  function getDefaultExportFromCjs (x) {
973
974
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
974
975
  }
@@ -21626,8 +21627,22 @@ const replaceImgSrc = (html, callback) => {
21626
21627
  parser.end();
21627
21628
  return lastedHtml;
21628
21629
  };
21630
+ const executeAction = (...actions) => {
21631
+ return async (...p) => {
21632
+ let lastError = null;
21633
+ for (const action of actions) {
21634
+ try {
21635
+ const result = await action(...p);
21636
+ return result;
21637
+ } catch (error) {
21638
+ lastError = error instanceof Error ? error : new Error(String(error));
21639
+ }
21640
+ }
21641
+ throw lastError || new Error("All actions failed");
21642
+ };
21643
+ };
21629
21644
 
21630
- const errnoMap$2 = {
21645
+ const errnoMap$3 = {
21631
21646
  20040706: "\u6B63\u6587\u56FE\u7247\u548C\u5C01\u9762\u56FE\u7247\u63A8\u8350jpg\u3001png\u683C\u5F0F\u3002",
21632
21647
  20040084: "\u6B63\u6587\u56FE\u7247\u548C\u5C01\u9762\u56FE\u7247\u63A8\u8350jpg\u3001png\u683C\u5F0F\u3002",
21633
21648
  20050004: "\u4ECA\u65E5\u767E\u5BB6\u53F7\u53D1\u5E03\u6B21\u6570\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u660E\u5929\u518D\u8BD5\u3002",
@@ -21639,7 +21654,7 @@ const errnoMap$2 = {
21639
21654
  2004005714: "\u7F51\u7EDC\u73AF\u5883\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5\u53D1\u5E03\u3002",
21640
21655
  401100032: "\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u56FE\u7247\uFF08\u5982\uFF1A\u683C\u5F0F\u3001\u7248\u6743\u3001\u5408\u89C4\u6027\u7B49\uFF09\u3002"
21641
21656
  };
21642
- const mockAction$4 = async (task, params) => {
21657
+ const mockAction$5 = async (task, params) => {
21643
21658
  const { baijiahaoSingleCover, baijiahaoMultCover, baijiahaoCoverType } = params.settingInfo;
21644
21659
  const tmpCachePath = task.getTmpPath();
21645
21660
  const api = axios$1.create({
@@ -21651,7 +21666,7 @@ const mockAction$4 = async (task, params) => {
21651
21666
  api.interceptors.response.use(
21652
21667
  (response) => {
21653
21668
  if (response.data.errno !== 0) {
21654
- const errmsg = response.data.errno === 2005e4 ? (params.saveType === "draft" ? "\u540C\u6B65" : "\u53D1\u5E03") + errnoMap$2[response.data.errno] : response.data.errno === 401100032 ? "\u56FE\u7247" + (params.saveType === "draft" ? "\u540C\u6B65" : "\u53D1\u5E03") + errnoMap$2[response.data.errno] : errnoMap$2[response.data.errno] || response.config.defaultErrorMsg || (params.saveType === "draft" ? "\u6587\u7AE0\u540C\u6B65\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : "\u6587\u7AE0\u53D1\u5E03\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002");
21669
+ const errmsg = response.data.errno === 2005e4 ? (params.saveType === "draft" ? "\u540C\u6B65" : "\u53D1\u5E03") + errnoMap$3[response.data.errno] : response.data.errno === 401100032 ? "\u56FE\u7247" + (params.saveType === "draft" ? "\u540C\u6B65" : "\u53D1\u5E03") + errnoMap$3[response.data.errno] : errnoMap$3[response.data.errno] || response.config.defaultErrorMsg || (params.saveType === "draft" ? "\u6587\u7AE0\u540C\u6B65\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : "\u6587\u7AE0\u53D1\u5E03\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002");
21655
21670
  task.logger.error(errmsg);
21656
21671
  return Promise.reject(new Error(errmsg));
21657
21672
  }
@@ -21770,7 +21785,7 @@ const mockAction$4 = async (task, params) => {
21770
21785
 
21771
21786
  const baijiahaoPublish = async (task, params) => {
21772
21787
  task.logger.info("\u5F00\u59CB\u767E\u5BB6\u53F7\u53D1\u5E03");
21773
- return mockAction$4(task, params);
21788
+ return mockAction$5(task, params);
21774
21789
  };
21775
21790
 
21776
21791
  const getBaijiahaoActivity = async (task, params) => {
@@ -21900,7 +21915,7 @@ const COVER_TYPE = {
21900
21915
  single: 2,
21901
21916
  multiple: 3
21902
21917
  };
21903
- const errnoMap$1 = {
21918
+ const errnoMap$2 = {
21904
21919
  20004020: "\u56FE\u7247\u4E0A\u4F20\u5F02\u5E38\uFF0C\u8BF7\u91CD\u65B0\u7ED1\u5B9A\u8D26\u53F7\u540E\u540C\u6B65\u3002",
21905
21920
  7115: "\u6B63\u6587\u56FE\u7247\u548C\u5C01\u9762\u56FE\u7247\u63A8\u8350jpg\u3001png\u683C\u5F0F\u3002",
21906
21921
  100006: "\u6587\u7AE0\u540C\u6B65\u5F02\u5E38\uFF0C\u8BF7\u91CD\u65B0\u7ED1\u5B9A\u8D26\u53F7\u540E\u91CD\u8BD5\u3002",
@@ -21924,7 +21939,7 @@ const get3101DetailError = (errorList, message, saveType) => {
21924
21939
  }
21925
21940
  return error || (saveType === "draft" ? "\u6587\u7AE0\u540C\u6B65\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : "\u6587\u7AE0\u53D1\u5E03\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002");
21926
21941
  };
21927
- const mockAction$3 = async (task, params) => {
21942
+ const mockAction$4 = async (task, params) => {
21928
21943
  const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType, toutiaoOriginal } = params.settingInfo;
21929
21944
  const tmpCachePath = task.getTmpPath();
21930
21945
  const api = axios$1.create({
@@ -21938,10 +21953,10 @@ const mockAction$3 = async (task, params) => {
21938
21953
  (response) => {
21939
21954
  if (response.data.code !== 0) {
21940
21955
  let errmsg = "";
21941
- if (Array.isArray(errnoMap$1[response.data.code])) {
21942
- errmsg = get3101DetailError(errnoMap$1[response.data.code], response.data.message, params.saveType);
21956
+ if (Array.isArray(errnoMap$2[response.data.code])) {
21957
+ errmsg = get3101DetailError(errnoMap$2[response.data.code], response.data.message, params.saveType);
21943
21958
  } else {
21944
- errmsg = errnoMap$1[response.data.code] || response.config.defaultErrorMsg || (params.saveType === "draft" ? "\u6587\u7AE0\u540C\u6B65\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : "\u6587\u7AE0\u53D1\u5E03\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002");
21959
+ errmsg = errnoMap$2[response.data.code] || response.config.defaultErrorMsg || (params.saveType === "draft" ? "\u6587\u7AE0\u540C\u6B65\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : "\u6587\u7AE0\u53D1\u5E03\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002");
21945
21960
  }
21946
21961
  task.logger.error(errmsg);
21947
21962
  return Promise.reject(new Error(errmsg));
@@ -22089,10 +22104,10 @@ const mockAction$3 = async (task, params) => {
22089
22104
 
22090
22105
  const toutiaoPublish = async (task, params) => {
22091
22106
  task.logger.info("\u5F00\u59CB\u5934\u6761\u53D1\u5E03");
22092
- return mockAction$3(task, params);
22107
+ return mockAction$4(task, params);
22093
22108
  };
22094
22109
 
22095
- const mockAction$2 = async (task, params) => {
22110
+ const mockAction$3 = async (task, params) => {
22096
22111
  const tmpCachePath = task.getTmpPath();
22097
22112
  const api = axios$1.create({
22098
22113
  headers: {
@@ -22223,26 +22238,19 @@ const rpaAction$2 = async (task, params) => {
22223
22238
  await page.locator(".footer-wrap button.publish-content").click();
22224
22239
  };
22225
22240
 
22226
- const executeAction$1 = (task, params) => {
22227
- return new Promise((resolve, reject) => {
22228
- mockAction$2(task, params).then(resolve).catch(() => {
22229
- rpaAction$2(task, params).then(resolve).catch(reject);
22230
- });
22231
- });
22232
- };
22233
22241
  const weitoutiaoPublish = async (task, params) => {
22234
22242
  task.logger.info("\u5F00\u59CB\u5FAE\u5934\u6761\u53D1\u5E03");
22235
22243
  if (params.actionType === "rpa") {
22236
22244
  return rpaAction$2(task, params);
22237
22245
  }
22238
22246
  if (params.actionType === "mockApi") {
22239
- return mockAction$2(task, params);
22247
+ return mockAction$3(task, params);
22240
22248
  }
22241
- return executeAction$1(task, params);
22249
+ return executeAction(mockAction$3, rpaAction$2)(task, params);
22242
22250
  };
22243
22251
 
22244
22252
  const scanRetryMaxCount = 30;
22245
- const errnoMap = {
22253
+ const errnoMap$1 = {
22246
22254
  200003: "\u767B\u5F55\u5931\u6548"
22247
22255
  };
22248
22256
  const saveDraft$1 = (api, params, data) => {
@@ -22340,7 +22348,7 @@ const massSend = async (api, params, data) => {
22340
22348
  });
22341
22349
  return res;
22342
22350
  };
22343
- const mockAction$1 = async (task, params) => {
22351
+ const mockAction$2 = async (task, params) => {
22344
22352
  const tmpCachePath = task.getTmpPath();
22345
22353
  const api = axios$1.create({
22346
22354
  headers: {
@@ -22352,7 +22360,7 @@ const mockAction$1 = async (task, params) => {
22352
22360
  (response) => {
22353
22361
  const responseData = response.data;
22354
22362
  if (responseData?.base_resp && responseData.base_resp.ret !== 0) {
22355
- const errmsg = errnoMap[responseData.base_resp.ret] || response.config.defaultErrorMsg || responseData.base_resp.err_msg || "Unknown error";
22363
+ const errmsg = errnoMap$1[responseData.base_resp.ret] || response.config.defaultErrorMsg || responseData.base_resp.err_msg || "Unknown error";
22356
22364
  task.logger.error(errmsg, responseData);
22357
22365
  return Promise.reject(new Error(errmsg));
22358
22366
  }
@@ -22561,7 +22569,7 @@ const mockAction$1 = async (task, params) => {
22561
22569
 
22562
22570
  const weixinPublish = async (task, params) => {
22563
22571
  task.logger.info("\u5F00\u59CB\u5FAE\u4FE1\u516C\u4F17\u53F7\u53D1\u5E03");
22564
- return mockAction$1(task, params);
22572
+ return mockAction$2(task, params);
22565
22573
  };
22566
22574
 
22567
22575
  const saveDraft = (api, params, data) => {
@@ -22582,7 +22590,7 @@ const saveDraft = (api, params, data) => {
22582
22590
  data: formData
22583
22591
  });
22584
22592
  };
22585
- const mockAction = async (task, params) => {
22593
+ const mockAction$1 = async (task, params) => {
22586
22594
  const tmpCachePath = task.getTmpPath();
22587
22595
  const api = axios$1.create({
22588
22596
  headers: {
@@ -22763,29 +22771,258 @@ const rpaAction$1 = async (task, params) => {
22763
22771
  }
22764
22772
  };
22765
22773
 
22766
- const executeAction = (task, params) => {
22767
- return new Promise((resolve, reject) => {
22768
- mockAction(task, params).then(resolve).catch(() => {
22769
- rpaAction$1(task, params).then(resolve).catch(reject);
22770
- });
22771
- });
22772
- };
22773
22774
  const weixinmpPublish = async (task, params) => {
22774
22775
  task.logger.info("\u5F00\u59CB\u5C0F\u7EFF\u4E66\u53D1\u5E03");
22775
22776
  if (params.actionType === "rpa") {
22776
22777
  return rpaAction$1(task, params);
22777
22778
  }
22778
22779
  if (params.actionType === "mockApi") {
22779
- return mockAction(task, params);
22780
+ return mockAction$1(task, params);
22780
22781
  }
22781
- return executeAction(task, params);
22782
+ return executeAction(mockAction$1, rpaAction$1)(task, params);
22782
22783
  };
22783
22784
 
22784
- var dayjs_min = {exports: {}};
22785
+ var __defProp = Object.defineProperty;
22786
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
22787
+ var __publicField = (obj, key, value) => {
22788
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22789
+ return value;
22790
+ };
22791
+ class XsEncrypt {
22792
+ constructor() {
22793
+ __publicField(this, "words", [929260340, 1633971297, 895580464, 925905270]);
22794
+ __publicField(this, "keyBytes", node_buffer.Buffer.concat(
22795
+ this.words.map(
22796
+ (word) => new Uint8Array(node_buffer.Buffer.from([word >> 24 & 255, word >> 16 & 255, word >> 8 & 255, word & 255]))
22797
+ )
22798
+ ));
22799
+ __publicField(this, "iv", node_buffer.Buffer.from("4uzjr7mbsibcaldp", "utf8"));
22800
+ }
22801
+ /**
22802
+ * 根据传入的url生成MD5摘要
22803
+ *
22804
+ * @param {string} url - API的url
22805
+ * @returns {string} MD5摘要
22806
+ */
22807
+ async encryptMD5(url) {
22808
+ return crypto__default.createHash("md5").update(url, "utf8").digest("hex");
22809
+ }
22810
+ /**
22811
+ * 根据传入的text生成AES加密后的内容,并将其转为base64编码
22812
+ *
22813
+ * @param {string} text - 需要加密的字符串
22814
+ * @returns {string} 加密后的base64编码字符串
22815
+ */
22816
+ async encryptText(text) {
22817
+ const textEncoded = node_buffer.Buffer.from(text).toString("base64");
22818
+ const cipher = crypto__default.createCipheriv("aes-128-cbc", new Uint8Array(this.keyBytes), new Uint8Array(this.iv));
22819
+ const ciphertext = cipher.update(textEncoded, "utf8", "base64");
22820
+ return ciphertext + cipher.final("base64");
22821
+ }
22822
+ /**
22823
+ * 把加密后的payload转为16进制
22824
+ *
22825
+ * @param {string} encodedData - 加密后的payload(Base64编码)
22826
+ * @returns {string} 十六进制字符串
22827
+ */
22828
+ async base64ToHex(encodedData) {
22829
+ const decodedData = node_buffer.Buffer.from(encodedData, "base64");
22830
+ return decodedData.toString("hex");
22831
+ }
22832
+ /**
22833
+ * 把小红书加密参数payload转16进制 再使用base64编码
22834
+ *
22835
+ * @param {string} payload - 要加密处理的payload内容
22836
+ * @param {string} platform - 登录平台
22837
+ * @returns {string} 加密后并进行base64编码的字符串
22838
+ */
22839
+ async encryptPayload(payload, platform) {
22840
+ const hexPayload = await this.base64ToHex(payload);
22841
+ const obj = {
22842
+ signSvn: "56",
22843
+ signType: "x2",
22844
+ appID: platform,
22845
+ signVersion: "1",
22846
+ payload: hexPayload
22847
+ };
22848
+ const jsonString = JSON.stringify(obj, null, 0);
22849
+ return node_buffer.Buffer.from(jsonString).toString("base64");
22850
+ }
22851
+ /**
22852
+ * 将传入的参数加密为小红书的xs
22853
+ * Args: url: API请求的URL
22854
+ * a1: 签名参数a1
22855
+ * ts: 时间戳
22856
+ * platform: 登录平台 默认为xhs-pc-web
22857
+ * Returns:
22858
+ * 最终的加密签名字符串,前缀为“XYW_”
22859
+ */
22860
+ async encryptXs(url, a1, ts, platform = "xhs-pc-web") {
22861
+ const text = `x1=${await this.encryptMD5(`url=${url}`)};x2=0|0|0|1|0|0|1|0|0|0|1|0|0|0|0|1|0|0|0;x3=${a1};x4=${ts};`;
22862
+ return `XYW_${await this.encryptPayload(await this.encryptText(text), platform)}`;
22863
+ }
22864
+ dumps(...rest) {
22865
+ const [data, replacer = null, space = 0] = rest;
22866
+ return JSON.stringify(data, replacer, space).replace(/\n/g, "").replace(/":\s+"/g, '":"');
22867
+ }
22868
+ }
22785
22869
 
22786
- (function (module, exports) {
22787
- !function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0;}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return b},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
22788
- } (dayjs_min));
22870
+ const errnoMap = {};
22871
+ const xsEncrypt = new XsEncrypt();
22872
+ const mockAction = async (task, params) => {
22873
+ const tmpCachePath = task.getTmpPath();
22874
+ const a1Cookie = params.cookies.find((it) => it.name === "a1")?.value;
22875
+ if (!a1Cookie) {
22876
+ throw new Error("\u672A\u83B7\u53D6\u5230 a1 cookie");
22877
+ }
22878
+ const api = axios$1.create({
22879
+ headers: {
22880
+ cookie: params.cookies.map((it) => `${it.name}=${it.value}`).join(";"),
22881
+ origin: "https://creator.xiaohongshu.com",
22882
+ referer: "https://creator.xiaohongshu.com/",
22883
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
22884
+ }
22885
+ });
22886
+ api.interceptors.response.use(
22887
+ (response) => {
22888
+ const responseData = response.data;
22889
+ if (responseData?.code && responseData.code !== 0) {
22890
+ const errmsg = errnoMap[responseData.code] || response.config.defaultErrorMsg || "Unknown error";
22891
+ task.logger.error(errmsg, responseData);
22892
+ return Promise.reject(new Error(errmsg));
22893
+ }
22894
+ return response;
22895
+ },
22896
+ (error) => {
22897
+ task.logger.error("\u5C0F\u7EA2\u4E66\u63A5\u53E3\u8BF7\u6C42\u5931\u8D25", error);
22898
+ return Promise.reject(error);
22899
+ }
22900
+ );
22901
+ const fetchCoverUrl = `/api/media/v1/upload/creator/permit?biz_name=spectrum&scene=image&file_count=${params.banners.length}&version=1&source=web`;
22902
+ const xt = Date.now().toString();
22903
+ const xs = await xsEncrypt.encryptXs(fetchCoverUrl, a1Cookie, xt);
22904
+ const coverIdInfo = await api({
22905
+ method: "get",
22906
+ baseURL: "https://creator.xiaohongshu.com",
22907
+ url: fetchCoverUrl,
22908
+ defaultErrorMsg: "\u83B7\u53D6\u4E0A\u4F20\u9644\u4EF6 token \u5931\u8D25",
22909
+ headers: { "x-s": xs, "x-t": xt }
22910
+ });
22911
+ const coverIds = coverIdInfo.data.data.uploadTempPermits[0].fileIds;
22912
+ const ossToken = coverIdInfo.data.data.uploadTempPermits[0].token;
22913
+ const uploadFile = async (url, index) => {
22914
+ const fileName = getFilenameFromUrl(url);
22915
+ const localUrl = await downloadImage(url, path__default.join(tmpCachePath, fileName));
22916
+ const ossFileId = coverIds[index];
22917
+ const fileBuffer = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c____default.readFileSync(localUrl);
22918
+ await api.put(`https://ros-upload.xiaohongshu.com/${ossFileId}`, fileBuffer, {
22919
+ headers: {
22920
+ "x-cos-security-token": ossToken
22921
+ },
22922
+ defaultErrorMsg: "\u56FE\u7247\u4E0A\u4F20\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D"
22923
+ });
22924
+ return { ossFileId, ossToken };
22925
+ };
22926
+ const coverInfos = await Promise.all(params.banners.map((it, idx) => uploadFile(it, idx)));
22927
+ const publishData = {
22928
+ common: {
22929
+ ats: [],
22930
+ biz_relations: [],
22931
+ desc: params?.content,
22932
+ goods_info: {},
22933
+ hash_tag: [],
22934
+ note_id: "",
22935
+ source: JSON.stringify({
22936
+ type: "web",
22937
+ ids: "",
22938
+ extraInfo: '{"systemId":"web"}'
22939
+ }),
22940
+ title: params?.title,
22941
+ type: "normal",
22942
+ privacy_info: {
22943
+ op_type: 1,
22944
+ type: params.visibleRange === "public" ? 0 : 1
22945
+ },
22946
+ post_loc: params.address ? {
22947
+ name: params.address?.name,
22948
+ poi_id: params.address?.poi_id,
22949
+ poi_type: params.address?.poi_type,
22950
+ subname: params.address?.full_address
22951
+ } : null,
22952
+ business_binds: ""
22953
+ },
22954
+ image_info: {
22955
+ images: coverInfos.map((it) => ({
22956
+ extra_info_json: '{"mimeType":"image/png"}',
22957
+ file_id: it.ossFileId,
22958
+ metadata: { source: -1 },
22959
+ stickers: { floating: [], version: 2 }
22960
+ }))
22961
+ },
22962
+ video_info: null
22963
+ };
22964
+ const userDeclarationBind = {
22965
+ origin: 2,
22966
+ photoInfo: {},
22967
+ repostInfo: {}
22968
+ };
22969
+ if (params.selfDeclaration?.type === "fictional-rendition") {
22970
+ userDeclarationBind.origin = 1;
22971
+ } else if (params.selfDeclaration?.type === "ai-generated") {
22972
+ userDeclarationBind.origin = 2;
22973
+ } else if (params.selfDeclaration?.type === "source-statement") {
22974
+ if (params.selfDeclaration.childType === "self-labeling") {
22975
+ userDeclarationBind.origin = 3;
22976
+ } else if (params.selfDeclaration.childType === "self-shooting") {
22977
+ userDeclarationBind.origin = 4;
22978
+ const photoInfo = {};
22979
+ if (params.selfDeclaration.shootingLocation) {
22980
+ photoInfo.photoPlace = {
22981
+ name: params.selfDeclaration.shootingLocation.name,
22982
+ poiId: params.selfDeclaration.shootingLocation.poi_id,
22983
+ poiType: params.selfDeclaration.shootingLocation.poi_type,
22984
+ subname: params.selfDeclaration.shootingLocation.full_address
22985
+ };
22986
+ }
22987
+ if (params.selfDeclaration.shootingDate) {
22988
+ photoInfo.photoTime = params.selfDeclaration.shootingDate;
22989
+ }
22990
+ userDeclarationBind.photoInfo = photoInfo;
22991
+ } else if (params.selfDeclaration.childType === "transshipment") {
22992
+ userDeclarationBind.origin = 5;
22993
+ if (params.selfDeclaration.sourceMedia) {
22994
+ userDeclarationBind.repostInfo = {
22995
+ source: params.selfDeclaration.sourceMedia
22996
+ };
22997
+ }
22998
+ }
22999
+ }
23000
+ const business_binds = {
23001
+ version: 1,
23002
+ bizType: "",
23003
+ noteId: "",
23004
+ noteOrderBind: {},
23005
+ // 发布时间 - 立即发布/定时发布
23006
+ notePostTiming: params.isImmediatelyPublish ? {} : { postTime: params.scheduledPublish },
23007
+ noteCollectionBind: { id: "" },
23008
+ ...params.selfDeclaration ? { userDeclarationBind } : {}
23009
+ };
23010
+ publishData.common.business_binds = JSON.stringify(business_binds);
23011
+ const publishDataStr = xsEncrypt.dumps(publishData);
23012
+ const publishXt = Date.now().toString();
23013
+ const publishXs = await xsEncrypt.encryptXs(`/web_api/sns/v2/note${publishDataStr}`, a1Cookie, publishXt);
23014
+ const publishResult = await api({
23015
+ method: "post",
23016
+ url: "https://edith.xiaohongshu.com/web_api/sns/v2/note",
23017
+ data: publishData,
23018
+ headers: {
23019
+ "x-s": publishXs,
23020
+ "x-t": publishXt
23021
+ },
23022
+ defaultErrorMsg: "\u6587\u7AE0\u53D1\u5E03\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D"
23023
+ });
23024
+ return publishResult.data.data.id;
23025
+ };
22789
23026
 
22790
23027
  const rpaAction = async (task, params) => {
22791
23028
  const commonCookies = {
@@ -22936,7 +23173,13 @@ const rpaAction = async (task, params) => {
22936
23173
 
22937
23174
  const xiaohongshuPublish = async (task, params) => {
22938
23175
  task.logger.info("\u5F00\u59CB\u5C0F\u7EA2\u4E66\u53D1\u5E03");
22939
- return rpaAction(task, params);
23176
+ if (params.actionType === "rpa") {
23177
+ return rpaAction(task, params);
23178
+ }
23179
+ if (params.actionType === "mockApi") {
23180
+ return mockAction(task, params);
23181
+ }
23182
+ return executeAction(mockAction, rpaAction)(task, params);
22940
23183
  };
22941
23184
 
22942
23185
  class Action {