@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 CHANGED
@@ -8735,7 +8735,7 @@ var __webpack_exports__ = {};
8735
8735
  });
8736
8736
  var package_namespaceObject = JSON.parse('{"i8":"0.1.0-beta.1"}');
8737
8737
  var package_namespaceObject_0 = {
8738
- i8: "3.0.0"
8738
+ i8: "3.0.1"
8739
8739
  };
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);
@@ -23385,6 +23385,9 @@ var __webpack_exports__ = {};
23385
23385
  case "ERR_BAD_REQUEST":
23386
23386
  _message = "请求出现错误,请检查请求参数!";
23387
23387
  break;
23388
+ case "ERR_BAD_RESPONSE":
23389
+ _message = `服务器响应异常 (${error.response?.status ?? "unknown"}),请稍后重试!`;
23390
+ break;
23388
23391
  case "ERR_CANCELED":
23389
23392
  errorResponse.code = 414;
23390
23393
  _message = "请求连接超时,请稍候重试!";
@@ -23435,6 +23438,9 @@ var __webpack_exports__ = {};
23435
23438
  const isRetry = [
23436
23439
  0,
23437
23440
  500,
23441
+ 502,
23442
+ 503,
23443
+ 504,
23438
23444
  599
23439
23445
  ].includes(handledError.code);
23440
23446
  if (Rtimes < retries && isRetry) {
@@ -34213,7 +34219,7 @@ var __webpack_exports__ = {};
34213
34219
  this.authCache = null;
34214
34220
  this.authExpireTime = 0;
34215
34221
  this.AUTH_REFRESH_BUFFER = 300000;
34216
- this.CONCURRENT_LIMIT = 5;
34222
+ this.CONCURRENT_LIMIT = 10;
34217
34223
  this.UPLOAD_DELAY = 1000;
34218
34224
  this.UPLOAD_TIMEOUT = 300000;
34219
34225
  this.TOS_UPLOAD_TIMEOUT = 600000;
@@ -34242,16 +34248,17 @@ var __webpack_exports__ = {};
34242
34248
  const aBogus = imageUploader_getABogus(`https://creator.douyin.com/web/api/media/upload/auth/v5/?${queryString}`, {}, this.headers["user-agent"]);
34243
34249
  this.queryParams.a_bogus = aBogus;
34244
34250
  const newQueryString = new URLSearchParams(this.queryParams).toString();
34245
- const uploadAuth = await this.proxyHttp.api({
34246
- method: "get",
34247
- url: `https://creator.douyin.com/web/api/media/upload/auth/v5/?${newQueryString}`,
34248
- headers: {
34249
- ...this.headers,
34250
- "Content-Type": "application/json"
34251
- }
34252
- }, {
34253
- timeout: 300000
34254
- });
34251
+ const uploadAuth = await this.withRetry(()=>this.proxyHttp.api({
34252
+ method: "get",
34253
+ url: `https://creator.douyin.com/web/api/media/upload/auth/v5/?${newQueryString}`,
34254
+ headers: {
34255
+ ...this.headers,
34256
+ "Content-Type": "application/json"
34257
+ }
34258
+ }, {
34259
+ timeout: 300000,
34260
+ retries: 0
34261
+ }), 3, 1000, "获取上传凭证");
34255
34262
  if (!uploadAuth.auth) throw new Error(uploadAuth.status_msg || "获取上传权限失败");
34256
34263
  try {
34257
34264
  const authData = JSON.parse(uploadAuth.auth);
@@ -34291,19 +34298,19 @@ var __webpack_exports__ = {};
34291
34298
  };
34292
34299
  const result = generateAuthorization(addrParamsConfig).authorization;
34293
34300
  const addrParamsQueryString = canonicalQueryString(addrParamsConfig.params);
34294
- const response = await this.proxyHttp.api({
34295
- method: "get",
34296
- url: `https://imagex.bytedanceapi.com/?${addrParamsQueryString}`,
34297
- headers: {
34298
- ...this.headers,
34299
- Authorization: result,
34300
- "Content-Type": "application/json",
34301
- "X-amz-date": amzDate,
34302
- "X-amz-security-token": authData.SessionToken
34303
- }
34304
- }, {
34305
- timeout: this.UPLOAD_TIMEOUT
34306
- });
34301
+ const response = await this.withRetry(()=>this.proxyHttp.api({
34302
+ method: "get",
34303
+ url: `https://imagex.bytedanceapi.com/?${addrParamsQueryString}`,
34304
+ headers: {
34305
+ ...this.headers,
34306
+ Authorization: result,
34307
+ "Content-Type": "application/json",
34308
+ "X-amz-date": amzDate,
34309
+ "X-amz-security-token": authData.SessionToken
34310
+ }
34311
+ }, {
34312
+ timeout: this.UPLOAD_TIMEOUT
34313
+ }), 3, 1000, "获取上传地址");
34307
34314
  if (!response) throw new Error("获取上传地址失败: 响应为空");
34308
34315
  if (response.ResponseMetadata?.Error) throw new Error(`ImageX错误: ${response.ResponseMetadata.Error.Code} - ${response.ResponseMetadata.Error.Message}`);
34309
34316
  if (!response.Result) {
@@ -34334,23 +34341,24 @@ var __webpack_exports__ = {};
34334
34341
  console.log(`上传至: ${uploadUrl.substring(0, 80)}...`);
34335
34342
  console.log(`文件大小: ${imageInfo.size} bytes, CRC32: ${imageInfo.md5}`);
34336
34343
  try {
34337
- const uploadImgResp = await this.proxyHttp.api({
34338
- method: "post",
34339
- url: uploadUrl,
34340
- headers: {
34341
- ...this.headers,
34342
- Authorization: uploadAddr.auth,
34343
- "Content-crc32": imageInfo.md5,
34344
- "Content-Type": "application/octet-stream",
34345
- "Content-Length": imageInfo.size.toString()
34346
- },
34347
- data: fileBuffer,
34348
- httpAgent: this.uploadAgent,
34349
- httpsAgent: this.uploadAgent,
34350
- timeout: this.TOS_UPLOAD_TIMEOUT,
34351
- maxBodyLength: 1 / 0,
34352
- maxContentLength: 1 / 0
34353
- });
34344
+ const uploadImgResp = await this.withRetry(()=>this.proxyHttp.api({
34345
+ method: "post",
34346
+ url: uploadUrl,
34347
+ headers: {
34348
+ ...this.headers,
34349
+ Authorization: uploadAddr.auth,
34350
+ "Content-crc32": imageInfo.md5,
34351
+ "Content-Type": "application/octet-stream",
34352
+ "Content-Length": imageInfo.size.toString()
34353
+ },
34354
+ data: fileBuffer,
34355
+ httpAgent: this.uploadAgent,
34356
+ httpsAgent: this.uploadAgent,
34357
+ maxBodyLength: 1 / 0,
34358
+ maxContentLength: 1 / 0
34359
+ }, {
34360
+ timeout: this.TOS_UPLOAD_TIMEOUT
34361
+ }), 5, 3000, "TOS上传");
34354
34362
  console.log("TOS 上传响应:", uploadImgResp);
34355
34363
  const isSuccess = uploadImgResp && (2000 === uploadImgResp.code || 200 === uploadImgResp.status || 200 === uploadImgResp.statusCode || uploadImgResp.data && uploadImgResp.data.crc32 || "Success" === uploadImgResp.message);
34356
34364
  if (!isSuccess) throw new Error(`上传失败: ${JSON.stringify(uploadImgResp)}`);
@@ -34371,20 +34379,22 @@ var __webpack_exports__ = {};
34371
34379
  async processSingleImage(imageUrl, index, total) {
34372
34380
  console.log(`\n[${index + 1}/${total}] 处理图片: ${imageUrl.substring(0, 50)}...`);
34373
34381
  const fileName = getFilenameFromUrl(imageUrl);
34374
- const localPath = external_node_path_default().join(this.tmpCachePath, fileName);
34382
+ const localPath = external_node_path_default().resolve(this.tmpCachePath, fileName);
34375
34383
  try {
34376
34384
  await downloadImage(imageUrl, localPath);
34377
34385
  console.log(`图片下载完成: ${localPath}`);
34386
+ const imageInfo = await this.getImageInfo(localPath);
34387
+ console.log(`图片信息: ${imageInfo.width}x${imageInfo.height}, ${imageInfo.size} bytes`);
34388
+ const auth = await this.getValidAuth();
34389
+ const uploadAddr = await this.getUploadAddress(auth);
34390
+ const result = await this.uploadToTOS(imageInfo, uploadAddr);
34391
+ this.safeDeleteFile(localPath);
34392
+ return result;
34378
34393
  } catch (error) {
34379
- throw new Error(`下载图片失败: ${imageUrl}`);
34380
- }
34381
- const imageInfo = await this.getImageInfo(localPath);
34382
- console.log(`图片信息: ${imageInfo.width}x${imageInfo.height}, ${imageInfo.size} bytes`);
34383
- const auth = await this.getValidAuth();
34384
- const uploadAddr = await this.getUploadAddress(auth);
34385
- const result = await this.uploadToTOS(imageInfo, uploadAddr);
34386
- this.safeDeleteFile(localPath);
34387
- return result;
34394
+ console.error(`[${index + 1}/${total}] 图片上传失败,已跳过: ${imageUrl}`, error?.message ?? error);
34395
+ this.safeDeleteFile(localPath);
34396
+ return null;
34397
+ }
34388
34398
  }
34389
34399
  async getImageInfo(localPath) {
34390
34400
  const stats = external_node_fs_default().statSync(localPath);
@@ -34417,13 +34427,11 @@ var __webpack_exports__ = {};
34417
34427
  const globalIndex = i + idx;
34418
34428
  return this.processSingleImage(url, globalIndex, total);
34419
34429
  });
34420
- try {
34421
- const batchResults = await Promise.all(batchPromises);
34422
- results.push(...batchResults);
34423
- } catch (error) {
34424
- console.error(`批次 ${batchIndex} 上传失败:`, error);
34425
- throw error;
34426
- }
34430
+ const batchResults = await Promise.all(batchPromises);
34431
+ const successResults = batchResults.filter((r)=>null !== r);
34432
+ results.push(...successResults);
34433
+ const failedCount = batchResults.length - successResults.length;
34434
+ if (failedCount > 0) console.warn(`批次 ${batchIndex} 中有 ${failedCount} 张图片上传失败`);
34427
34435
  if (i + this.CONCURRENT_LIMIT < total) {
34428
34436
  console.log(`等待 ${this.UPLOAD_DELAY}ms...`);
34429
34437
  await this.delay(this.UPLOAD_DELAY);
@@ -34435,6 +34443,7 @@ var __webpack_exports__ = {};
34435
34443
  async uploadCover(coverUrl) {
34436
34444
  console.log("\n========== 上传封面 ==========\n");
34437
34445
  const result = await this.processSingleImage(coverUrl, 0, 1);
34446
+ if (!result) console.error(`封面图上传失败,已跳过: ${coverUrl}`);
34438
34447
  return result;
34439
34448
  }
34440
34449
  safeDeleteFile(filePath) {
@@ -34448,6 +34457,17 @@ var __webpack_exports__ = {};
34448
34457
  delay(ms) {
34449
34458
  return new Promise((resolve)=>setTimeout(resolve, ms));
34450
34459
  }
34460
+ async withRetry(fn, retries = 3, delayMs = 1000, label = "") {
34461
+ for(let attempt = 1; attempt <= retries; attempt++)try {
34462
+ return await fn();
34463
+ } catch (err) {
34464
+ if (attempt === retries) throw err;
34465
+ const waitTime = delayMs * attempt;
34466
+ console.warn(`${label} 第 ${attempt} 次失败,${waitTime}ms 后重试:`, err?.message ?? err);
34467
+ await this.delay(waitTime);
34468
+ }
34469
+ throw new Error("unreachable");
34470
+ }
34451
34471
  destroy() {
34452
34472
  this.uploadAgent.destroy();
34453
34473
  }
@@ -34644,14 +34664,16 @@ var __webpack_exports__ = {};
34644
34664
  const uploader = new DouyinImageUploader(proxyHttp, headers, publishParams, tmpCachePath);
34645
34665
  if (params.coverImage) {
34646
34666
  const cover = await uploader.uploadCover(params.coverImage);
34647
- publishData.item.common.images.push({
34648
- uri: cover.uri,
34649
- width: cover.width,
34650
- height: cover.height
34651
- });
34652
- publishData.item.cover = {
34653
- poster: cover.uri
34654
- };
34667
+ if (cover) {
34668
+ publishData.item.common.images.push({
34669
+ uri: cover.uri,
34670
+ width: cover.width,
34671
+ height: cover.height
34672
+ });
34673
+ publishData.item.cover = {
34674
+ poster: cover.uri
34675
+ };
34676
+ }
34655
34677
  }
34656
34678
  if (params.banners && params.banners.length > 0) {
34657
34679
  const banners = params.banners.filter((i)=>i !== params.coverImage);
@@ -34677,11 +34699,15 @@ var __webpack_exports__ = {};
34677
34699
  }
34678
34700
  if (!response || !response.data) return;
34679
34701
  const responseData = response.data;
34680
- if (response && responseData?.status_code && 0 !== responseData.status_code) return {
34681
- code: responseData?.status_code,
34682
- message: responseData.status_msg || "文章发布异常,请稍后重试。",
34683
- data: responseData
34684
- };
34702
+ if (response && responseData?.status_code && 0 !== responseData.status_code) {
34703
+ const errorCode = 4 === responseData.status_code ? 500 : responseData.status_code;
34704
+ if (4 === responseData.status_code) task.logger.warn(`抖音服务器错误 status_code: 4,映射为 500 触发重试。原始响应: ${JSON.stringify(responseData)}`);
34705
+ return {
34706
+ code: errorCode,
34707
+ message: responseData.status_msg || "文章发布异常,请稍后重试。",
34708
+ data: responseData
34709
+ };
34710
+ }
34685
34711
  });
34686
34712
  task._timerRecord.PrePublish = Date.now();
34687
34713
  if (MockPublish) {
@@ -34764,7 +34790,9 @@ var __webpack_exports__ = {};
34764
34790
  "x-tt-session-dtrait": sessionDtrait || ""
34765
34791
  }
34766
34792
  }, {
34767
- timeout: 60000
34793
+ timeout: 60000,
34794
+ retries: 3,
34795
+ retryDelay: 2000
34768
34796
  });
34769
34797
  reportLogger({
34770
34798
  token: params.huiwenToken || "",
@@ -34777,9 +34805,8 @@ var __webpack_exports__ = {};
34777
34805
  platform: "douyin",
34778
34806
  publishParams: publishData
34779
34807
  });
34780
- console.log("publishResult", JSON.stringify(publishResult));
34781
- task.logger.warn("发布数据");
34782
- task.logger.warn(JSON.stringify(publishData));
34808
+ task.logger.warn("发布结果");
34809
+ task.logger.warn(JSON.stringify(publishResult));
34783
34810
  const isSuccess = 0 === publishResult.status_code;
34784
34811
  const message = `图文发布${isSuccess ? "成功" : `失败,原因:${publishResult.status_msg} ${decision?.verify_title} ${decision?.verify_desc}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
34785
34812
  const data = isSuccess ? publishResult.item_id || "" : "";