@iflyrpa/actions 4.0.0-beta.2 → 4.0.0-beta.6
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 +160 -57
- package/dist/bundle.js.map +1 -1
- package/dist/index.js +128 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/bundle.js
CHANGED
|
@@ -8734,9 +8734,9 @@ var __webpack_exports__ = {};
|
|
|
8734
8734
|
origin: ()=>utils_origin
|
|
8735
8735
|
});
|
|
8736
8736
|
var package_namespaceObject = {
|
|
8737
|
-
i8: "0.1.
|
|
8737
|
+
i8: "0.1.1"
|
|
8738
8738
|
};
|
|
8739
|
-
var package_namespaceObject_0 = JSON.parse('{"i8":"4.0.0-beta.
|
|
8739
|
+
var package_namespaceObject_0 = JSON.parse('{"i8":"4.0.0-beta.5"}');
|
|
8740
8740
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
8741
8741
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
8742
8742
|
const external_node_http_namespaceObject = require("node:http");
|
|
@@ -8777,6 +8777,7 @@ var __webpack_exports__ = {};
|
|
|
8777
8777
|
}
|
|
8778
8778
|
});
|
|
8779
8779
|
}
|
|
8780
|
+
const DOWNLOAD_BASE_TIMEOUT = 60000;
|
|
8780
8781
|
async function downloadImage(url, savePath, retries = 3) {
|
|
8781
8782
|
const RETRYABLE_CODES = new Set([
|
|
8782
8783
|
"ECONNRESET",
|
|
@@ -8784,20 +8785,25 @@ var __webpack_exports__ = {};
|
|
|
8784
8785
|
"EAI_AGAIN",
|
|
8785
8786
|
"ENOTFOUND"
|
|
8786
8787
|
]);
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8788
|
+
const maxAttempts = retries;
|
|
8789
|
+
let lastErr;
|
|
8790
|
+
for(let attempt = 1; attempt <= maxAttempts; attempt++){
|
|
8791
|
+
const timeout = attempt * DOWNLOAD_BASE_TIMEOUT;
|
|
8792
|
+
try {
|
|
8793
|
+
return await downloadImageOnce(url, savePath, timeout);
|
|
8794
|
+
} catch (err) {
|
|
8795
|
+
var _err_extra;
|
|
8796
|
+
lastErr = err;
|
|
8797
|
+
const errCode = (null == err ? void 0 : err.code) ?? (null == err ? void 0 : null === (_err_extra = err.extra) || void 0 === _err_extra ? void 0 : _err_extra.code);
|
|
8798
|
+
const retryable = RETRYABLE_CODES.has(errCode) || (null == err ? void 0 : err.code) === 500;
|
|
8799
|
+
if (attempt >= maxAttempts || !retryable) throw err;
|
|
8800
|
+
console.warn(`downloadImage 失败,已尝试 ${attempt}/${maxAttempts} 次,下次超时 ${(attempt + 1) * DOWNLOAD_BASE_TIMEOUT / 1000}s,url: ${url},原因:`, (null == err ? void 0 : err.message) ?? err);
|
|
8794
8801
|
await new Promise((r)=>setTimeout(r, 1000));
|
|
8795
|
-
return downloadImage(url, savePath, retries - 1);
|
|
8796
8802
|
}
|
|
8797
|
-
throw err;
|
|
8798
8803
|
}
|
|
8804
|
+
throw lastErr;
|
|
8799
8805
|
}
|
|
8800
|
-
async function downloadImageOnce(url, savePath) {
|
|
8806
|
+
async function downloadImageOnce(url, savePath, timeout = DOWNLOAD_BASE_TIMEOUT) {
|
|
8801
8807
|
await ensureFile(savePath);
|
|
8802
8808
|
return new Promise((resolve, reject)=>{
|
|
8803
8809
|
const handleResponse = (response)=>{
|
|
@@ -8879,11 +8885,24 @@ var __webpack_exports__ = {};
|
|
|
8879
8885
|
};
|
|
8880
8886
|
const requestFn = url.startsWith("http://") ? external_node_http_namespaceObject.get : external_node_https_namespaceObject.get;
|
|
8881
8887
|
const req = requestFn(url, handleResponse);
|
|
8882
|
-
|
|
8888
|
+
let remoteAddress = "";
|
|
8889
|
+
req.on("socket", (socket)=>{
|
|
8890
|
+
socket.on("connect", ()=>{
|
|
8891
|
+
remoteAddress = `${socket.remoteAddress ?? ""}:${socket.remotePort ?? ""}`;
|
|
8892
|
+
});
|
|
8893
|
+
if (socket.remoteAddress) remoteAddress = `${socket.remoteAddress}:${socket.remotePort ?? ""}`;
|
|
8894
|
+
});
|
|
8895
|
+
req.setTimeout(timeout, ()=>{
|
|
8883
8896
|
req.destroy();
|
|
8897
|
+
const remoteInfo = remoteAddress || "未建立连接";
|
|
8898
|
+
console.warn(`图片下载超时 (${timeout / 1000}s),远端IP: ${remoteInfo},Url:${url}`);
|
|
8884
8899
|
reject({
|
|
8885
8900
|
code: 500,
|
|
8886
|
-
message: `图片下载超时 (${url}
|
|
8901
|
+
message: `图片下载超时 (${timeout / 1000}s) Url:${url},请检查网络连接或稍后重试! 远端ip: ${remoteInfo}`,
|
|
8902
|
+
extra: {
|
|
8903
|
+
url,
|
|
8904
|
+
remoteAddress: remoteInfo
|
|
8905
|
+
}
|
|
8887
8906
|
});
|
|
8888
8907
|
});
|
|
8889
8908
|
req.on("error", handleError);
|
|
@@ -23353,6 +23372,13 @@ var __webpack_exports__ = {};
|
|
|
23353
23372
|
}
|
|
23354
23373
|
};
|
|
23355
23374
|
if (foundError) Object.assign(errorResponse, foundError);
|
|
23375
|
+
if (error.response?.status === 403) {
|
|
23376
|
+
this.logger?.warn(`[403 详细信息] URL: ${error.config?.url}`);
|
|
23377
|
+
this.logger?.warn(`[403 响应头] ${JSON.stringify(error.response?.headers || {})}`);
|
|
23378
|
+
this.logger?.warn(`[403 响应体] ${JSON.stringify(error.response?.data || null)}`);
|
|
23379
|
+
const verifyDecision = error.response?.headers?.["x-tt-verify-passport-decision"];
|
|
23380
|
+
if (verifyDecision) this.logger?.warn(`[403 验证决策] x-tt-verify-passport-decision: ${verifyDecision}`);
|
|
23381
|
+
}
|
|
23356
23382
|
if (error.response?.data) {
|
|
23357
23383
|
if ("object" == typeof error.response.data) {
|
|
23358
23384
|
const serverError = error.response.data;
|
|
@@ -34692,21 +34718,13 @@ var __webpack_exports__ = {};
|
|
|
34692
34718
|
console.log("拦截器收到响应:", JSON.stringify(response.data));
|
|
34693
34719
|
task.logger.info(`拦截器收到响应response.headers: ${JSON.stringify(response.headers)} `);
|
|
34694
34720
|
task.logger.info(`拦截器收到响应response.data: ${JSON.stringify(response.data)} `);
|
|
34695
|
-
task.logger.info(`拦截器收到响应response.data类型: ${typeof response.data}, 值: ${JSON.stringify(response.data)}`);
|
|
34696
34721
|
decision = parseVerifyPassportDecision(response.headers["x-tt-verify-passport-decision"]);
|
|
34697
|
-
task.logger.info(`解析后的decision: ${JSON.stringify(decision)}`);
|
|
34698
34722
|
if (needsVerification(decision)) {
|
|
34699
|
-
task.logger.info(
|
|
34700
|
-
task.logger.info("拦截器即将return,不抛错");
|
|
34701
|
-
return;
|
|
34702
|
-
}
|
|
34703
|
-
task.logger.info("不需要验证,继续检查response.data");
|
|
34704
|
-
if (!response || !response.data) {
|
|
34705
|
-
task.logger.info("response或response.data为空,拦截器return");
|
|
34723
|
+
task.logger.info(`需要验证: ${JSON.stringify(decision)}`);
|
|
34706
34724
|
return;
|
|
34707
34725
|
}
|
|
34726
|
+
if (!response || !response.data) return;
|
|
34708
34727
|
const responseData = response.data;
|
|
34709
|
-
task.logger.info(`responseData.status_code: ${responseData?.status_code}`);
|
|
34710
34728
|
if (response && responseData?.status_code && 0 !== responseData.status_code) {
|
|
34711
34729
|
const errorCode = 4 === responseData.status_code ? 500 : responseData.status_code;
|
|
34712
34730
|
if (4 === responseData.status_code) task.logger.warn(`抖音服务器错误 status_code: 4,映射为 500 触发重试。原始响应: ${JSON.stringify(responseData)}`);
|
|
@@ -34803,9 +34821,33 @@ var __webpack_exports__ = {};
|
|
|
34803
34821
|
retryDelay: 2000
|
|
34804
34822
|
});
|
|
34805
34823
|
task.logger.info("========== api调用完成 ==========");
|
|
34806
|
-
task.logger.info(`
|
|
34807
|
-
|
|
34808
|
-
|
|
34824
|
+
task.logger.info(`decision值: ${JSON.stringify(decision)}, needsVerification(decision): ${needsVerification(decision)}`);
|
|
34825
|
+
if (needsVerification(decision)) {
|
|
34826
|
+
const details = [
|
|
34827
|
+
publishResult.status_msg,
|
|
34828
|
+
decision?.verify_title,
|
|
34829
|
+
decision?.verify_desc
|
|
34830
|
+
].filter(Boolean).join(" ");
|
|
34831
|
+
const message = `图文发布失败,原因:${details}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
34832
|
+
task.logger.warn(`TaskId:${task.taskId},检测到需要验证,准备返回验证信息`);
|
|
34833
|
+
let decisionObj = {};
|
|
34834
|
+
if (decision) decisionObj = decision;
|
|
34835
|
+
const mockData = {
|
|
34836
|
+
state: types_TaskState.FAILED,
|
|
34837
|
+
error: message,
|
|
34838
|
+
result: {
|
|
34839
|
+
...decisionObj,
|
|
34840
|
+
data: decision,
|
|
34841
|
+
uploadedImgList: JSON.stringify(publishData.item.common.images)
|
|
34842
|
+
}
|
|
34843
|
+
};
|
|
34844
|
+
await updateTaskState?.(mockData);
|
|
34845
|
+
return {
|
|
34846
|
+
code: 0,
|
|
34847
|
+
data: mockData,
|
|
34848
|
+
message: "操作成功"
|
|
34849
|
+
};
|
|
34850
|
+
}
|
|
34809
34851
|
task.logger.info("不需要验证,继续正常流程");
|
|
34810
34852
|
reportLogger({
|
|
34811
34853
|
token: params.huiwenToken || "",
|
|
@@ -34824,10 +34866,13 @@ var __webpack_exports__ = {};
|
|
|
34824
34866
|
const message = `图文发布${isSuccess ? "成功" : `失败,原因:${publishResult.status_msg} ${decision?.verify_title} ${decision?.verify_desc}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
34825
34867
|
const data = isSuccess ? publishResult.item_id || "" : "";
|
|
34826
34868
|
if (!isSuccess) {
|
|
34869
|
+
let decisionObj = {};
|
|
34870
|
+
if (decision) decisionObj = decision;
|
|
34827
34871
|
await updateTaskState?.({
|
|
34828
34872
|
state: types_TaskState.FAILED,
|
|
34829
34873
|
error: message,
|
|
34830
34874
|
result: {
|
|
34875
|
+
...decisionObj,
|
|
34831
34876
|
data: decision,
|
|
34832
34877
|
uploadedImgList: JSON.stringify(publishData.item.common.images)
|
|
34833
34878
|
}
|
|
@@ -35502,15 +35547,41 @@ var __webpack_exports__ = {};
|
|
|
35502
35547
|
}
|
|
35503
35548
|
task.logger?.info("准备发布...");
|
|
35504
35549
|
await page.waitForTimeout(1000);
|
|
35505
|
-
const
|
|
35550
|
+
const result = await new Promise((resolve, reject)=>{
|
|
35506
35551
|
const handleResponse = async (res)=>{
|
|
35507
35552
|
if (res.url().includes("/web/api/media/aweme/create_v2")) {
|
|
35508
35553
|
task.logger?.info("匹配到发布接口响应");
|
|
35554
|
+
let decision = null;
|
|
35555
|
+
try {
|
|
35556
|
+
const headers = await res.allHeaders();
|
|
35557
|
+
decision = parseVerifyPassportDecision(headers["x-tt-verify-passport-decision"]);
|
|
35558
|
+
} catch (error) {
|
|
35559
|
+
task.logger?.warn(`解析验证决策头失败: ${error}`);
|
|
35560
|
+
}
|
|
35509
35561
|
const jsonResponse = await res.json();
|
|
35510
35562
|
task.logger?.info(`发布接口响应数据: ${JSON.stringify(jsonResponse)}`);
|
|
35511
35563
|
page.off("response", handleResponse);
|
|
35512
|
-
if (
|
|
35513
|
-
|
|
35564
|
+
if (needsVerification(decision)) {
|
|
35565
|
+
task.logger?.warn("检测到需要二次验证,文章未真正发布");
|
|
35566
|
+
resolve({
|
|
35567
|
+
itemId: "",
|
|
35568
|
+
decision
|
|
35569
|
+
});
|
|
35570
|
+
return;
|
|
35571
|
+
}
|
|
35572
|
+
if (jsonResponse?.status_code !== 0) {
|
|
35573
|
+
reject(new Error(jsonResponse?.status_msg || "发布失败"));
|
|
35574
|
+
return;
|
|
35575
|
+
}
|
|
35576
|
+
const itemId = jsonResponse?.data?.item_id || jsonResponse?.item_id || "";
|
|
35577
|
+
if (!itemId) {
|
|
35578
|
+
reject(new Error(jsonResponse?.status_msg || "发布异常:未返回作品ID,文章可能未真正发布"));
|
|
35579
|
+
return;
|
|
35580
|
+
}
|
|
35581
|
+
resolve({
|
|
35582
|
+
itemId,
|
|
35583
|
+
decision: null
|
|
35584
|
+
});
|
|
35514
35585
|
}
|
|
35515
35586
|
};
|
|
35516
35587
|
page.on("response", handleResponse);
|
|
@@ -35532,20 +35603,42 @@ var __webpack_exports__ = {};
|
|
|
35532
35603
|
await page.close();
|
|
35533
35604
|
return null;
|
|
35534
35605
|
});
|
|
35535
|
-
if (!
|
|
35606
|
+
if (!result) return {
|
|
35536
35607
|
code: 414,
|
|
35537
35608
|
message: "发布失败",
|
|
35538
35609
|
data: ""
|
|
35539
35610
|
};
|
|
35540
|
-
|
|
35611
|
+
if (needsVerification(result.decision)) {
|
|
35612
|
+
const decision = result.decision;
|
|
35613
|
+
const details = [
|
|
35614
|
+
decision?.verify_title,
|
|
35615
|
+
decision?.verify_desc
|
|
35616
|
+
].filter(Boolean).join(" ");
|
|
35617
|
+
const message = `发布失败,需要二次验证${details ? `:${details}` : ""}`;
|
|
35618
|
+
task.logger?.warn(message);
|
|
35619
|
+
await updateTaskState?.({
|
|
35620
|
+
state: types_TaskState.FAILED,
|
|
35621
|
+
error: message,
|
|
35622
|
+
result: {
|
|
35623
|
+
data: decision
|
|
35624
|
+
}
|
|
35625
|
+
});
|
|
35626
|
+
await page.close();
|
|
35627
|
+
return {
|
|
35628
|
+
code: 414,
|
|
35629
|
+
message,
|
|
35630
|
+
data: ""
|
|
35631
|
+
};
|
|
35632
|
+
}
|
|
35633
|
+
task.logger?.info(`✓ 发布成功,item_id: ${result.itemId}`);
|
|
35541
35634
|
await updateTaskState?.({
|
|
35542
35635
|
state: types_TaskState.SUCCESS,
|
|
35543
35636
|
result: {
|
|
35544
|
-
response
|
|
35637
|
+
response: result.itemId
|
|
35545
35638
|
}
|
|
35546
35639
|
});
|
|
35547
35640
|
await page.close();
|
|
35548
|
-
return success(
|
|
35641
|
+
return success(result.itemId);
|
|
35549
35642
|
};
|
|
35550
35643
|
const DouyinPublishParamsSchema = ActionCommonParamsSchema.extend({
|
|
35551
35644
|
title: classic_schemas_string(),
|
|
@@ -36325,26 +36418,26 @@ var __webpack_exports__ = {};
|
|
|
36325
36418
|
const http = new Http({
|
|
36326
36419
|
headers: {
|
|
36327
36420
|
cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
|
|
36328
|
-
referer: "https://mp.toutiao.com/profile_v4/graphic/publish"
|
|
36421
|
+
referer: "https://mp.toutiao.com/profile_v4/graphic/publish",
|
|
36422
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
|
36423
|
+
}
|
|
36424
|
+
});
|
|
36425
|
+
const totalData = await http.api({
|
|
36426
|
+
method: "get",
|
|
36427
|
+
url: "https://mp.toutiao.com/mp/fe_api/home/merge_v2",
|
|
36428
|
+
params: {
|
|
36429
|
+
app_id: 1231
|
|
36430
|
+
}
|
|
36431
|
+
});
|
|
36432
|
+
await new Promise((r)=>setTimeout(r, 1000));
|
|
36433
|
+
const contentDataYesterday = await http.api({
|
|
36434
|
+
method: "get",
|
|
36435
|
+
url: "https://mp.toutiao.com/mp/agw/statistic/v2/content_stat",
|
|
36436
|
+
params: {
|
|
36437
|
+
type: 0,
|
|
36438
|
+
app_id: 1231
|
|
36329
36439
|
}
|
|
36330
36440
|
});
|
|
36331
|
-
const [totalData, contentDataYesterday] = await Promise.all([
|
|
36332
|
-
http.api({
|
|
36333
|
-
method: "get",
|
|
36334
|
-
url: "https://mp.toutiao.com/mp/fe_api/home/merge_v2",
|
|
36335
|
-
params: {
|
|
36336
|
-
app_id: 1231
|
|
36337
|
-
}
|
|
36338
|
-
}),
|
|
36339
|
-
http.api({
|
|
36340
|
-
method: "get",
|
|
36341
|
-
url: "https://mp.toutiao.com/mp/agw/statistic/v2/content_stat",
|
|
36342
|
-
params: {
|
|
36343
|
-
type: 0,
|
|
36344
|
-
app_id: 1231
|
|
36345
|
-
}
|
|
36346
|
-
})
|
|
36347
|
-
]);
|
|
36348
36441
|
const isSuccess = !!(totalData?.data?.statistic && contentDataYesterday?.author_stat);
|
|
36349
36442
|
if (!isSuccess || !totalData?.data || !contentDataYesterday?.author_stat) return types_errorResponse(totalData?.message || contentDataYesterday?.message || "头条号数据获取失败,请检查Cookie是否有效", 414);
|
|
36350
36443
|
const ttData = {
|
|
@@ -40521,8 +40614,10 @@ var __webpack_exports__ = {};
|
|
|
40521
40614
|
tuwen_wtt_trans_flag: params.settingInfo?.toutiaoTransWtt ? "2" : "0",
|
|
40522
40615
|
info_source: sourceData,
|
|
40523
40616
|
...location ? {
|
|
40524
|
-
|
|
40525
|
-
|
|
40617
|
+
manual_selected_city: JSON.stringify({
|
|
40618
|
+
city: location.label,
|
|
40619
|
+
city_code: location.value
|
|
40620
|
+
})
|
|
40526
40621
|
} : null,
|
|
40527
40622
|
...params.settingInfo?.toutiaoCollectionId ? {
|
|
40528
40623
|
want_join_collection_id: params.settingInfo.toutiaoCollectionId
|
|
@@ -40572,6 +40667,12 @@ var __webpack_exports__ = {};
|
|
|
40572
40667
|
claim_exclusive: toutiaoExclusive ? toutiaoExclusive : toutiaoOriginal?.includes("exclusive") ? 1 : 0
|
|
40573
40668
|
};
|
|
40574
40669
|
task._timerRecord.PrePublish = Date.now();
|
|
40670
|
+
task.logger.info(`[toutiaoPublish] ${"draft" === params.saveType ? "同步草稿" : "发布文章"}参数`, {
|
|
40671
|
+
saveType: params.saveType,
|
|
40672
|
+
title: params.title,
|
|
40673
|
+
extra: extraData,
|
|
40674
|
+
publishData
|
|
40675
|
+
});
|
|
40575
40676
|
const msToken = params.cookies.find((it)=>"msToken" === it.name)?.value;
|
|
40576
40677
|
let publishOption = {};
|
|
40577
40678
|
if (msToken) {
|
|
@@ -41767,8 +41868,8 @@ var __webpack_exports__ = {};
|
|
|
41767
41868
|
headers
|
|
41768
41869
|
});
|
|
41769
41870
|
const proxyHttp = new Http(...args);
|
|
41770
|
-
|
|
41771
|
-
const responseData = response
|
|
41871
|
+
const baseRespFinder = (response)=>{
|
|
41872
|
+
const responseData = response?.data;
|
|
41772
41873
|
const msgType = "draft" === params.saveType ? "同步" : "发布";
|
|
41773
41874
|
if (response && responseData?.base_resp && 0 !== responseData.base_resp.ret && !ignoreErrno.includes(responseData.base_resp.ret)) {
|
|
41774
41875
|
const errmsg = weixinPublish_mock_errnoMap[responseData.base_resp.ret] || response.config.defaultErrorMsg || responseData.base_resp.err_msg || `文章${msgType}异常,请稍后重试。`;
|
|
@@ -41778,7 +41879,9 @@ var __webpack_exports__ = {};
|
|
|
41778
41879
|
data: responseData
|
|
41779
41880
|
};
|
|
41780
41881
|
}
|
|
41781
|
-
}
|
|
41882
|
+
};
|
|
41883
|
+
http.addResponseInterceptor(baseRespFinder);
|
|
41884
|
+
proxyHttp.addResponseInterceptor(baseRespFinder);
|
|
41782
41885
|
await http.api({
|
|
41783
41886
|
method: "get",
|
|
41784
41887
|
url: "https://mp.weixin.qq.com/cgi-bin/appmsgpublish",
|