@iflyrpa/actions 4.0.0-beta.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +314 -100
- package/dist/bundle.js.map +1 -1
- package/dist/index.js +313 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +313 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -5434,7 +5434,9 @@ function __webpack_require__(moduleId) {
|
|
|
5434
5434
|
return module;
|
|
5435
5435
|
};
|
|
5436
5436
|
})();
|
|
5437
|
-
var package_namespaceObject =
|
|
5437
|
+
var package_namespaceObject = {
|
|
5438
|
+
i8: "3.1.1"
|
|
5439
|
+
};
|
|
5438
5440
|
var dist = __webpack_require__("../../node_modules/.pnpm/https-proxy-agent@7.0.6/node_modules/https-proxy-agent/dist/index.js");
|
|
5439
5441
|
async function ProxyAgent(task, ip, adr, accountId, refresh) {
|
|
5440
5442
|
const http = new Http({
|
|
@@ -5520,7 +5522,8 @@ class Http {
|
|
|
5520
5522
|
url: error.config?.url,
|
|
5521
5523
|
isProxyRequest: !!(error.config && (error.config.httpAgent || error.config.httpsAgent)),
|
|
5522
5524
|
params: error.config?.params,
|
|
5523
|
-
data: error.config?.data
|
|
5525
|
+
data: error.config?.data,
|
|
5526
|
+
serverDate: error.response?.headers?.date
|
|
5524
5527
|
}
|
|
5525
5528
|
};
|
|
5526
5529
|
if (foundError) Object.assign(errorResponse, foundError);
|
|
@@ -5598,7 +5601,7 @@ class Http {
|
|
|
5598
5601
|
try {
|
|
5599
5602
|
this.proxyInfo = agent ? `${agent.ip}:${agent.port}` : void 0;
|
|
5600
5603
|
const controller = new AbortController();
|
|
5601
|
-
const timeoutId = setTimeout(()=>controller.abort(), reqTimeout);
|
|
5604
|
+
const timeoutId = setTimeout(()=>controller.abort(), reqTimeout + 500);
|
|
5602
5605
|
const response = await this.apiClient({
|
|
5603
5606
|
...config,
|
|
5604
5607
|
timeout: reqTimeout,
|
|
@@ -5622,7 +5625,7 @@ class Http {
|
|
|
5622
5625
|
599
|
|
5623
5626
|
].includes(handledError.code);
|
|
5624
5627
|
if (Rtimes < retries && isRetry) {
|
|
5625
|
-
this.logger?.info(`进入第${Rtimes + 1}
|
|
5628
|
+
this.logger?.info(`进入第${Rtimes + 1}次重试!错误码: ${handledError.code}`);
|
|
5626
5629
|
await new Promise((resolve)=>setTimeout(resolve, retryDelay));
|
|
5627
5630
|
return sessionRt(Rtimes + 1);
|
|
5628
5631
|
}
|
|
@@ -9837,23 +9840,26 @@ const rpaServer = async (task, params)=>{
|
|
|
9837
9840
|
};
|
|
9838
9841
|
}
|
|
9839
9842
|
case types_ExecutionState.SUCCESS:
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9843
|
+
{
|
|
9844
|
+
const cookie = JSON.stringify(await task.steelBrowserContext?.cookies());
|
|
9845
|
+
await updateTaskState?.({
|
|
9846
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.SUCCESS,
|
|
9847
|
+
result: {
|
|
9848
|
+
cookie,
|
|
9849
|
+
token,
|
|
9850
|
+
userInfo: userInfo
|
|
9851
|
+
}
|
|
9852
|
+
});
|
|
9853
|
+
return {
|
|
9854
|
+
code: 0,
|
|
9855
|
+
message: "成功",
|
|
9856
|
+
data: {
|
|
9857
|
+
cookie,
|
|
9858
|
+
token,
|
|
9859
|
+
userInfo
|
|
9860
|
+
}
|
|
9861
|
+
};
|
|
9862
|
+
}
|
|
9857
9863
|
default:
|
|
9858
9864
|
return {
|
|
9859
9865
|
code: 500,
|
|
@@ -10027,6 +10033,16 @@ const mockAction = async (task, params)=>{
|
|
|
10027
10033
|
const images = _images.filter((url)=>!!url && "" !== url.trim());
|
|
10028
10034
|
return await Promise.all(images.map(async (url)=>{
|
|
10029
10035
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
10036
|
+
const ext = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(fileName).toLowerCase();
|
|
10037
|
+
if (![
|
|
10038
|
+
".jpg",
|
|
10039
|
+
".jpeg",
|
|
10040
|
+
".png"
|
|
10041
|
+
].includes(ext)) throw {
|
|
10042
|
+
code: 414,
|
|
10043
|
+
message: `图片格式不支持:${fileName}。百家号仅支持 jpg、png 格式,请转换后重试。`,
|
|
10044
|
+
data: ""
|
|
10045
|
+
};
|
|
10030
10046
|
const image = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
10031
10047
|
const formData = new __WEBPACK_EXTERNAL_MODULE_form_data_cf000082__["default"]();
|
|
10032
10048
|
formData.append("org_file_name", fileName);
|
|
@@ -10210,20 +10226,11 @@ const mockAction = async (task, params)=>{
|
|
|
10210
10226
|
};
|
|
10211
10227
|
const rpa_rpaAction = async (task, params)=>{
|
|
10212
10228
|
const tmpCachePath = task.getTmpPath();
|
|
10213
|
-
const
|
|
10214
|
-
path: "/",
|
|
10215
|
-
secure: true,
|
|
10216
|
-
domain: "baijiahao.baidu.com",
|
|
10217
|
-
url: "https://baijiahao.baidu.com",
|
|
10218
|
-
httpOnly: true
|
|
10219
|
-
};
|
|
10229
|
+
const validCookies = (params.cookies || []).filter((it)=>it.name && it.value && "undefined" !== it.value);
|
|
10220
10230
|
const page = await task.createPage({
|
|
10221
10231
|
show: task.debug,
|
|
10222
10232
|
url: params.url || "https://baijiahao.baidu.com/builder/rc/edit?type=news&is_from_cms=1",
|
|
10223
|
-
cookies:
|
|
10224
|
-
...it,
|
|
10225
|
-
...commonCookies
|
|
10226
|
-
})) || []
|
|
10233
|
+
cookies: validCookies
|
|
10227
10234
|
});
|
|
10228
10235
|
page.setDefaultTimeout(60000);
|
|
10229
10236
|
page.setDefaultNavigationTimeout(60000);
|
|
@@ -10628,6 +10635,7 @@ const BaijiahaoPublishParamsSchema = ActionCommonParamsSchema.extend({
|
|
|
10628
10635
|
})
|
|
10629
10636
|
});
|
|
10630
10637
|
const baijiahaoPublish = async (task, params)=>{
|
|
10638
|
+
task.logger.info(`baijiahaoPublish actionType: ${params.actionType}`);
|
|
10631
10639
|
params.content = formatSectionHtml(params.content);
|
|
10632
10640
|
if ("rpa" === params.actionType) return rpa_rpaAction(task, params);
|
|
10633
10641
|
if ("mockApi" === params.actionType) return mockAction(task, params);
|
|
@@ -11756,6 +11764,8 @@ class Xhshow {
|
|
|
11756
11764
|
}
|
|
11757
11765
|
new Xhshow();
|
|
11758
11766
|
const sessionCheck_xsEncrypt = new Xhshow();
|
|
11767
|
+
let lastEnvLogTime = 0;
|
|
11768
|
+
const ENV_LOG_INTERVAL_MS = 5000;
|
|
11759
11769
|
const SessionCheckResultSchema = schemas_object({
|
|
11760
11770
|
isValidSession: schemas_boolean()
|
|
11761
11771
|
});
|
|
@@ -11820,6 +11830,23 @@ const WxSessionCheck = async (_task, params)=>{
|
|
|
11820
11830
|
}, "微信账号有效性检测完成!");
|
|
11821
11831
|
};
|
|
11822
11832
|
const XhsSessionCheck = async (_task, params)=>{
|
|
11833
|
+
const now = Date.now();
|
|
11834
|
+
const shouldLogEnv = now - lastEnvLogTime >= ENV_LOG_INTERVAL_MS;
|
|
11835
|
+
if (shouldLogEnv) {
|
|
11836
|
+
lastEnvLogTime = now;
|
|
11837
|
+
_task.logger?.debug("[XhsSessionCheck] 环境信息", {
|
|
11838
|
+
processType: process.type,
|
|
11839
|
+
pid: process.pid,
|
|
11840
|
+
nodeVersion: process.version,
|
|
11841
|
+
platform: process.platform,
|
|
11842
|
+
memoryUsage: {
|
|
11843
|
+
heapUsed: `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)} MB`,
|
|
11844
|
+
heapTotal: `${Math.round(process.memoryUsage().heapTotal / 1024 / 1024)} MB`
|
|
11845
|
+
},
|
|
11846
|
+
accountId: params.accountId,
|
|
11847
|
+
hasProxy: !!(params.proxyLoc || params.localIP)
|
|
11848
|
+
});
|
|
11849
|
+
}
|
|
11823
11850
|
const check = {
|
|
11824
11851
|
isValidSession: false,
|
|
11825
11852
|
isValidWebSession: false
|
|
@@ -11856,7 +11883,32 @@ const XhsSessionCheck = async (_task, params)=>{
|
|
|
11856
11883
|
if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
|
|
11857
11884
|
return acc;
|
|
11858
11885
|
}, {});
|
|
11859
|
-
|
|
11886
|
+
let loginBaseXsHeader;
|
|
11887
|
+
try {
|
|
11888
|
+
loginBaseXsHeader = sessionCheck_xsEncrypt.signHeadersGet(loginBasePath, recordCookie, "xhs-pc-web", null);
|
|
11889
|
+
} catch (signError) {
|
|
11890
|
+
_task.logger?.error("[XhsSessionCheck] 签名生成失败 - 环境快照", {
|
|
11891
|
+
accountId: params.accountId,
|
|
11892
|
+
error: signError instanceof Error ? signError.message : String(signError),
|
|
11893
|
+
stack: _task.debug ? signError instanceof Error ? signError.stack : void 0 : void 0,
|
|
11894
|
+
hasA1: !!recordCookie.a1,
|
|
11895
|
+
env: {
|
|
11896
|
+
processType: process.type,
|
|
11897
|
+
memoryUsage: {
|
|
11898
|
+
heapUsed: `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)} MB`,
|
|
11899
|
+
heapTotal: `${Math.round(process.memoryUsage().heapTotal / 1024 / 1024)} MB`
|
|
11900
|
+
},
|
|
11901
|
+
hasProxy: !!(params.proxyLoc || params.localIP),
|
|
11902
|
+
timeSinceLastLog: Date.now() - lastEnvLogTime
|
|
11903
|
+
}
|
|
11904
|
+
});
|
|
11905
|
+
return {
|
|
11906
|
+
code: 500,
|
|
11907
|
+
message: "账号签名生成失败,请稍后重试。",
|
|
11908
|
+
data: check
|
|
11909
|
+
};
|
|
11910
|
+
}
|
|
11911
|
+
const baseInfoStart = Date.now();
|
|
11860
11912
|
const _baseInfo = http.api({
|
|
11861
11913
|
method: "get",
|
|
11862
11914
|
baseURL: "https://creator.xiaohongshu.com",
|
|
@@ -11865,23 +11917,43 @@ const XhsSessionCheck = async (_task, params)=>{
|
|
|
11865
11917
|
}, {
|
|
11866
11918
|
retries: 3,
|
|
11867
11919
|
retryDelay: 20,
|
|
11868
|
-
timeout:
|
|
11869
|
-
}).catch((e)=>
|
|
11920
|
+
timeout: 5000
|
|
11921
|
+
}).catch((e)=>{
|
|
11922
|
+
const clientTimestamp = Date.now();
|
|
11923
|
+
const serverDate = e?.extra?.serverDate;
|
|
11924
|
+
const serverTimestamp = serverDate ? new Date(serverDate).getTime() : null;
|
|
11925
|
+
const timeDriftMs = serverTimestamp ? clientTimestamp - serverTimestamp : null;
|
|
11926
|
+
_task.logger?.warn("[XhsSessionCheck] creator base 接口请求失败", {
|
|
11927
|
+
accountId: params.accountId,
|
|
11928
|
+
duration: Date.now() - baseInfoStart,
|
|
11929
|
+
code: e?.code,
|
|
11930
|
+
message: e?.message,
|
|
11931
|
+
data: e?.data,
|
|
11932
|
+
extra: e?.extra,
|
|
11933
|
+
proxyInfo: http.proxyInfo,
|
|
11934
|
+
clientTimestamp,
|
|
11935
|
+
serverDate,
|
|
11936
|
+
serverTimestamp,
|
|
11937
|
+
timeDriftMs,
|
|
11938
|
+
isLikelyClockDrift: null !== timeDriftMs && Math.abs(timeDriftMs) > 300000
|
|
11939
|
+
});
|
|
11940
|
+
return e.data;
|
|
11941
|
+
});
|
|
11870
11942
|
const _web_session = http.api({
|
|
11871
11943
|
method: "get",
|
|
11872
11944
|
url: "https://edith.xiaohongshu.com/api/sns/web/unread_count"
|
|
11873
11945
|
}, {
|
|
11874
11946
|
retries: 3,
|
|
11875
11947
|
retryDelay: 20,
|
|
11876
|
-
timeout:
|
|
11948
|
+
timeout: 5000
|
|
11877
11949
|
});
|
|
11878
11950
|
const [baseInfo, web_session] = await Promise.all([
|
|
11879
11951
|
_baseInfo,
|
|
11880
11952
|
_web_session
|
|
11881
11953
|
]);
|
|
11882
11954
|
if (baseInfo?.code === 0) check.isValidSession = true;
|
|
11883
|
-
if (
|
|
11884
|
-
baseInfo?.code, web_session
|
|
11955
|
+
if (web_session?.code === 0) check.isValidWebSession = true;
|
|
11956
|
+
baseInfo?.code, web_session?.code;
|
|
11885
11957
|
const message = `小红书账号有效性检测成功${_task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
11886
11958
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(check, message);
|
|
11887
11959
|
};
|
|
@@ -14326,9 +14398,7 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14326
14398
|
msToken: params.cookies.find((e)=>"msToken" === e.name)?.value || "",
|
|
14327
14399
|
a_bogus: ""
|
|
14328
14400
|
};
|
|
14329
|
-
task.logger.
|
|
14330
|
-
publishParams
|
|
14331
|
-
});
|
|
14401
|
+
task.logger.info(`[douyinPublish] publishParams ${JSON.stringify(publishParams)}`);
|
|
14332
14402
|
const publishData = {
|
|
14333
14403
|
item: {
|
|
14334
14404
|
common: {
|
|
@@ -14404,21 +14474,21 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14404
14474
|
}
|
|
14405
14475
|
publishData.item.common.creation_id = generateRandomString(8) + Date.now();
|
|
14406
14476
|
let decision = null;
|
|
14407
|
-
task.logger.info(`proxyHttp 代理信息: ${proxyHttp.proxyInfo} `);
|
|
14477
|
+
task.logger.info(`[douyinPublish] proxyHttp 代理信息: ${proxyHttp.proxyInfo} `);
|
|
14408
14478
|
proxyHttp.addResponseInterceptor((response)=>{
|
|
14409
14479
|
console.log("拦截器收到响应:", JSON.stringify(response.data));
|
|
14410
|
-
task.logger.
|
|
14411
|
-
task.logger.
|
|
14480
|
+
task.logger.warn(`[douyinPublish] 拦截器收到响应response.headers: ${JSON.stringify(response.headers)} `);
|
|
14481
|
+
task.logger.warn(`[douyinPublish] 拦截器收到响应response.data: ${JSON.stringify(response.data)} `);
|
|
14412
14482
|
decision = parseVerifyPassportDecision(response.headers["x-tt-verify-passport-decision"]);
|
|
14413
14483
|
if (needsVerification(decision)) {
|
|
14414
|
-
task.logger.
|
|
14484
|
+
task.logger.warn(`[douyinPublish] 检测到需要验证: ${JSON.stringify(decision)}`);
|
|
14415
14485
|
return;
|
|
14416
14486
|
}
|
|
14417
14487
|
if (!response || !response.data) return;
|
|
14418
14488
|
const responseData = response.data;
|
|
14419
14489
|
if (response && responseData?.status_code && 0 !== responseData.status_code) {
|
|
14420
14490
|
const errorCode = 4 === responseData.status_code ? 500 : responseData.status_code;
|
|
14421
|
-
if (4 === responseData.status_code) task.logger.warn(
|
|
14491
|
+
if (4 === responseData.status_code) task.logger.warn(`[douyinPublish] 抖音服务器错误 status_code: 4,映射为 500 触发重试。原始响应: ${JSON.stringify(responseData)}`);
|
|
14422
14492
|
return {
|
|
14423
14493
|
code: errorCode,
|
|
14424
14494
|
message: responseData.status_msg || "文章发布异常,请稍后重试。",
|
|
@@ -14438,42 +14508,120 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14438
14508
|
});
|
|
14439
14509
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(0, message, data);
|
|
14440
14510
|
}
|
|
14441
|
-
|
|
14442
|
-
|
|
14443
|
-
|
|
14444
|
-
|
|
14445
|
-
|
|
14511
|
+
let webProtectData;
|
|
14512
|
+
try {
|
|
14513
|
+
webProtectData = JSON.parse(JSON.parse(params.extraParam["security-sdk/s_sdk_sign_data_key/web_protect"] || "{}").data || "{}");
|
|
14514
|
+
if (!webProtectData.ticket || !webProtectData.ts_sign || !webProtectData.client_cert) {
|
|
14515
|
+
task.logger.error(`webProtectData 关键字段缺失: ${JSON.stringify(webProtectData)}`);
|
|
14516
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 webProtectData 不完整,请重新获取后重试", "");
|
|
14517
|
+
}
|
|
14518
|
+
} catch (error) {
|
|
14519
|
+
task.logger.error(`解析 webProtectData 失败: ${error}`);
|
|
14520
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 webProtectData 解析失败,请重新获取后重试", "");
|
|
14521
|
+
}
|
|
14522
|
+
let ticket = webProtectData.ticket;
|
|
14523
|
+
let ts_sign = webProtectData.ts_sign;
|
|
14524
|
+
const serverDataCookie = params.cookies.find((it)=>"bd_ticket_guard_server_data" === it.name)?.value;
|
|
14525
|
+
if (serverDataCookie) try {
|
|
14526
|
+
const decoded = JSON.parse(Buffer.from(decodeURIComponent(serverDataCookie), "base64").toString("utf8"));
|
|
14527
|
+
if (decoded.ticket && decoded.ts_sign) {
|
|
14528
|
+
if (decoded.ticket !== ticket) task.logger.info("[douyinPublish] 使用 cookie 中的最新 ticket(web_protect 已过期)");
|
|
14529
|
+
ticket = decoded.ticket;
|
|
14530
|
+
ts_sign = decoded.ts_sign;
|
|
14531
|
+
}
|
|
14532
|
+
} catch (error) {
|
|
14533
|
+
task.logger.warn(`解析 bd_ticket_guard_server_data 失败,回退到 web_protect: ${error}`);
|
|
14534
|
+
}
|
|
14535
|
+
let ec_privateKey;
|
|
14536
|
+
try {
|
|
14537
|
+
ec_privateKey = JSON.parse(JSON.parse(params.extraParam["security-sdk/s_sdk_crypt_sdk"] || "{}").data || "{}").ec_privateKey;
|
|
14538
|
+
if (!ec_privateKey) {
|
|
14539
|
+
task.logger.error("ec_privateKey 为空");
|
|
14540
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 ec_privateKey 缺失,请重新获取后重试", "");
|
|
14541
|
+
}
|
|
14542
|
+
} catch (error) {
|
|
14543
|
+
task.logger.error(`解析 ec_privateKey 失败: ${error}`);
|
|
14544
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 ec_privateKey 解析失败,请重新获取后重试", "");
|
|
14545
|
+
}
|
|
14546
|
+
let certificate;
|
|
14547
|
+
try {
|
|
14548
|
+
certificate = JSON.parse(params.extraParam["security-sdk/s_sdk_server_cert_key"] || "{}").cert;
|
|
14549
|
+
if (!certificate) {
|
|
14550
|
+
task.logger.error("certificate 为空");
|
|
14551
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 certificate 缺失,请重新获取后重试", "");
|
|
14552
|
+
}
|
|
14553
|
+
} catch (error) {
|
|
14554
|
+
task.logger.error(`解析 certificate 失败: ${error}`);
|
|
14555
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 certificate 解析失败,请重新获取后重试", "");
|
|
14556
|
+
}
|
|
14446
14557
|
const ree_public_key = webProtectData.client_cert.replace("pub.", "");
|
|
14447
|
-
task.logger.info(`生成 bdTicketGuardClientData 的参数: ticket: ${ticket
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14451
|
-
|
|
14452
|
-
|
|
14453
|
-
|
|
14454
|
-
|
|
14455
|
-
|
|
14456
|
-
|
|
14457
|
-
|
|
14558
|
+
task.logger.info(`生成 bdTicketGuardClientData 的参数: ticket: ${ticket?.substring(0, 20)}..., ts_sign: ${ts_sign}, ree_public_key: ${ree_public_key?.substring(0, 20)}...`);
|
|
14559
|
+
let bdTicketGuardClientData;
|
|
14560
|
+
try {
|
|
14561
|
+
bdTicketGuardClientData = getBdV2({
|
|
14562
|
+
ticket,
|
|
14563
|
+
ts_sign: ts_sign,
|
|
14564
|
+
ec_privateKey: ec_privateKey,
|
|
14565
|
+
certificate: certificate,
|
|
14566
|
+
bd_ticket_guard_ree_public_key: ree_public_key
|
|
14567
|
+
});
|
|
14568
|
+
if (!bdTicketGuardClientData || !bdTicketGuardClientData["headers_bd_ticket_guard_client_data"]) {
|
|
14569
|
+
task.logger.error(`bdTicketGuardClientData 生成失败或不完整: ${JSON.stringify(bdTicketGuardClientData)}`);
|
|
14570
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 bdTicketGuardClientData 生成失败,请重新获取后重试", "");
|
|
14571
|
+
}
|
|
14572
|
+
} catch (error) {
|
|
14573
|
+
task.logger.error(`生成 bdTicketGuardClientData 失败: ${error}`);
|
|
14574
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 bdTicketGuardClientData 生成异常,请重新获取后重试", "");
|
|
14575
|
+
}
|
|
14576
|
+
task.logger.info("bdTicketGuardClientData 生成成功");
|
|
14458
14577
|
const publishQuery = {
|
|
14459
14578
|
...publishParams,
|
|
14460
14579
|
a_bogus: ""
|
|
14461
14580
|
};
|
|
14462
14581
|
const queryString = new URLSearchParams(publishQuery).toString();
|
|
14463
|
-
|
|
14582
|
+
let aBogus;
|
|
14583
|
+
try {
|
|
14584
|
+
aBogus = mock_getABogus(`https://creator.douyin.com/web/api/media/aweme/create_v2/?${queryString}`, publishData, userAgent);
|
|
14585
|
+
if (!aBogus || aBogus.length < 10) {
|
|
14586
|
+
task.logger.error(`a_bogus 生成异常,长度过短: ${aBogus}`);
|
|
14587
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 a_bogus 生成失败,请重试", "");
|
|
14588
|
+
}
|
|
14589
|
+
task.logger.info(`a_bogus 生成成功: ${aBogus.substring(0, 20)}...`);
|
|
14590
|
+
} catch (error) {
|
|
14591
|
+
task.logger.error(`生成 a_bogus 失败: ${error}`);
|
|
14592
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 a_bogus 生成异常,请重试", "");
|
|
14593
|
+
}
|
|
14464
14594
|
publishQuery.a_bogus = aBogus;
|
|
14465
14595
|
const publishQueryParams = new URLSearchParams(publishQuery).toString();
|
|
14466
|
-
|
|
14467
|
-
|
|
14468
|
-
|
|
14469
|
-
|
|
14470
|
-
|
|
14471
|
-
|
|
14472
|
-
|
|
14473
|
-
|
|
14596
|
+
let csrfToken;
|
|
14597
|
+
try {
|
|
14598
|
+
csrfToken = mock_generateCsrfTokenAdvanced({
|
|
14599
|
+
cookies: params.cookies,
|
|
14600
|
+
url: "https://creator.douyin.com/web/api/media/aweme/create_v2/",
|
|
14601
|
+
method: "POST",
|
|
14602
|
+
userAgent
|
|
14603
|
+
});
|
|
14604
|
+
if (!csrfToken || csrfToken.length < 10) {
|
|
14605
|
+
task.logger.error(`csrfToken 生成异常,长度过短: ${csrfToken}`);
|
|
14606
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 csrfToken 生成失败,请重试", "");
|
|
14607
|
+
}
|
|
14608
|
+
task.logger.info(`csrfToken 生成成功: ${csrfToken.substring(0, 20)}...`);
|
|
14609
|
+
} catch (error) {
|
|
14610
|
+
task.logger.error(`生成 csrfToken 失败: ${error}`);
|
|
14611
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 csrfToken 生成异常,请重试", "");
|
|
14612
|
+
}
|
|
14613
|
+
let sessionDtrait;
|
|
14614
|
+
try {
|
|
14615
|
+
sessionDtrait = mock_generateDtrait("/web/api/media/aweme/create_v2/");
|
|
14616
|
+
task.logger.info(`sessionDtrait 生成成功: ${sessionDtrait || "(空)"}`);
|
|
14617
|
+
} catch (error) {
|
|
14618
|
+
task.logger.error(`生成 sessionDtrait 失败: ${error}`);
|
|
14619
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "安全参数 sessionDtrait 生成异常,请重试", "");
|
|
14620
|
+
}
|
|
14621
|
+
task.logger.info("[douyinPublish] 发布数据", {
|
|
14474
14622
|
data: JSON.stringify(publishData)
|
|
14475
14623
|
});
|
|
14476
|
-
task.logger.info(`headers: ${JSON.stringify({
|
|
14624
|
+
task.logger.info(`[douyinPublish] headers: ${JSON.stringify({
|
|
14477
14625
|
...headers,
|
|
14478
14626
|
Referer: "https://creator.douyin.com/creator-micro/content/post/image?default-tab=3&enter_from=publish_page&media_type=image&type=new",
|
|
14479
14627
|
"Content-Type": "application/json",
|
|
@@ -14486,8 +14634,7 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14486
14634
|
"x-secsdk-csrf-token": csrfToken,
|
|
14487
14635
|
"x-tt-session-dtrait": sessionDtrait || ""
|
|
14488
14636
|
})}`);
|
|
14489
|
-
task.logger.info(`
|
|
14490
|
-
task.logger.info(`url: https://creator.douyin.com/web/api/media/aweme/create_v2/?${publishQueryParams}`);
|
|
14637
|
+
task.logger.info(`[douyinPublish] url: https://creator.douyin.com/web/api/media/aweme/create_v2/?${publishQueryParams}`);
|
|
14491
14638
|
const publishResult = await proxyHttp.api({
|
|
14492
14639
|
method: "post",
|
|
14493
14640
|
url: `https://creator.douyin.com/web/api/media/aweme/create_v2/?${publishQueryParams}`,
|
|
@@ -14511,8 +14658,7 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14511
14658
|
retries: 3,
|
|
14512
14659
|
retryDelay: 2000
|
|
14513
14660
|
});
|
|
14514
|
-
task.logger.info(
|
|
14515
|
-
task.logger.info(`decision值: ${JSON.stringify(decision)}, needsVerification(decision): ${needsVerification(decision)}`);
|
|
14661
|
+
task.logger.info(`[douyinPublish] decision值: ${JSON.stringify(decision)}, needsVerification(decision): ${needsVerification(decision)}`);
|
|
14516
14662
|
if (needsVerification(decision)) {
|
|
14517
14663
|
const details = [
|
|
14518
14664
|
publishResult.status_msg,
|
|
@@ -14520,7 +14666,6 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14520
14666
|
decision?.verify_desc
|
|
14521
14667
|
].filter(Boolean).join(" ");
|
|
14522
14668
|
const message = `图文发布失败,原因:${details}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
14523
|
-
task.logger.warn(`TaskId:${task.taskId},检测到需要验证,准备返回验证信息`);
|
|
14524
14669
|
let decisionObj = {};
|
|
14525
14670
|
if (decision) decisionObj = decision;
|
|
14526
14671
|
const mockData = {
|
|
@@ -14539,7 +14684,6 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14539
14684
|
message: "操作成功"
|
|
14540
14685
|
};
|
|
14541
14686
|
}
|
|
14542
|
-
task.logger.info("不需要验证,继续正常流程");
|
|
14543
14687
|
reportLogger({
|
|
14544
14688
|
token: params.huiwenToken || "",
|
|
14545
14689
|
enverionment: task.enverionment || "development",
|
|
@@ -14551,8 +14695,7 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14551
14695
|
platform: "douyin",
|
|
14552
14696
|
publishParams: publishData
|
|
14553
14697
|
});
|
|
14554
|
-
task.logger.
|
|
14555
|
-
task.logger.warn(JSON.stringify(publishResult));
|
|
14698
|
+
task.logger.info(`[douyinPublish] 发布结果 ${JSON.stringify(publishResult)}`);
|
|
14556
14699
|
const isSuccess = 0 === publishResult.status_code;
|
|
14557
14700
|
const message = `图文发布${isSuccess ? "成功" : `失败,原因:${publishResult.status_msg} ${decision?.verify_title} ${decision?.verify_desc}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
14558
14701
|
const data = isSuccess ? publishResult.item_id || "" : "";
|
|
@@ -15393,6 +15536,7 @@ const DouyinPublishParamsSchema = ActionCommonParamsSchema.extend({
|
|
|
15393
15536
|
uploadedImgList: schemas_string().optional()
|
|
15394
15537
|
});
|
|
15395
15538
|
const douyinPublish = async (task, params)=>{
|
|
15539
|
+
task.logger.info(`douyinPublish actionType: ${params.actionType}`);
|
|
15396
15540
|
if ("rpa" === params.actionType) return douyinPublish_rpa_rpaAction(task, params);
|
|
15397
15541
|
if ("mockApi" === params.actionType) return mock_mockAction(task, params);
|
|
15398
15542
|
if ("server" === params.actionType) return rpaAction_Server(task, params);
|
|
@@ -19678,7 +19822,7 @@ const ShipinhaoPublishParamsSchema = ActionCommonParamsSchema.extend({
|
|
|
19678
19822
|
]).optional()
|
|
19679
19823
|
});
|
|
19680
19824
|
const shipinhaoPublish = async (task, params)=>{
|
|
19681
|
-
|
|
19825
|
+
task.logger.info(`shipinhaoPublish actionType: ${params.actionType}`);
|
|
19682
19826
|
if ("rpa" === params.actionType) return shipinhaoPublish_rpa_rpaAction(task, params);
|
|
19683
19827
|
if ("mockApi" === params.actionType) return shipinhaoPublish_mock_mockAction(task, params);
|
|
19684
19828
|
if ("server" === params.actionType) return rpa_server_rpaAction_Server(task, params);
|
|
@@ -20736,6 +20880,7 @@ const COVER_TYPE = {
|
|
|
20736
20880
|
};
|
|
20737
20881
|
const getAddTypeValue = (toutiaoAd)=>"yes" === toutiaoAd ? 3 : 2;
|
|
20738
20882
|
const toutiaoPublish = async (task, params)=>{
|
|
20883
|
+
task.logger.info(`toutiaoPublish actionType: ${params.actionType}`);
|
|
20739
20884
|
params.content = formatSectionHtml(params.content);
|
|
20740
20885
|
if ("rpa" === params.actionType) return toutiaoPublish_rpa_rpaAction(task, params);
|
|
20741
20886
|
if ("mockApi" === params.actionType) return toutiaoPublish_mock_mockAction(task, params);
|
|
@@ -23072,6 +23217,33 @@ const xiaohongshuLogin_rpa_rpaAction = async (task, _params)=>{
|
|
|
23072
23217
|
const encode_mnsv2 = __webpack_require__("./src/utils/xhs_ob/x_s.encoder.js");
|
|
23073
23218
|
const xiaohongshuLogin_rpa_server_scanRetryMaxCount = 60;
|
|
23074
23219
|
const xiaohongshuLogin_rpa_server_waitQrcodeResultMaxTime = 2000 * xiaohongshuLogin_rpa_server_scanRetryMaxCount;
|
|
23220
|
+
async function collectCookiesWithA1(task) {
|
|
23221
|
+
const hasA1 = (cookies)=>cookies.some((c)=>"a1" === c.name && !!c.value);
|
|
23222
|
+
let cookies = await task.steelBrowserContext?.cookies() ?? [];
|
|
23223
|
+
if (hasA1(cookies)) return cookies;
|
|
23224
|
+
task.logger?.warn("[XhsLogin] 首次抓取缺失 a1,尝试补救……");
|
|
23225
|
+
try {
|
|
23226
|
+
const page = task.steelBrowserContext?.pages?.()[0];
|
|
23227
|
+
if (page) {
|
|
23228
|
+
await page.goto("https://www.xiaohongshu.com", {
|
|
23229
|
+
waitUntil: "domcontentloaded",
|
|
23230
|
+
timeout: 15000
|
|
23231
|
+
});
|
|
23232
|
+
for(let i = 0; i < 10; i++){
|
|
23233
|
+
cookies = await task.steelBrowserContext?.cookies() ?? [];
|
|
23234
|
+
if (hasA1(cookies)) {
|
|
23235
|
+
task.logger?.info(`[XhsLogin] a1 补救成功,第 ${i + 1} 次轮询命中`);
|
|
23236
|
+
return cookies;
|
|
23237
|
+
}
|
|
23238
|
+
await new Promise((resolve)=>setTimeout(resolve, 500));
|
|
23239
|
+
}
|
|
23240
|
+
}
|
|
23241
|
+
} catch (err) {
|
|
23242
|
+
task.logger?.warn("[XhsLogin] a1 补救访问主站失败", err);
|
|
23243
|
+
}
|
|
23244
|
+
cookies = await task.steelBrowserContext?.cookies() ?? [];
|
|
23245
|
+
return cookies;
|
|
23246
|
+
}
|
|
23075
23247
|
const xiaohongshuLogin_rpa_server_rpaServer = async (task, params)=>{
|
|
23076
23248
|
const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
|
|
23077
23249
|
const reporter = task.reportService?.reportLoginStatus ?? (()=>Promise.resolve());
|
|
@@ -23272,21 +23444,29 @@ const xiaohongshuLogin_rpa_server_rpaServer = async (task, params)=>{
|
|
|
23272
23444
|
};
|
|
23273
23445
|
}
|
|
23274
23446
|
case types_ExecutionState.SUCCESS:
|
|
23275
|
-
|
|
23276
|
-
|
|
23277
|
-
|
|
23278
|
-
|
|
23279
|
-
|
|
23280
|
-
}
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23284
|
-
|
|
23285
|
-
|
|
23286
|
-
|
|
23287
|
-
|
|
23288
|
-
}
|
|
23289
|
-
|
|
23447
|
+
{
|
|
23448
|
+
const cookies = await collectCookiesWithA1(task);
|
|
23449
|
+
const hasA1 = cookies.some((c)=>"a1" === c.name && !!c.value);
|
|
23450
|
+
if (!hasA1) task.logger?.warn("[XhsLogin] 登录成功但缺失关键 cookie a1,后续检测可能失败", {
|
|
23451
|
+
cookieNames: cookies.map((c)=>c.name)
|
|
23452
|
+
});
|
|
23453
|
+
const cookieStr = JSON.stringify(cookies);
|
|
23454
|
+
await updateTaskState?.({
|
|
23455
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.SUCCESS,
|
|
23456
|
+
result: {
|
|
23457
|
+
cookie: cookieStr,
|
|
23458
|
+
userInfo: userInfo
|
|
23459
|
+
}
|
|
23460
|
+
});
|
|
23461
|
+
return {
|
|
23462
|
+
code: 0,
|
|
23463
|
+
message: "成功",
|
|
23464
|
+
data: {
|
|
23465
|
+
cookie: cookieStr,
|
|
23466
|
+
userInfo
|
|
23467
|
+
}
|
|
23468
|
+
};
|
|
23469
|
+
}
|
|
23290
23470
|
default:
|
|
23291
23471
|
return {
|
|
23292
23472
|
code: 500,
|
|
@@ -23487,6 +23667,24 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23487
23667
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
23488
23668
|
const localUrl = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
23489
23669
|
const fileBuffer = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(localUrl);
|
|
23670
|
+
let width = 0;
|
|
23671
|
+
let height = 0;
|
|
23672
|
+
try {
|
|
23673
|
+
const dimensions = (0, __WEBPACK_EXTERNAL_MODULE_image_size_bc738ffb__["default"])(fileBuffer);
|
|
23674
|
+
width = dimensions.width ?? 0;
|
|
23675
|
+
height = dimensions.height ?? 0;
|
|
23676
|
+
const orientation = dimensions.orientation ?? 1;
|
|
23677
|
+
if ([
|
|
23678
|
+
5,
|
|
23679
|
+
6,
|
|
23680
|
+
7,
|
|
23681
|
+
8
|
|
23682
|
+
].includes(orientation)) [width, height] = [
|
|
23683
|
+
height,
|
|
23684
|
+
width
|
|
23685
|
+
];
|
|
23686
|
+
} catch {}
|
|
23687
|
+
const originSize = fileBuffer.byteLength / 1024;
|
|
23490
23688
|
const MAX_RETRIES = uploadInfos.length;
|
|
23491
23689
|
let attempt = 0;
|
|
23492
23690
|
while(attempt < MAX_RETRIES){
|
|
@@ -23508,7 +23706,10 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23508
23706
|
});
|
|
23509
23707
|
return {
|
|
23510
23708
|
ossFileId,
|
|
23511
|
-
ossToken
|
|
23709
|
+
ossToken,
|
|
23710
|
+
width,
|
|
23711
|
+
height,
|
|
23712
|
+
originSize
|
|
23512
23713
|
};
|
|
23513
23714
|
} catch (error) {
|
|
23514
23715
|
attempt++;
|
|
@@ -23516,7 +23717,10 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23516
23717
|
}
|
|
23517
23718
|
return {
|
|
23518
23719
|
ossFileId: "",
|
|
23519
|
-
ossToken: ""
|
|
23720
|
+
ossToken: "",
|
|
23721
|
+
width,
|
|
23722
|
+
height,
|
|
23723
|
+
originSize
|
|
23520
23724
|
};
|
|
23521
23725
|
};
|
|
23522
23726
|
const coverInfos = await Promise.all(params.banners.map((it, idx)=>uploadFile(it, idx)));
|
|
@@ -23581,8 +23785,16 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23581
23785
|
},
|
|
23582
23786
|
image_info: {
|
|
23583
23787
|
images: coverInfos.map((it)=>({
|
|
23584
|
-
extra_info_json:
|
|
23788
|
+
extra_info_json: JSON.stringify({
|
|
23789
|
+
mimeType: "image/png",
|
|
23790
|
+
image_metadata: {
|
|
23791
|
+
bg_color: "",
|
|
23792
|
+
origin_size: it.originSize
|
|
23793
|
+
}
|
|
23794
|
+
}),
|
|
23585
23795
|
file_id: it.ossFileId,
|
|
23796
|
+
width: it.width,
|
|
23797
|
+
height: it.height,
|
|
23586
23798
|
metadata: {
|
|
23587
23799
|
source: -1
|
|
23588
23800
|
},
|
|
@@ -23689,6 +23901,7 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23689
23901
|
});
|
|
23690
23902
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(data, message);
|
|
23691
23903
|
}
|
|
23904
|
+
task.logger.info(`[xiaohongshuPublish] publishData: ${JSON.stringify(publishData)} `);
|
|
23692
23905
|
const publishResult = await proxyHttp.api({
|
|
23693
23906
|
method: "post",
|
|
23694
23907
|
url: "https://edith.xiaohongshu.com/web_api/sns/v2/note",
|
|
@@ -24798,6 +25011,7 @@ const XiaohongshuPublishParamsSchema = ActionCommonParamsSchema.extend({
|
|
|
24798
25011
|
originalBind: schemas_boolean().optional()
|
|
24799
25012
|
});
|
|
24800
25013
|
const xiaohongshuPublish = async (task, params)=>{
|
|
25014
|
+
task.logger.info(`xiaohongshuPublish actionType: ${params.actionType}`);
|
|
24801
25015
|
if (DisabledReq) return {
|
|
24802
25016
|
code: 414,
|
|
24803
25017
|
data: "",
|