@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 +284 -41
- package/dist/index.mjs +283 -41
- package/package.json +1 -2
- package/src/actions/weitoutiaoPublish/index.ts +3 -13
- package/src/actions/weixinmpPublish/index.ts +3 -13
- package/src/actions/xiaohongshuPublish/index.ts +8 -19
- package/src/actions/xiaohongshuPublish/mock.ts +40 -38
- package/src/utils/index.ts +51 -0
- package/src/utils/xhsXsEncrypt.ts +103 -0
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
21942
|
-
errmsg = get3101DetailError(errnoMap$
|
|
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$
|
|
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$
|
|
22107
|
+
return mockAction$4(task, params);
|
|
22093
22108
|
};
|
|
22094
22109
|
|
|
22095
|
-
const mockAction$
|
|
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$
|
|
22247
|
+
return mockAction$3(task, params);
|
|
22240
22248
|
}
|
|
22241
|
-
return executeAction$
|
|
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$
|
|
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$
|
|
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
|
|
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
|
-
|
|
22787
|
-
|
|
22788
|
-
|
|
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
|
-
|
|
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 {
|