@iflyrpa/actions 1.1.6 → 1.1.7

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
@@ -967,6 +967,8 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
967
967
  return axiosError;
968
968
  };
969
969
 
970
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
971
+
970
972
  function getDefaultExportFromCjs (x) {
971
973
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
972
974
  }
@@ -21637,7 +21639,7 @@ const errnoMap$2 = {
21637
21639
  2004005714: "\u7F51\u7EDC\u73AF\u5883\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5\u53D1\u5E03\u3002",
21638
21640
  401100032: "\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u56FE\u7247\uFF08\u5982\uFF1A\u683C\u5F0F\u3001\u7248\u6743\u3001\u5408\u89C4\u6027\u7B49\uFF09\u3002"
21639
21641
  };
21640
- const mockAction$5 = async (task, params) => {
21642
+ const mockAction$4 = async (task, params) => {
21641
21643
  const { baijiahaoSingleCover, baijiahaoMultCover, baijiahaoCoverType } = params.settingInfo;
21642
21644
  const tmpCachePath = task.getTmpPath();
21643
21645
  const api = axios$1.create({
@@ -21768,7 +21770,7 @@ const mockAction$5 = async (task, params) => {
21768
21770
 
21769
21771
  const baijiahaoPublish = async (task, params) => {
21770
21772
  task.logger.info("\u5F00\u59CB\u767E\u5BB6\u53F7\u53D1\u5E03");
21771
- return mockAction$5(task, params);
21773
+ return mockAction$4(task, params);
21772
21774
  };
21773
21775
 
21774
21776
  const getBaijiahaoActivity = async (task, params) => {
@@ -21922,7 +21924,7 @@ const get3101DetailError = (errorList, message, saveType) => {
21922
21924
  }
21923
21925
  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");
21924
21926
  };
21925
- const mockAction$4 = async (task, params) => {
21927
+ const mockAction$3 = async (task, params) => {
21926
21928
  const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType, toutiaoOriginal } = params.settingInfo;
21927
21929
  const tmpCachePath = task.getTmpPath();
21928
21930
  const api = axios$1.create({
@@ -22087,10 +22089,10 @@ const mockAction$4 = async (task, params) => {
22087
22089
 
22088
22090
  const toutiaoPublish = async (task, params) => {
22089
22091
  task.logger.info("\u5F00\u59CB\u5934\u6761\u53D1\u5E03");
22090
- return mockAction$4(task, params);
22092
+ return mockAction$3(task, params);
22091
22093
  };
22092
22094
 
22093
- const mockAction$3 = async (task, params) => {
22095
+ const mockAction$2 = async (task, params) => {
22094
22096
  const tmpCachePath = task.getTmpPath();
22095
22097
  const api = axios$1.create({
22096
22098
  headers: {
@@ -22221,9 +22223,9 @@ const rpaAction$2 = async (task, params) => {
22221
22223
  await page.locator(".footer-wrap button.publish-content").click();
22222
22224
  };
22223
22225
 
22224
- const executeAction$2 = (task, params) => {
22226
+ const executeAction$1 = (task, params) => {
22225
22227
  return new Promise((resolve, reject) => {
22226
- mockAction$3(task, params).then(resolve).catch(() => {
22228
+ mockAction$2(task, params).then(resolve).catch(() => {
22227
22229
  rpaAction$2(task, params).then(resolve).catch(reject);
22228
22230
  });
22229
22231
  });
@@ -22234,9 +22236,9 @@ const weitoutiaoPublish = async (task, params) => {
22234
22236
  return rpaAction$2(task, params);
22235
22237
  }
22236
22238
  if (params.actionType === "mockApi") {
22237
- return mockAction$3(task, params);
22239
+ return mockAction$2(task, params);
22238
22240
  }
22239
- return executeAction$2(task, params);
22241
+ return executeAction$1(task, params);
22240
22242
  };
22241
22243
 
22242
22244
  const scanRetryMaxCount = 30;
@@ -22246,7 +22248,7 @@ const errnoMap = {
22246
22248
  const saveDraft$1 = (api, params, data) => {
22247
22249
  const formData = new FormData$2();
22248
22250
  for (const [key, value] of Object.entries(data)) {
22249
- formData.append(key, value);
22251
+ formData.append(key, value ?? "");
22250
22252
  }
22251
22253
  return api({
22252
22254
  method: "post",
@@ -22265,7 +22267,7 @@ const saveDraft$1 = (api, params, data) => {
22265
22267
  const safeAssistant = (api, params, data) => {
22266
22268
  const formData = new FormData$2();
22267
22269
  for (const [key, value] of Object.entries(data)) {
22268
- formData.append(key, value);
22270
+ formData.append(key, value ?? "");
22269
22271
  }
22270
22272
  return api({
22271
22273
  method: "post",
@@ -22283,7 +22285,7 @@ const getUuid = async (api, params, data) => {
22283
22285
  const formData = new FormData$2();
22284
22286
  const defaultErrorMsg = "\u7FA4\u53D1\u4E8C\u7EF4\u7801\u83B7\u53D6\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D";
22285
22287
  for (const [key, value] of Object.entries(data)) {
22286
- formData.append(key, value);
22288
+ formData.append(key, value ?? "");
22287
22289
  }
22288
22290
  const res = await api({
22289
22291
  method: "post",
@@ -22304,7 +22306,7 @@ const getUuid = async (api, params, data) => {
22304
22306
  const safeUuid = async (api, params, data) => {
22305
22307
  const formData = new FormData$2();
22306
22308
  for (const [key, value] of Object.entries(data)) {
22307
- formData.append(key, value);
22309
+ formData.append(key, value ?? "");
22308
22310
  }
22309
22311
  const res = await api({
22310
22312
  method: "post",
@@ -22322,7 +22324,7 @@ const massSend = async (api, params, data) => {
22322
22324
  const formData = new FormData$2();
22323
22325
  const defaultErrorMsg = "\u6587\u7AE0\u53D1\u5E03\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D";
22324
22326
  for (const [key, value] of Object.entries(data)) {
22325
- formData.append(key, value);
22327
+ formData.append(key, value ?? "");
22326
22328
  }
22327
22329
  const res = await api({
22328
22330
  method: "post",
@@ -22338,7 +22340,7 @@ const massSend = async (api, params, data) => {
22338
22340
  });
22339
22341
  return res;
22340
22342
  };
22341
- const mockAction$2 = async (task, params) => {
22343
+ const mockAction$1 = async (task, params) => {
22342
22344
  const tmpCachePath = task.getTmpPath();
22343
22345
  const api = axios$1.create({
22344
22346
  headers: {
@@ -22441,7 +22443,7 @@ const mockAction$2 = async (task, params) => {
22441
22443
  reply_flag0: 0,
22442
22444
  not_pay_can_comment0: 0,
22443
22445
  token: params.token,
22444
- AppMsgId: params.appMsgId,
22446
+ AppMsgId: params.appMsgId || "",
22445
22447
  title0: params.title,
22446
22448
  author0: params?.settingInfo?.wxAuthor || "",
22447
22449
  digest0: params?.settingInfo?.wxAbstract || "",
@@ -22558,7 +22560,7 @@ const mockAction$2 = async (task, params) => {
22558
22560
 
22559
22561
  const weixinPublish = async (task, params) => {
22560
22562
  task.logger.info("\u5F00\u59CB\u5FAE\u4FE1\u516C\u4F17\u53F7\u53D1\u5E03");
22561
- return mockAction$2(task, params);
22563
+ return mockAction$1(task, params);
22562
22564
  };
22563
22565
 
22564
22566
  const saveDraft = (api, params, data) => {
@@ -22579,7 +22581,7 @@ const saveDraft = (api, params, data) => {
22579
22581
  data: formData
22580
22582
  });
22581
22583
  };
22582
- const mockAction$1 = async (task, params) => {
22584
+ const mockAction = async (task, params) => {
22583
22585
  const tmpCachePath = task.getTmpPath();
22584
22586
  const api = axios$1.create({
22585
22587
  headers: {
@@ -22760,9 +22762,9 @@ const rpaAction$1 = async (task, params) => {
22760
22762
  }
22761
22763
  };
22762
22764
 
22763
- const executeAction$1 = (task, params) => {
22765
+ const executeAction = (task, params) => {
22764
22766
  return new Promise((resolve, reject) => {
22765
- mockAction$1(task, params).then(resolve).catch(() => {
22767
+ mockAction(task, params).then(resolve).catch(() => {
22766
22768
  rpaAction$1(task, params).then(resolve).catch(reject);
22767
22769
  });
22768
22770
  });
@@ -22773,14 +22775,16 @@ const weixinmpPublish = async (task, params) => {
22773
22775
  return rpaAction$1(task, params);
22774
22776
  }
22775
22777
  if (params.actionType === "mockApi") {
22776
- return mockAction$1(task, params);
22778
+ return mockAction(task, params);
22777
22779
  }
22778
- return executeAction$1(task, params);
22780
+ return executeAction(task, params);
22779
22781
  };
22780
22782
 
22781
- const mockAction = async (_task, _params) => {
22782
- return Promise.reject();
22783
- };
22783
+ var dayjs_min = {exports: {}};
22784
+
22785
+ (function (module, exports) {
22786
+ !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}));
22787
+ } (dayjs_min));
22784
22788
 
22785
22789
  const rpaAction = async (task, params) => {
22786
22790
  const commonCookies = {
@@ -22864,7 +22868,7 @@ const rpaAction = async (task, params) => {
22864
22868
  if (params.address) {
22865
22869
  await selectAddress(
22866
22870
  page.locator(".media-extension .address-input").filter({ hasText: "\u6DFB\u52A0\u5730\u70B9" }),
22867
- params.address
22871
+ params.address.name
22868
22872
  );
22869
22873
  }
22870
22874
  if (params.selfDeclaration) {
@@ -22887,7 +22891,7 @@ const rpaAction = async (task, params) => {
22887
22891
  const selfShootingPopup = await getDialogInstance();
22888
22892
  const hasCustomContent = shootingDate || shootingLocation;
22889
22893
  if (shootingLocation) {
22890
- await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation);
22894
+ await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation.name);
22891
22895
  }
22892
22896
  if (shootingDate) {
22893
22897
  await selectDate(selfShootingPopup.locator(".date-picker input"), shootingDate);
@@ -22929,22 +22933,9 @@ const rpaAction = async (task, params) => {
22929
22933
  return response;
22930
22934
  };
22931
22935
 
22932
- const executeAction = (task, params) => {
22933
- return new Promise((resolve, reject) => {
22934
- mockAction().then(resolve).catch(() => {
22935
- rpaAction(task, params).then(resolve).catch(reject);
22936
- });
22937
- });
22938
- };
22939
22936
  const xiaohongshuPublish = async (task, params) => {
22940
22937
  task.logger.info("\u5F00\u59CB\u5C0F\u7EA2\u4E66\u53D1\u5E03");
22941
- if (params.actionType === "rpa") {
22942
- return rpaAction(task, params);
22943
- }
22944
- if (params.actionType === "mockApi") {
22945
- return mockAction();
22946
- }
22947
- return executeAction(task, params);
22938
+ return rpaAction(task, params);
22948
22939
  };
22949
22940
 
22950
22941
  class Action {
package/dist/index.mjs CHANGED
@@ -937,6 +937,8 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
937
937
  return axiosError;
938
938
  };
939
939
 
940
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
941
+
940
942
  function getDefaultExportFromCjs (x) {
941
943
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
942
944
  }
@@ -21607,7 +21609,7 @@ const errnoMap$2 = {
21607
21609
  2004005714: "\u7F51\u7EDC\u73AF\u5883\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5\u53D1\u5E03\u3002",
21608
21610
  401100032: "\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u56FE\u7247\uFF08\u5982\uFF1A\u683C\u5F0F\u3001\u7248\u6743\u3001\u5408\u89C4\u6027\u7B49\uFF09\u3002"
21609
21611
  };
21610
- const mockAction$5 = async (task, params) => {
21612
+ const mockAction$4 = async (task, params) => {
21611
21613
  const { baijiahaoSingleCover, baijiahaoMultCover, baijiahaoCoverType } = params.settingInfo;
21612
21614
  const tmpCachePath = task.getTmpPath();
21613
21615
  const api = axios$1.create({
@@ -21738,7 +21740,7 @@ const mockAction$5 = async (task, params) => {
21738
21740
 
21739
21741
  const baijiahaoPublish = async (task, params) => {
21740
21742
  task.logger.info("\u5F00\u59CB\u767E\u5BB6\u53F7\u53D1\u5E03");
21741
- return mockAction$5(task, params);
21743
+ return mockAction$4(task, params);
21742
21744
  };
21743
21745
 
21744
21746
  const getBaijiahaoActivity = async (task, params) => {
@@ -21892,7 +21894,7 @@ const get3101DetailError = (errorList, message, saveType) => {
21892
21894
  }
21893
21895
  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");
21894
21896
  };
21895
- const mockAction$4 = async (task, params) => {
21897
+ const mockAction$3 = async (task, params) => {
21896
21898
  const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType, toutiaoOriginal } = params.settingInfo;
21897
21899
  const tmpCachePath = task.getTmpPath();
21898
21900
  const api = axios$1.create({
@@ -22057,10 +22059,10 @@ const mockAction$4 = async (task, params) => {
22057
22059
 
22058
22060
  const toutiaoPublish = async (task, params) => {
22059
22061
  task.logger.info("\u5F00\u59CB\u5934\u6761\u53D1\u5E03");
22060
- return mockAction$4(task, params);
22062
+ return mockAction$3(task, params);
22061
22063
  };
22062
22064
 
22063
- const mockAction$3 = async (task, params) => {
22065
+ const mockAction$2 = async (task, params) => {
22064
22066
  const tmpCachePath = task.getTmpPath();
22065
22067
  const api = axios$1.create({
22066
22068
  headers: {
@@ -22191,9 +22193,9 @@ const rpaAction$2 = async (task, params) => {
22191
22193
  await page.locator(".footer-wrap button.publish-content").click();
22192
22194
  };
22193
22195
 
22194
- const executeAction$2 = (task, params) => {
22196
+ const executeAction$1 = (task, params) => {
22195
22197
  return new Promise((resolve, reject) => {
22196
- mockAction$3(task, params).then(resolve).catch(() => {
22198
+ mockAction$2(task, params).then(resolve).catch(() => {
22197
22199
  rpaAction$2(task, params).then(resolve).catch(reject);
22198
22200
  });
22199
22201
  });
@@ -22204,9 +22206,9 @@ const weitoutiaoPublish = async (task, params) => {
22204
22206
  return rpaAction$2(task, params);
22205
22207
  }
22206
22208
  if (params.actionType === "mockApi") {
22207
- return mockAction$3(task, params);
22209
+ return mockAction$2(task, params);
22208
22210
  }
22209
- return executeAction$2(task, params);
22211
+ return executeAction$1(task, params);
22210
22212
  };
22211
22213
 
22212
22214
  const scanRetryMaxCount = 30;
@@ -22216,7 +22218,7 @@ const errnoMap = {
22216
22218
  const saveDraft$1 = (api, params, data) => {
22217
22219
  const formData = new FormData$2();
22218
22220
  for (const [key, value] of Object.entries(data)) {
22219
- formData.append(key, value);
22221
+ formData.append(key, value ?? "");
22220
22222
  }
22221
22223
  return api({
22222
22224
  method: "post",
@@ -22235,7 +22237,7 @@ const saveDraft$1 = (api, params, data) => {
22235
22237
  const safeAssistant = (api, params, data) => {
22236
22238
  const formData = new FormData$2();
22237
22239
  for (const [key, value] of Object.entries(data)) {
22238
- formData.append(key, value);
22240
+ formData.append(key, value ?? "");
22239
22241
  }
22240
22242
  return api({
22241
22243
  method: "post",
@@ -22253,7 +22255,7 @@ const getUuid = async (api, params, data) => {
22253
22255
  const formData = new FormData$2();
22254
22256
  const defaultErrorMsg = "\u7FA4\u53D1\u4E8C\u7EF4\u7801\u83B7\u53D6\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D";
22255
22257
  for (const [key, value] of Object.entries(data)) {
22256
- formData.append(key, value);
22258
+ formData.append(key, value ?? "");
22257
22259
  }
22258
22260
  const res = await api({
22259
22261
  method: "post",
@@ -22274,7 +22276,7 @@ const getUuid = async (api, params, data) => {
22274
22276
  const safeUuid = async (api, params, data) => {
22275
22277
  const formData = new FormData$2();
22276
22278
  for (const [key, value] of Object.entries(data)) {
22277
- formData.append(key, value);
22279
+ formData.append(key, value ?? "");
22278
22280
  }
22279
22281
  const res = await api({
22280
22282
  method: "post",
@@ -22292,7 +22294,7 @@ const massSend = async (api, params, data) => {
22292
22294
  const formData = new FormData$2();
22293
22295
  const defaultErrorMsg = "\u6587\u7AE0\u53D1\u5E03\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D";
22294
22296
  for (const [key, value] of Object.entries(data)) {
22295
- formData.append(key, value);
22297
+ formData.append(key, value ?? "");
22296
22298
  }
22297
22299
  const res = await api({
22298
22300
  method: "post",
@@ -22308,7 +22310,7 @@ const massSend = async (api, params, data) => {
22308
22310
  });
22309
22311
  return res;
22310
22312
  };
22311
- const mockAction$2 = async (task, params) => {
22313
+ const mockAction$1 = async (task, params) => {
22312
22314
  const tmpCachePath = task.getTmpPath();
22313
22315
  const api = axios$1.create({
22314
22316
  headers: {
@@ -22411,7 +22413,7 @@ const mockAction$2 = async (task, params) => {
22411
22413
  reply_flag0: 0,
22412
22414
  not_pay_can_comment0: 0,
22413
22415
  token: params.token,
22414
- AppMsgId: params.appMsgId,
22416
+ AppMsgId: params.appMsgId || "",
22415
22417
  title0: params.title,
22416
22418
  author0: params?.settingInfo?.wxAuthor || "",
22417
22419
  digest0: params?.settingInfo?.wxAbstract || "",
@@ -22528,7 +22530,7 @@ const mockAction$2 = async (task, params) => {
22528
22530
 
22529
22531
  const weixinPublish = async (task, params) => {
22530
22532
  task.logger.info("\u5F00\u59CB\u5FAE\u4FE1\u516C\u4F17\u53F7\u53D1\u5E03");
22531
- return mockAction$2(task, params);
22533
+ return mockAction$1(task, params);
22532
22534
  };
22533
22535
 
22534
22536
  const saveDraft = (api, params, data) => {
@@ -22549,7 +22551,7 @@ const saveDraft = (api, params, data) => {
22549
22551
  data: formData
22550
22552
  });
22551
22553
  };
22552
- const mockAction$1 = async (task, params) => {
22554
+ const mockAction = async (task, params) => {
22553
22555
  const tmpCachePath = task.getTmpPath();
22554
22556
  const api = axios$1.create({
22555
22557
  headers: {
@@ -22730,9 +22732,9 @@ const rpaAction$1 = async (task, params) => {
22730
22732
  }
22731
22733
  };
22732
22734
 
22733
- const executeAction$1 = (task, params) => {
22735
+ const executeAction = (task, params) => {
22734
22736
  return new Promise((resolve, reject) => {
22735
- mockAction$1(task, params).then(resolve).catch(() => {
22737
+ mockAction(task, params).then(resolve).catch(() => {
22736
22738
  rpaAction$1(task, params).then(resolve).catch(reject);
22737
22739
  });
22738
22740
  });
@@ -22743,14 +22745,16 @@ const weixinmpPublish = async (task, params) => {
22743
22745
  return rpaAction$1(task, params);
22744
22746
  }
22745
22747
  if (params.actionType === "mockApi") {
22746
- return mockAction$1(task, params);
22748
+ return mockAction(task, params);
22747
22749
  }
22748
- return executeAction$1(task, params);
22750
+ return executeAction(task, params);
22749
22751
  };
22750
22752
 
22751
- const mockAction = async (_task, _params) => {
22752
- return Promise.reject();
22753
- };
22753
+ var dayjs_min = {exports: {}};
22754
+
22755
+ (function (module, exports) {
22756
+ !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}));
22757
+ } (dayjs_min));
22754
22758
 
22755
22759
  const rpaAction = async (task, params) => {
22756
22760
  const commonCookies = {
@@ -22834,7 +22838,7 @@ const rpaAction = async (task, params) => {
22834
22838
  if (params.address) {
22835
22839
  await selectAddress(
22836
22840
  page.locator(".media-extension .address-input").filter({ hasText: "\u6DFB\u52A0\u5730\u70B9" }),
22837
- params.address
22841
+ params.address.name
22838
22842
  );
22839
22843
  }
22840
22844
  if (params.selfDeclaration) {
@@ -22857,7 +22861,7 @@ const rpaAction = async (task, params) => {
22857
22861
  const selfShootingPopup = await getDialogInstance();
22858
22862
  const hasCustomContent = shootingDate || shootingLocation;
22859
22863
  if (shootingLocation) {
22860
- await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation);
22864
+ await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation.name);
22861
22865
  }
22862
22866
  if (shootingDate) {
22863
22867
  await selectDate(selfShootingPopup.locator(".date-picker input"), shootingDate);
@@ -22899,22 +22903,9 @@ const rpaAction = async (task, params) => {
22899
22903
  return response;
22900
22904
  };
22901
22905
 
22902
- const executeAction = (task, params) => {
22903
- return new Promise((resolve, reject) => {
22904
- mockAction().then(resolve).catch(() => {
22905
- rpaAction(task, params).then(resolve).catch(reject);
22906
- });
22907
- });
22908
- };
22909
22906
  const xiaohongshuPublish = async (task, params) => {
22910
22907
  task.logger.info("\u5F00\u59CB\u5C0F\u7EA2\u4E66\u53D1\u5E03");
22911
- if (params.actionType === "rpa") {
22912
- return rpaAction(task, params);
22913
- }
22914
- if (params.actionType === "mockApi") {
22915
- return mockAction();
22916
- }
22917
- return executeAction(task, params);
22908
+ return rpaAction(task, params);
22918
22909
  };
22919
22910
 
22920
22911
  class Action {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iflyrpa/actions",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -14,6 +14,7 @@
14
14
  "devDependencies": {
15
15
  "@types/mime-types": "^2.1.4",
16
16
  "axios": "^1.7.8",
17
+ "dayjs": "^1.11.13",
17
18
  "dom-serializer": "^2.0.0",
18
19
  "domhandler": "^5.0.3",
19
20
  "form-data": "^4.0.1",
@@ -19,7 +19,7 @@ const saveDraft = (api: axios.AxiosInstance, params: WeixinPublishParams, data:
19
19
  const formData = new FormData();
20
20
 
21
21
  for (const [key, value] of Object.entries(data)) {
22
- formData.append(key, value);
22
+ formData.append(key, value ?? "");
23
23
  }
24
24
 
25
25
  return api<{ appMsgId: string }>({
@@ -41,7 +41,7 @@ const safeAssistant = (api: axios.AxiosInstance, params: WeixinPublishParams, da
41
41
  const formData = new FormData();
42
42
 
43
43
  for (const [key, value] of Object.entries(data)) {
44
- formData.append(key, value);
44
+ formData.append(key, value ?? "");
45
45
  }
46
46
 
47
47
  return api<{ operation_seq: string; ticket: string }>({
@@ -62,7 +62,7 @@ const getUuid = async (api: axios.AxiosInstance, params: WeixinPublishParams, da
62
62
  const defaultErrorMsg = "群发二维码获取出现问题,请联系客服";
63
63
 
64
64
  for (const [key, value] of Object.entries(data)) {
65
- formData.append(key, value);
65
+ formData.append(key, value ?? "");
66
66
  }
67
67
 
68
68
  const res = await api<{ uuid: string; genuuid_res: number }>({
@@ -88,7 +88,7 @@ const safeUuid = async (api: axios.AxiosInstance, params: WeixinPublishParams, d
88
88
  const formData = new FormData();
89
89
 
90
90
  for (const [key, value] of Object.entries(data)) {
91
- formData.append(key, value);
91
+ formData.append(key, value ?? "");
92
92
  }
93
93
 
94
94
  const res = await api<{ code: string; errcode: number }>({
@@ -110,7 +110,7 @@ const massSend = async (api: axios.AxiosInstance, params: WeixinPublishParams, d
110
110
  const defaultErrorMsg = "文章发布出现问题,请联系客服";
111
111
 
112
112
  for (const [key, value] of Object.entries(data)) {
113
- formData.append(key, value);
113
+ formData.append(key, value ?? "");
114
114
  }
115
115
 
116
116
  const res = await api<{ code: string; errcode: number }>({
@@ -262,7 +262,7 @@ export const mockAction: PublishAction = async (task, params) => {
262
262
  not_pay_can_comment0: 0,
263
263
 
264
264
  token: params.token,
265
- AppMsgId: params.appMsgId,
265
+ AppMsgId: params.appMsgId || "",
266
266
  title0: params.title,
267
267
  author0: params?.settingInfo?.wxAuthor || "",
268
268
  digest0: params?.settingInfo?.wxAbstract || "",
@@ -1,6 +1,6 @@
1
1
  import type { CommonAction, CookiesSetDetails } from "@iflyrpa/share";
2
2
 
3
- import type { ActiomCommonParams } from "../../types";
3
+ import type { ActiomCommonParams, Xiaohongshu } from "../../types";
4
4
  import { mockAction } from "./mock";
5
5
  import { rpaAction } from "./rpa";
6
6
 
@@ -15,7 +15,7 @@ interface AIGenerated {
15
15
  interface SourceStatement {
16
16
  type: "source-statement"; // 内容来源声明
17
17
  childType: "self-labeling" | "self-shooting" | "transshipment"; // 已自主标注 / 自助拍摄 / 转载
18
- shootingLocation?: string; // 拍摄地点
18
+ shootingLocation?: Xiaohongshu.Location; // 拍摄地点
19
19
  shootingDate?: string; // 拍摄日期
20
20
  sourceMedia?: string; // 来源媒体
21
21
  }
@@ -27,7 +27,7 @@ export interface XiaohongshuPublishParams extends Omit<ActiomCommonParams, "cook
27
27
  banners: string[]; // 图片
28
28
  title: string; // 标题
29
29
  content: string; // 正文
30
- address?: string; // 地点
30
+ address?: Xiaohongshu.Location; // 地点
31
31
  selfDeclaration?: SelfDeclaration; // 自主声明
32
32
  visibleRange: "public" | "private"; // 可见范围
33
33
  isImmediatelyPublish?: boolean; // 是否立即发布
@@ -49,13 +49,15 @@ const executeAction: PublishAction = (task, params) => {
49
49
  export const xiaohongshuPublish: PublishAction = async (task, params) => {
50
50
  task.logger.info("开始小红书发布");
51
51
 
52
- if (params.actionType === "rpa") {
53
- return rpaAction(task, params);
54
- }
52
+ return rpaAction(task, params);
55
53
 
56
- if (params.actionType === "mockApi") {
57
- return mockAction(task, params);
58
- }
54
+ // if (params.actionType === "rpa") {
55
+ // return rpaAction(task, params);
56
+ // }
59
57
 
60
- return executeAction(task, params);
58
+ // if (params.actionType === "mockApi") {
59
+ // return mockAction(task, params);
60
+ // }
61
+
62
+ // return executeAction(task, params);
61
63
  };
@@ -1,5 +1,222 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ // import type { CookieMap } from "@iflyrpa/share";
4
+ import { downloadImage, getFilenameFromUrl, sleep } from "@iflyrpa/share";
5
+ import axios, { type AxiosResponse } from "axios";
6
+ import dayjs from "dayjs";
1
7
  import type { PublishAction } from ".";
2
8
 
3
- export const mockAction: PublishAction = async (_task, _params) => {
9
+ interface CommonResponse<T = unknown> {
10
+ data: T;
11
+ code: number;
12
+ success: boolean;
13
+ }
14
+
15
+ interface UploadTempPermit {
16
+ bucket: string;
17
+ fileIds: string[];
18
+ token: string;
19
+ }
20
+
21
+ const errnoMap: Record<number, string> = {};
22
+
23
+ // const commonCookies: CookieMap[number] = {
24
+ // path: "/",
25
+ // sameSite: "lax",
26
+ // secure: false,
27
+ // domain: "xiaohongshu.com",
28
+ // url: "https://creator.xiaohongshu.com",
29
+ // httpOnly: true,
30
+ // };
31
+
32
+ export const mockAction: PublishAction = async (task, params) => {
33
+ // const page = await task.createPage({
34
+ // show: task.debug,
35
+ // url: params.url || "https://creator.xiaohongshu.com/publish/publish",
36
+ // cookies: params.cookies?.map((it) => ({ ...commonCookies, ...it })) || [],
37
+ // });
38
+ const tmpCachePath = task.getTmpPath();
39
+
40
+ await sleep(5000);
41
+
42
+ const fetchCoverArg = `/api/media/v1/upload/creator/permit?biz_name=spectrum&scene=image&file_count=${params.banners.length}&version=1&source=web`;
43
+
44
+ // const xsValue = await page.evaluate(([arg]) => window._webmsxyw(), [fetchCoverArg]);
45
+
46
+ const api = axios.create({
47
+ headers: {
48
+ cookie: params.cookies.map((it) => `${it.name}=${it.value}`).join(";"),
49
+ referer: "https://creator.xiaohongshu.com/publish/publish?source=official&from=tab_switch",
50
+ // "x-s": xsValue["X-s"],
51
+ // "x-t": xsValue["X-t"],
52
+ },
53
+ });
54
+
55
+ // 添加响应拦截器
56
+ api.interceptors.response.use(
57
+ (response: AxiosResponse<CommonResponse>) => {
58
+ const responseData = response.data;
59
+
60
+ // 检查响应中的 errno 字段
61
+ if (responseData?.code && responseData.code !== 0) {
62
+ const errmsg = errnoMap[responseData.code] || response.config.defaultErrorMsg || "Unknown error";
63
+
64
+ task.logger.error(errmsg, responseData);
65
+
66
+ return Promise.reject(new Error(errmsg));
67
+ }
68
+ // 如果 errno 为 0,返回响应数据
69
+ return response;
70
+ },
71
+ (error) => {
72
+ task.logger.error("小红书接口请求失败:", error);
73
+ // 处理响应错误
74
+ return Promise.reject(error);
75
+ },
76
+ );
77
+
78
+ // 0. 获取上传 token
79
+ const coverIdInfo = await api<{ data: { uploadTempPermits: UploadTempPermit[] } }>({
80
+ method: "get",
81
+ url: `https://creator.xiaohongshu.com${fetchCoverArg}`,
82
+ defaultErrorMsg: "获取上传附件 token 失败",
83
+ });
84
+
85
+ const coverIds = coverIdInfo.data.data.uploadTempPermits[0].fileIds;
86
+ const ossToken = coverIdInfo.data.data.uploadTempPermits[0].token;
87
+
88
+ // 1. 上传附件
89
+ const uploadFile = async (url: string, index: number) => {
90
+ const fileName = getFilenameFromUrl(url);
91
+ const localUrl = await downloadImage(url, path.join(tmpCachePath, fileName));
92
+
93
+ const ossFileId = coverIds[index];
94
+ // 读取本地文件,转成 Buffer
95
+ const fileBuffer = fs.readFileSync(localUrl);
96
+
97
+ await api.put(`https://ros-upload.xiaohongshu.com/${ossFileId}`, fileBuffer, {
98
+ headers: {
99
+ "x-cos-security-token": ossToken,
100
+ },
101
+ defaultErrorMsg: "获取上传附件 token 失败",
102
+ });
103
+
104
+ return { ossFileId, ossToken };
105
+ };
106
+
107
+ const coverInfos = await Promise.all(params.banners.map((it, idx) => uploadFile(it, idx)));
108
+
109
+ const publishData = {
110
+ common: {
111
+ ats: [],
112
+ biz_relations: [],
113
+ desc: params?.content,
114
+ goods_info: {},
115
+ hash_tag: [],
116
+ note_id: "",
117
+ source: JSON.stringify({
118
+ type: "web",
119
+ ids: "",
120
+ extraInfo: '{"systemId":"web"}',
121
+ }),
122
+ title: params?.title,
123
+ type: "normal",
124
+ privacy_info: {
125
+ op_type: 1,
126
+ type: params.visibleRange === "public" ? 0 : 1,
127
+ },
128
+ post_loc: params.address
129
+ ? {
130
+ name: params.address?.name,
131
+ poi_id: params.address?.poi_id,
132
+ poi_type: params.address?.poi_type,
133
+ subname: params.address?.full_address,
134
+ }
135
+ : null,
136
+ business_binds: "",
137
+ },
138
+ image_info: {
139
+ images: coverInfos.map((it) => ({
140
+ extra_info_json: '{"mimeType":"image/png"}',
141
+ file_id: it.ossFileId,
142
+ metadata: {
143
+ source: -1,
144
+ },
145
+ stickers: {
146
+ floating: [],
147
+ version: 2,
148
+ },
149
+ })),
150
+ },
151
+ video_info: null,
152
+ };
153
+
154
+ // 自主声明
155
+ const userDeclarationBind = {
156
+ origin: 2,
157
+ photoInfo: {},
158
+ repostInfo: {},
159
+ };
160
+
161
+ if (params.selfDeclaration?.type === "fictional-rendition") {
162
+ // 虚拟演绎,仅供娱乐
163
+ userDeclarationBind.origin = 1;
164
+ } else if (params.selfDeclaration?.type === "ai-generated") {
165
+ // 笔记含AI合成内容
166
+ userDeclarationBind.origin = 2;
167
+ } else if (params.selfDeclaration?.type === "source-statement") {
168
+ // 内容来源声明
169
+ if (params.selfDeclaration.childType === "self-labeling") {
170
+ // 已自主标注
171
+ userDeclarationBind.origin = 3;
172
+ } else if (params.selfDeclaration.childType === "self-shooting") {
173
+ // 自主拍摄
174
+ userDeclarationBind.origin = 4;
175
+ const photoInfo: { photoPlace?: unknown; photoTime?: string } = {};
176
+
177
+ if (params.selfDeclaration.shootingLocation) {
178
+ // 拍摄地点
179
+ photoInfo.photoPlace = {
180
+ name: params.selfDeclaration.shootingLocation.name,
181
+ poiId: params.selfDeclaration.shootingLocation.poi_id,
182
+ poiType: params.selfDeclaration.shootingLocation.poi_type,
183
+ subname: params.selfDeclaration.shootingLocation.full_address,
184
+ };
185
+ }
186
+
187
+ if (params.selfDeclaration.shootingDate) {
188
+ // 拍摄日期
189
+ photoInfo.photoTime = params.selfDeclaration.shootingDate;
190
+ }
191
+
192
+ userDeclarationBind.photoInfo = photoInfo;
193
+ } else if (params.selfDeclaration.childType === "transshipment") {
194
+ // 来源转载
195
+ userDeclarationBind.origin = 5;
196
+
197
+ if (params.selfDeclaration.sourceMedia) {
198
+ // 来源媒体
199
+ userDeclarationBind.repostInfo = {
200
+ source: params.selfDeclaration.sourceMedia,
201
+ };
202
+ }
203
+ }
204
+ }
205
+
206
+ const business_binds = {
207
+ version: 1,
208
+ bizType: "",
209
+ noteId: "",
210
+ noteOrderBind: {},
211
+ // 发布时间 - 立即发布
212
+ notePostTiming: params.isImmediatelyPublish ? { postTime: dayjs().format("YYYY-MM-DD HH:mm") } : {},
213
+ noteCollectionBind: { id: "" },
214
+ ...(params.selfDeclaration ? { userDeclarationBind } : {}),
215
+ };
216
+
217
+ publishData.common.business_binds = JSON.stringify(business_binds);
218
+
219
+ console.log(publishData);
220
+
4
221
  return Promise.reject();
5
222
  };
@@ -127,7 +127,7 @@ export const rpaAction: PublishAction = async (task, params) => {
127
127
  // 填写地点
128
128
  await selectAddress(
129
129
  page.locator(".media-extension .address-input").filter({ hasText: "添加地点" }),
130
- params.address,
130
+ params.address.name,
131
131
  );
132
132
  }
133
133
 
@@ -157,7 +157,7 @@ export const rpaAction: PublishAction = async (task, params) => {
157
157
 
158
158
  // 选择拍摄地点
159
159
  if (shootingLocation) {
160
- await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation);
160
+ await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation.name);
161
161
  }
162
162
  // 选择拍摄日期
163
163
  if (shootingDate) {
@@ -0,0 +1,7 @@
1
+ export {}; // 确保文件作为一个模块导出 (否则会出现类型污染)
2
+
3
+ declare global {
4
+ interface Window {
5
+ _webmsxyw: (arg?: string, arg1?: string) => { "X-s": string; "X-t": number };
6
+ }
7
+ }
package/src/types.ts CHANGED
@@ -66,6 +66,6 @@ export namespace Xiaohongshu {
66
66
  name: string;
67
67
  poi_id: string;
68
68
  poi_type: number;
69
- type: "location";
69
+ type: string;
70
70
  }
71
71
  }