@iflyrpa/actions 3.0.1 → 3.0.2
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 +103 -76
- package/dist/bundle.js.map +1 -1
- package/dist/index.js +103 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -76
- package/dist/index.mjs.map +1 -1
- package/dist/utils/douyin/imageUploader.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5435,7 +5435,7 @@ function __webpack_require__(moduleId) {
|
|
|
5435
5435
|
};
|
|
5436
5436
|
})();
|
|
5437
5437
|
var package_namespaceObject = {
|
|
5438
|
-
i8: "3.0.
|
|
5438
|
+
i8: "3.0.1"
|
|
5439
5439
|
};
|
|
5440
5440
|
var dist = __webpack_require__("../../node_modules/.pnpm/https-proxy-agent@7.0.6/node_modules/https-proxy-agent/dist/index.js");
|
|
5441
5441
|
async function ProxyAgent(task, ip, adr, accountId, refresh) {
|
|
@@ -5558,6 +5558,9 @@ class Http {
|
|
|
5558
5558
|
case "ERR_BAD_REQUEST":
|
|
5559
5559
|
_message = "请求出现错误,请检查请求参数!";
|
|
5560
5560
|
break;
|
|
5561
|
+
case "ERR_BAD_RESPONSE":
|
|
5562
|
+
_message = `服务器响应异常 (${error.response?.status ?? "unknown"}),请稍后重试!`;
|
|
5563
|
+
break;
|
|
5561
5564
|
case "ERR_CANCELED":
|
|
5562
5565
|
errorResponse.code = 414;
|
|
5563
5566
|
_message = "请求连接超时,请稍候重试!";
|
|
@@ -5608,6 +5611,9 @@ class Http {
|
|
|
5608
5611
|
const isRetry = [
|
|
5609
5612
|
0,
|
|
5610
5613
|
500,
|
|
5614
|
+
502,
|
|
5615
|
+
503,
|
|
5616
|
+
504,
|
|
5611
5617
|
599
|
|
5612
5618
|
].includes(handledError.code);
|
|
5613
5619
|
if (Rtimes < retries && isRetry) {
|
|
@@ -13925,7 +13931,7 @@ class DouyinImageUploader {
|
|
|
13925
13931
|
this.authCache = null;
|
|
13926
13932
|
this.authExpireTime = 0;
|
|
13927
13933
|
this.AUTH_REFRESH_BUFFER = 300000;
|
|
13928
|
-
this.CONCURRENT_LIMIT =
|
|
13934
|
+
this.CONCURRENT_LIMIT = 10;
|
|
13929
13935
|
this.UPLOAD_DELAY = 1000;
|
|
13930
13936
|
this.UPLOAD_TIMEOUT = 300000;
|
|
13931
13937
|
this.TOS_UPLOAD_TIMEOUT = 600000;
|
|
@@ -13954,16 +13960,17 @@ class DouyinImageUploader {
|
|
|
13954
13960
|
const aBogus = imageUploader_getABogus(`https://creator.douyin.com/web/api/media/upload/auth/v5/?${queryString}`, {}, this.headers["user-agent"]);
|
|
13955
13961
|
this.queryParams.a_bogus = aBogus;
|
|
13956
13962
|
const newQueryString = new URLSearchParams(this.queryParams).toString();
|
|
13957
|
-
const uploadAuth = await this.proxyHttp.api({
|
|
13958
|
-
|
|
13959
|
-
|
|
13960
|
-
|
|
13961
|
-
|
|
13962
|
-
|
|
13963
|
-
|
|
13964
|
-
|
|
13965
|
-
|
|
13966
|
-
|
|
13963
|
+
const uploadAuth = await this.withRetry(()=>this.proxyHttp.api({
|
|
13964
|
+
method: "get",
|
|
13965
|
+
url: `https://creator.douyin.com/web/api/media/upload/auth/v5/?${newQueryString}`,
|
|
13966
|
+
headers: {
|
|
13967
|
+
...this.headers,
|
|
13968
|
+
"Content-Type": "application/json"
|
|
13969
|
+
}
|
|
13970
|
+
}, {
|
|
13971
|
+
timeout: 300000,
|
|
13972
|
+
retries: 0
|
|
13973
|
+
}), 3, 1000, "获取上传凭证");
|
|
13967
13974
|
if (!uploadAuth.auth) throw new Error(uploadAuth.status_msg || "获取上传权限失败");
|
|
13968
13975
|
try {
|
|
13969
13976
|
const authData = JSON.parse(uploadAuth.auth);
|
|
@@ -14003,19 +14010,19 @@ class DouyinImageUploader {
|
|
|
14003
14010
|
};
|
|
14004
14011
|
const result = generateAuthorization(addrParamsConfig).authorization;
|
|
14005
14012
|
const addrParamsQueryString = canonicalQueryString(addrParamsConfig.params);
|
|
14006
|
-
const response = await this.proxyHttp.api({
|
|
14007
|
-
|
|
14008
|
-
|
|
14009
|
-
|
|
14010
|
-
|
|
14011
|
-
|
|
14012
|
-
|
|
14013
|
-
|
|
14014
|
-
|
|
14015
|
-
|
|
14016
|
-
|
|
14017
|
-
|
|
14018
|
-
|
|
14013
|
+
const response = await this.withRetry(()=>this.proxyHttp.api({
|
|
14014
|
+
method: "get",
|
|
14015
|
+
url: `https://imagex.bytedanceapi.com/?${addrParamsQueryString}`,
|
|
14016
|
+
headers: {
|
|
14017
|
+
...this.headers,
|
|
14018
|
+
Authorization: result,
|
|
14019
|
+
"Content-Type": "application/json",
|
|
14020
|
+
"X-amz-date": amzDate,
|
|
14021
|
+
"X-amz-security-token": authData.SessionToken
|
|
14022
|
+
}
|
|
14023
|
+
}, {
|
|
14024
|
+
timeout: this.UPLOAD_TIMEOUT
|
|
14025
|
+
}), 3, 1000, "获取上传地址");
|
|
14019
14026
|
if (!response) throw new Error("获取上传地址失败: 响应为空");
|
|
14020
14027
|
if (response.ResponseMetadata?.Error) throw new Error(`ImageX错误: ${response.ResponseMetadata.Error.Code} - ${response.ResponseMetadata.Error.Message}`);
|
|
14021
14028
|
if (!response.Result) {
|
|
@@ -14046,23 +14053,24 @@ class DouyinImageUploader {
|
|
|
14046
14053
|
console.log(`上传至: ${uploadUrl.substring(0, 80)}...`);
|
|
14047
14054
|
console.log(`文件大小: ${imageInfo.size} bytes, CRC32: ${imageInfo.md5}`);
|
|
14048
14055
|
try {
|
|
14049
|
-
const uploadImgResp = await this.proxyHttp.api({
|
|
14050
|
-
|
|
14051
|
-
|
|
14052
|
-
|
|
14053
|
-
|
|
14054
|
-
|
|
14055
|
-
|
|
14056
|
-
|
|
14057
|
-
|
|
14058
|
-
|
|
14059
|
-
|
|
14060
|
-
|
|
14061
|
-
|
|
14062
|
-
|
|
14063
|
-
|
|
14064
|
-
|
|
14065
|
-
|
|
14056
|
+
const uploadImgResp = await this.withRetry(()=>this.proxyHttp.api({
|
|
14057
|
+
method: "post",
|
|
14058
|
+
url: uploadUrl,
|
|
14059
|
+
headers: {
|
|
14060
|
+
...this.headers,
|
|
14061
|
+
Authorization: uploadAddr.auth,
|
|
14062
|
+
"Content-crc32": imageInfo.md5,
|
|
14063
|
+
"Content-Type": "application/octet-stream",
|
|
14064
|
+
"Content-Length": imageInfo.size.toString()
|
|
14065
|
+
},
|
|
14066
|
+
data: fileBuffer,
|
|
14067
|
+
httpAgent: this.uploadAgent,
|
|
14068
|
+
httpsAgent: this.uploadAgent,
|
|
14069
|
+
maxBodyLength: 1 / 0,
|
|
14070
|
+
maxContentLength: 1 / 0
|
|
14071
|
+
}, {
|
|
14072
|
+
timeout: this.TOS_UPLOAD_TIMEOUT
|
|
14073
|
+
}), 5, 3000, "TOS上传");
|
|
14066
14074
|
console.log("TOS 上传响应:", uploadImgResp);
|
|
14067
14075
|
const isSuccess = uploadImgResp && (2000 === uploadImgResp.code || 200 === uploadImgResp.status || 200 === uploadImgResp.statusCode || uploadImgResp.data && uploadImgResp.data.crc32 || "Success" === uploadImgResp.message);
|
|
14068
14076
|
if (!isSuccess) throw new Error(`上传失败: ${JSON.stringify(uploadImgResp)}`);
|
|
@@ -14083,20 +14091,22 @@ class DouyinImageUploader {
|
|
|
14083
14091
|
async processSingleImage(imageUrl, index, total) {
|
|
14084
14092
|
console.log(`\n[${index + 1}/${total}] 处理图片: ${imageUrl.substring(0, 50)}...`);
|
|
14085
14093
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(imageUrl);
|
|
14086
|
-
const localPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].
|
|
14094
|
+
const localPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(this.tmpCachePath, fileName);
|
|
14087
14095
|
try {
|
|
14088
14096
|
await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(imageUrl, localPath);
|
|
14089
14097
|
console.log(`图片下载完成: ${localPath}`);
|
|
14098
|
+
const imageInfo = await this.getImageInfo(localPath);
|
|
14099
|
+
console.log(`图片信息: ${imageInfo.width}x${imageInfo.height}, ${imageInfo.size} bytes`);
|
|
14100
|
+
const auth = await this.getValidAuth();
|
|
14101
|
+
const uploadAddr = await this.getUploadAddress(auth);
|
|
14102
|
+
const result = await this.uploadToTOS(imageInfo, uploadAddr);
|
|
14103
|
+
this.safeDeleteFile(localPath);
|
|
14104
|
+
return result;
|
|
14090
14105
|
} catch (error) {
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
const auth = await this.getValidAuth();
|
|
14096
|
-
const uploadAddr = await this.getUploadAddress(auth);
|
|
14097
|
-
const result = await this.uploadToTOS(imageInfo, uploadAddr);
|
|
14098
|
-
this.safeDeleteFile(localPath);
|
|
14099
|
-
return result;
|
|
14106
|
+
console.error(`[${index + 1}/${total}] 图片上传失败,已跳过: ${imageUrl}`, error?.message ?? error);
|
|
14107
|
+
this.safeDeleteFile(localPath);
|
|
14108
|
+
return null;
|
|
14109
|
+
}
|
|
14100
14110
|
}
|
|
14101
14111
|
async getImageInfo(localPath) {
|
|
14102
14112
|
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(localPath);
|
|
@@ -14129,13 +14139,11 @@ class DouyinImageUploader {
|
|
|
14129
14139
|
const globalIndex = i + idx;
|
|
14130
14140
|
return this.processSingleImage(url, globalIndex, total);
|
|
14131
14141
|
});
|
|
14132
|
-
|
|
14133
|
-
|
|
14134
|
-
|
|
14135
|
-
|
|
14136
|
-
|
|
14137
|
-
throw error;
|
|
14138
|
-
}
|
|
14142
|
+
const batchResults = await Promise.all(batchPromises);
|
|
14143
|
+
const successResults = batchResults.filter((r)=>null !== r);
|
|
14144
|
+
results.push(...successResults);
|
|
14145
|
+
const failedCount = batchResults.length - successResults.length;
|
|
14146
|
+
if (failedCount > 0) console.warn(`批次 ${batchIndex} 中有 ${failedCount} 张图片上传失败`);
|
|
14139
14147
|
if (i + this.CONCURRENT_LIMIT < total) {
|
|
14140
14148
|
console.log(`等待 ${this.UPLOAD_DELAY}ms...`);
|
|
14141
14149
|
await this.delay(this.UPLOAD_DELAY);
|
|
@@ -14147,6 +14155,7 @@ class DouyinImageUploader {
|
|
|
14147
14155
|
async uploadCover(coverUrl) {
|
|
14148
14156
|
console.log("\n========== 上传封面 ==========\n");
|
|
14149
14157
|
const result = await this.processSingleImage(coverUrl, 0, 1);
|
|
14158
|
+
if (!result) console.error(`封面图上传失败,已跳过: ${coverUrl}`);
|
|
14150
14159
|
return result;
|
|
14151
14160
|
}
|
|
14152
14161
|
safeDeleteFile(filePath) {
|
|
@@ -14160,6 +14169,17 @@ class DouyinImageUploader {
|
|
|
14160
14169
|
delay(ms) {
|
|
14161
14170
|
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
14162
14171
|
}
|
|
14172
|
+
async withRetry(fn, retries = 3, delayMs = 1000, label = "") {
|
|
14173
|
+
for(let attempt = 1; attempt <= retries; attempt++)try {
|
|
14174
|
+
return await fn();
|
|
14175
|
+
} catch (err) {
|
|
14176
|
+
if (attempt === retries) throw err;
|
|
14177
|
+
const waitTime = delayMs * attempt;
|
|
14178
|
+
console.warn(`${label} 第 ${attempt} 次失败,${waitTime}ms 后重试:`, err?.message ?? err);
|
|
14179
|
+
await this.delay(waitTime);
|
|
14180
|
+
}
|
|
14181
|
+
throw new Error("unreachable");
|
|
14182
|
+
}
|
|
14163
14183
|
destroy() {
|
|
14164
14184
|
this.uploadAgent.destroy();
|
|
14165
14185
|
}
|
|
@@ -14356,14 +14376,16 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14356
14376
|
const uploader = new DouyinImageUploader(proxyHttp, headers, publishParams, tmpCachePath);
|
|
14357
14377
|
if (params.coverImage) {
|
|
14358
14378
|
const cover = await uploader.uploadCover(params.coverImage);
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
|
|
14365
|
-
|
|
14366
|
-
|
|
14379
|
+
if (cover) {
|
|
14380
|
+
publishData.item.common.images.push({
|
|
14381
|
+
uri: cover.uri,
|
|
14382
|
+
width: cover.width,
|
|
14383
|
+
height: cover.height
|
|
14384
|
+
});
|
|
14385
|
+
publishData.item.cover = {
|
|
14386
|
+
poster: cover.uri
|
|
14387
|
+
};
|
|
14388
|
+
}
|
|
14367
14389
|
}
|
|
14368
14390
|
if (params.banners && params.banners.length > 0) {
|
|
14369
14391
|
const banners = params.banners.filter((i)=>i !== params.coverImage);
|
|
@@ -14389,11 +14411,15 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14389
14411
|
}
|
|
14390
14412
|
if (!response || !response.data) return;
|
|
14391
14413
|
const responseData = response.data;
|
|
14392
|
-
if (response && responseData?.status_code && 0 !== responseData.status_code)
|
|
14393
|
-
|
|
14394
|
-
|
|
14395
|
-
|
|
14396
|
-
|
|
14414
|
+
if (response && responseData?.status_code && 0 !== responseData.status_code) {
|
|
14415
|
+
const errorCode = 4 === responseData.status_code ? 500 : responseData.status_code;
|
|
14416
|
+
if (4 === responseData.status_code) task.logger.warn(`抖音服务器错误 status_code: 4,映射为 500 触发重试。原始响应: ${JSON.stringify(responseData)}`);
|
|
14417
|
+
return {
|
|
14418
|
+
code: errorCode,
|
|
14419
|
+
message: responseData.status_msg || "文章发布异常,请稍后重试。",
|
|
14420
|
+
data: responseData
|
|
14421
|
+
};
|
|
14422
|
+
}
|
|
14397
14423
|
});
|
|
14398
14424
|
task._timerRecord.PrePublish = Date.now();
|
|
14399
14425
|
if (MockPublish) {
|
|
@@ -14476,7 +14502,9 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14476
14502
|
"x-tt-session-dtrait": sessionDtrait || ""
|
|
14477
14503
|
}
|
|
14478
14504
|
}, {
|
|
14479
|
-
timeout: 60000
|
|
14505
|
+
timeout: 60000,
|
|
14506
|
+
retries: 3,
|
|
14507
|
+
retryDelay: 2000
|
|
14480
14508
|
});
|
|
14481
14509
|
reportLogger({
|
|
14482
14510
|
token: params.huiwenToken || "",
|
|
@@ -14489,9 +14517,8 @@ const mock_mockAction = async (task, params)=>{
|
|
|
14489
14517
|
platform: "douyin",
|
|
14490
14518
|
publishParams: publishData
|
|
14491
14519
|
});
|
|
14492
|
-
|
|
14493
|
-
task.logger.warn(
|
|
14494
|
-
task.logger.warn(JSON.stringify(publishData));
|
|
14520
|
+
task.logger.warn("发布结果");
|
|
14521
|
+
task.logger.warn(JSON.stringify(publishResult));
|
|
14495
14522
|
const isSuccess = 0 === publishResult.status_code;
|
|
14496
14523
|
const message = `图文发布${isSuccess ? "成功" : `失败,原因:${publishResult.status_msg} ${decision?.verify_title} ${decision?.verify_desc}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
14497
14524
|
const data = isSuccess ? publishResult.item_id || "" : "";
|