@iflyrpa/actions 4.0.9 → 4.1.0-beta.1
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/actions/searchAccountInfo/index.d.ts +1 -1
- package/dist/actions/searchPublishInfo/index.d.ts +1 -1
- package/dist/actions/shipinhaoPublishVideo/index.d.ts +95 -0
- package/dist/actions/shipinhaoPublishVideo/mock.d.ts +4 -0
- package/dist/actions/shipinhaoPublishVideo/payload.d.ts +70 -0
- package/dist/actions/shipinhaoPublishVideo/rpa.d.ts +6 -0
- package/dist/actions/shipinhaoPublishVideo/uploader.d.ts +57 -0
- package/dist/actions/shipinhaoPublishVideo/videoMeta.d.ts +65 -0
- package/dist/actions/shipinhaoPublishVideo/videoValidator.d.ts +37 -0
- package/dist/bundle.js +1950 -102
- package/dist/bundle.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.js +2098 -250
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2099 -252
- package/dist/index.mjs.map +1 -1
- package/dist/utils/errorMessages.d.ts +41 -0
- package/dist/utils/feishuAlarm.d.ts +30 -0
- package/dist/utils/http.d.ts +12 -0
- package/dist/utils/imageValidator.d.ts +67 -0
- package/dist/utils/shipinhao/auth.d.ts +31 -0
- package/dist/utils/shipinhao/utils.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d7b84b2c-f6d7-5874-b962-65e4fb23456c")}catch(e){}}();
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE_crypto__ from "crypto";
|
|
4
4
|
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_package_json_58ae5f06__ from "@iflyrpa/share/package.json";
|
|
@@ -4352,8 +4352,130 @@ function __webpack_require__(moduleId) {
|
|
|
4352
4352
|
return module;
|
|
4353
4353
|
};
|
|
4354
4354
|
})();
|
|
4355
|
-
var package_namespaceObject = {
|
|
4356
|
-
|
|
4355
|
+
var package_namespaceObject = JSON.parse('{"i8":"4.1.0-beta.1"}');
|
|
4356
|
+
const USER_MESSAGE = {
|
|
4357
|
+
PROXY_UNAVAILABLE: "代理暂时不可用,请稍后重试或使用本地IP",
|
|
4358
|
+
NETWORK_ERROR: "网络异常,请稍后重试",
|
|
4359
|
+
SYSTEM_ERROR: "系统异常,请稍后重试或联系客服",
|
|
4360
|
+
PUBLISH_NETWORK: "发布失败,网络不稳定,请稍后重试",
|
|
4361
|
+
DOUYIN_ACCOUNT_FETCH_FAILED: "抖音数据获取失败,请稍后重试",
|
|
4362
|
+
SHIPINHAO_ACCOUNT_FETCH_FAILED: "视频号数据获取失败,请稍后重试",
|
|
4363
|
+
DOUYIN_POST_FETCH_FAILED: "抖音作品数据获取失败,请稍后重试",
|
|
4364
|
+
SHIPINHAO_POST_FETCH_FAILED: "视频号作品数据获取失败,请稍后重试",
|
|
4365
|
+
BJH_POST_FETCH_FAILED: "百家号作品数据获取失败,请稍后重试",
|
|
4366
|
+
TT_POST_FETCH_FAILED: "头条号作品数据获取失败,请稍后重试",
|
|
4367
|
+
QRCODE_FETCH_FAILED: "认证二维码获取失败,请稍后重试",
|
|
4368
|
+
IMAGE_UPLOAD_FAILED: "图片上传失败,请稍后重试或联系客服"
|
|
4369
|
+
};
|
|
4370
|
+
const NETWORK_CODES = [
|
|
4371
|
+
500,
|
|
4372
|
+
502,
|
|
4373
|
+
503,
|
|
4374
|
+
504
|
|
4375
|
+
];
|
|
4376
|
+
function classifyPublishError(handledError) {
|
|
4377
|
+
const { code } = handledError;
|
|
4378
|
+
const isProxyRequest = handledError.extra?.isProxyRequest === true;
|
|
4379
|
+
if (!NETWORK_CODES.includes(code) && 599 !== code) return null;
|
|
4380
|
+
const category = 599 === code || isProxyRequest ? "代理错误" : "网络错误";
|
|
4381
|
+
return {
|
|
4382
|
+
category,
|
|
4383
|
+
userMessage: USER_MESSAGE.PUBLISH_NETWORK
|
|
4384
|
+
};
|
|
4385
|
+
}
|
|
4386
|
+
const RPA_ERROR_WEBHOOK_URL = "https://open.xfchat.iflytek.com/open-apis/bot/v2/hook/d202c0dc-5af5-40bc-83ed-abc677caa4a5";
|
|
4387
|
+
const ALARM_THROTTLE_MS = 60000;
|
|
4388
|
+
const lastSentAt = new Map();
|
|
4389
|
+
const THROTTLE_MAP_MAX_KEYS = 500;
|
|
4390
|
+
const pruneThrottleMap = (now)=>{
|
|
4391
|
+
if (lastSentAt.size < THROTTLE_MAP_MAX_KEYS) return;
|
|
4392
|
+
for (const [key, at] of lastSentAt)if (now - at >= ALARM_THROTTLE_MS) lastSentAt.delete(key);
|
|
4393
|
+
};
|
|
4394
|
+
const postFeishuWebhook = (webhookUrl, payload)=>__WEBPACK_EXTERNAL_MODULE_axios__["default"].post(webhookUrl, payload, {
|
|
4395
|
+
headers: {
|
|
4396
|
+
"Content-Type": "application/json"
|
|
4397
|
+
},
|
|
4398
|
+
timeout: 10000
|
|
4399
|
+
});
|
|
4400
|
+
const buildFeishuPostMessage = (report)=>{
|
|
4401
|
+
const content = [
|
|
4402
|
+
[
|
|
4403
|
+
{
|
|
4404
|
+
tag: "text",
|
|
4405
|
+
text: `平台:${report.platform || "未知平台"}`
|
|
4406
|
+
}
|
|
4407
|
+
],
|
|
4408
|
+
[
|
|
4409
|
+
{
|
|
4410
|
+
tag: "text",
|
|
4411
|
+
text: `错误信息:${report.msg || "未知错误信息"}`
|
|
4412
|
+
}
|
|
4413
|
+
],
|
|
4414
|
+
[
|
|
4415
|
+
{
|
|
4416
|
+
tag: "text",
|
|
4417
|
+
text: `错误类型:${report.errorType || "未知错误类型"}`
|
|
4418
|
+
}
|
|
4419
|
+
],
|
|
4420
|
+
[
|
|
4421
|
+
{
|
|
4422
|
+
tag: "text",
|
|
4423
|
+
text: `阶段:${report.stage || "未知阶段"}`
|
|
4424
|
+
}
|
|
4425
|
+
],
|
|
4426
|
+
[
|
|
4427
|
+
{
|
|
4428
|
+
tag: "text",
|
|
4429
|
+
text: `等级:${report.level}`
|
|
4430
|
+
}
|
|
4431
|
+
],
|
|
4432
|
+
[
|
|
4433
|
+
{
|
|
4434
|
+
tag: "text",
|
|
4435
|
+
text: `来源:${report.source}`
|
|
4436
|
+
}
|
|
4437
|
+
]
|
|
4438
|
+
];
|
|
4439
|
+
if (void 0 !== report.code && null !== report.code) content.push([
|
|
4440
|
+
{
|
|
4441
|
+
tag: "text",
|
|
4442
|
+
text: `接口错误码:${report.code}`
|
|
4443
|
+
}
|
|
4444
|
+
]);
|
|
4445
|
+
if (report.url) content.push([
|
|
4446
|
+
{
|
|
4447
|
+
tag: "text",
|
|
4448
|
+
text: `地址:${report.url}`
|
|
4449
|
+
}
|
|
4450
|
+
]);
|
|
4451
|
+
if ("alarm" === report.level) content.push([
|
|
4452
|
+
{
|
|
4453
|
+
tag: "at",
|
|
4454
|
+
user_id: "all"
|
|
4455
|
+
}
|
|
4456
|
+
]);
|
|
4457
|
+
return {
|
|
4458
|
+
msg_type: "post",
|
|
4459
|
+
content: {
|
|
4460
|
+
post: {
|
|
4461
|
+
zh_cn: {
|
|
4462
|
+
title: report.title || "RPA异常",
|
|
4463
|
+
content
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
4467
|
+
};
|
|
4468
|
+
};
|
|
4469
|
+
const reportFeishuAlarm = (report)=>{
|
|
4470
|
+
try {
|
|
4471
|
+
const key = `${report.platform}|${report.source}|${report.stage}|${report.errorType}|${report.code ?? ""}`;
|
|
4472
|
+
const now = Date.now();
|
|
4473
|
+
const last = lastSentAt.get(key);
|
|
4474
|
+
if (last && now - last < ALARM_THROTTLE_MS) return;
|
|
4475
|
+
pruneThrottleMap(now);
|
|
4476
|
+
lastSentAt.set(key, now);
|
|
4477
|
+
postFeishuWebhook(RPA_ERROR_WEBHOOK_URL, buildFeishuPostMessage(report)).catch(()=>{});
|
|
4478
|
+
} catch {}
|
|
4357
4479
|
};
|
|
4358
4480
|
const PROXY_CREDENTIALS = [
|
|
4359
4481
|
{
|
|
@@ -4456,9 +4578,20 @@ async function ProxyAgent(task, addr, accountId, refresh) {
|
|
|
4456
4578
|
url: "https://fetdev.iflysec.com/ip-pool/pool/eip/proxy",
|
|
4457
4579
|
data: params
|
|
4458
4580
|
}).catch((err)=>{
|
|
4581
|
+
reportFeishuAlarm({
|
|
4582
|
+
level: "alarm",
|
|
4583
|
+
platform: "ip-pool",
|
|
4584
|
+
source: "proxy",
|
|
4585
|
+
stage: "POST /ip-pool/pool/eip/proxy",
|
|
4586
|
+
errorType: "PROXY_REQUEST_FAILED",
|
|
4587
|
+
code: err?.code,
|
|
4588
|
+
msg: `请求代理失败:${err.message},区域:${addr ?? "-"},AccountId:${accountId ?? "-"}`,
|
|
4589
|
+
url: "https://fetdev.iflysec.com/ip-pool/pool/eip/proxy",
|
|
4590
|
+
title: "代理异常"
|
|
4591
|
+
});
|
|
4459
4592
|
throw {
|
|
4460
4593
|
code: 414,
|
|
4461
|
-
message:
|
|
4594
|
+
message: USER_MESSAGE.PROXY_UNAVAILABLE,
|
|
4462
4595
|
data: {}
|
|
4463
4596
|
};
|
|
4464
4597
|
});
|
|
@@ -4478,12 +4611,53 @@ async function ProxyAgent(task, addr, accountId, refresh) {
|
|
|
4478
4611
|
} : null;
|
|
4479
4612
|
return proxyAgent;
|
|
4480
4613
|
}
|
|
4614
|
+
const ALARM_STATUS = new Set([
|
|
4615
|
+
401,
|
|
4616
|
+
403,
|
|
4617
|
+
429,
|
|
4618
|
+
461,
|
|
4619
|
+
471
|
|
4620
|
+
]);
|
|
4621
|
+
const HTTP_STATUS_MESSAGE = {
|
|
4622
|
+
400: "请求参数错误,请检查参数格式是否正确!",
|
|
4623
|
+
401: "登录状态已失效,请重新登录后重试!",
|
|
4624
|
+
403: "没有访问权限,账号可能受限或签名已失效!",
|
|
4625
|
+
404: "请求的资源不存在,请检查接口地址!",
|
|
4626
|
+
405: "请求方法不被允许,请检查接口调用方式!",
|
|
4627
|
+
406: "服务端无法返回可接受的内容格式!",
|
|
4628
|
+
407: "代理需要身份验证,请检查代理配置!",
|
|
4629
|
+
408: "请求超时,请检查网络连接!",
|
|
4630
|
+
409: "请求冲突,资源状态已变更,请刷新后重试!",
|
|
4631
|
+
410: "请求的资源已被移除!",
|
|
4632
|
+
412: "请求前置条件不满足,请刷新后重试!",
|
|
4633
|
+
413: "提交内容过大,请压缩或分批后重试!",
|
|
4634
|
+
414: "请求地址过长,请检查参数!",
|
|
4635
|
+
415: "不支持的内容类型,请检查请求格式!",
|
|
4636
|
+
422: "请求内容校验失败,请检查参数内容!",
|
|
4637
|
+
423: "资源已被锁定,请稍后重试!",
|
|
4638
|
+
429: "请求过于频繁,请稍后重试!",
|
|
4639
|
+
431: "请求头过大,请清理 Cookie 后重试!",
|
|
4640
|
+
451: "内容不合规或因法律原因被拒绝!",
|
|
4641
|
+
461: "账号可能受限,请在网页上完成验证后重试!",
|
|
4642
|
+
471: "账号可能受限,请在网页上完成验证后重试!",
|
|
4643
|
+
500: "服务器内部错误,请稍后重试!",
|
|
4644
|
+
501: "服务端不支持该请求,请稍后重试!",
|
|
4645
|
+
502: "网关错误,请稍后重试!",
|
|
4646
|
+
503: "服务暂时不可用,请稍后重试!",
|
|
4647
|
+
504: "网关超时,请稍后重试!",
|
|
4648
|
+
507: "服务端存储空间不足,请稍后重试!",
|
|
4649
|
+
509: "服务带宽超限,请稍后重试!",
|
|
4650
|
+
520: "服务端返回未知错误,请稍后重试!",
|
|
4651
|
+
521: "源站拒绝连接,请稍后重试!",
|
|
4652
|
+
522: "源站连接超时,请稍后重试!",
|
|
4653
|
+
524: "源站响应超时,请稍后重试!"
|
|
4654
|
+
};
|
|
4481
4655
|
class Http {
|
|
4482
4656
|
static handleApiError(error) {
|
|
4483
4657
|
if (error && "object" == typeof error && "code" in error && "message" in error) return error;
|
|
4484
4658
|
return {
|
|
4485
4659
|
code: 500,
|
|
4486
|
-
message:
|
|
4660
|
+
message: USER_MESSAGE.SYSTEM_ERROR,
|
|
4487
4661
|
data: error
|
|
4488
4662
|
};
|
|
4489
4663
|
}
|
|
@@ -4538,6 +4712,18 @@ class Http {
|
|
|
4538
4712
|
const verifyDecision = error.response?.headers?.["x-tt-verify-passport-decision"];
|
|
4539
4713
|
if (verifyDecision) this.logger?.warn(`[403 验证决策] x-tt-verify-passport-decision: ${verifyDecision}`);
|
|
4540
4714
|
}
|
|
4715
|
+
if (error.response?.status === 461 || error.response?.status === 471) {
|
|
4716
|
+
const h = error.response?.headers ?? {};
|
|
4717
|
+
const pick = (name)=>h[name] ?? h[name.toLowerCase()];
|
|
4718
|
+
this.logger?.warn(`[${error.response.status} 风控验证] URL: ${error.config?.url} Verifytype: ${pick("Verifytype") ?? "-"} Verifyuuid: ${pick("Verifyuuid") ?? "-"} Verifybiz: ${pick("Verifybiz") ?? "-"}`);
|
|
4719
|
+
this.logger?.warn(`[${error.response.status} 响应头] ${JSON.stringify(h)}`);
|
|
4720
|
+
errorResponse.extra = {
|
|
4721
|
+
...errorResponse.extra,
|
|
4722
|
+
verifyType: pick("Verifytype"),
|
|
4723
|
+
verifyUuid: pick("Verifyuuid"),
|
|
4724
|
+
verifyBiz: pick("Verifybiz")
|
|
4725
|
+
};
|
|
4726
|
+
}
|
|
4541
4727
|
if (error.response?.data) {
|
|
4542
4728
|
if ("object" == typeof error.response.data) {
|
|
4543
4729
|
const serverError = error.response.data;
|
|
@@ -4568,11 +4754,17 @@ class Http {
|
|
|
4568
4754
|
_message = "DNS 查询超时,请稍后重试!";
|
|
4569
4755
|
break;
|
|
4570
4756
|
case "ERR_BAD_REQUEST":
|
|
4571
|
-
|
|
4572
|
-
|
|
4757
|
+
{
|
|
4758
|
+
const status = error.response?.status;
|
|
4759
|
+
_message = status && HTTP_STATUS_MESSAGE[status] || `请求失败,状态码${status ?? "unknown"}!`;
|
|
4760
|
+
break;
|
|
4761
|
+
}
|
|
4573
4762
|
case "ERR_BAD_RESPONSE":
|
|
4574
|
-
|
|
4575
|
-
|
|
4763
|
+
{
|
|
4764
|
+
const status = error.response?.status;
|
|
4765
|
+
_message = status && HTTP_STATUS_MESSAGE[status] || `服务器响应异常 (${status ?? "unknown"}),请稍后重试!`;
|
|
4766
|
+
break;
|
|
4767
|
+
}
|
|
4576
4768
|
case "ERR_CANCELED":
|
|
4577
4769
|
errorResponse.code = 414;
|
|
4578
4770
|
_message = "请求连接超时,请稍候重试!";
|
|
@@ -4583,11 +4775,14 @@ class Http {
|
|
|
4583
4775
|
}
|
|
4584
4776
|
break;
|
|
4585
4777
|
default:
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4778
|
+
{
|
|
4779
|
+
this.logger?.debug(`未处理的网络错误代码: ${error.code} ${error.message}`, {
|
|
4780
|
+
errorString: stringifyError(error)
|
|
4781
|
+
});
|
|
4782
|
+
const status = error.response?.status;
|
|
4783
|
+
_message = status && HTTP_STATUS_MESSAGE[status] || USER_MESSAGE.NETWORK_ERROR;
|
|
4784
|
+
break;
|
|
4785
|
+
}
|
|
4591
4786
|
}
|
|
4592
4787
|
}
|
|
4593
4788
|
if (error.code && !error.response?.data) errorResponse.message = _message || errorResponse.message;
|
|
@@ -4597,29 +4792,62 @@ class Http {
|
|
|
4597
4792
|
errorResponse.message = message;
|
|
4598
4793
|
}
|
|
4599
4794
|
if (error.message.includes("Proxy connection ended")) errorResponse.message = "所在区域代理连接超时,请更换区域或稍后重试!";
|
|
4795
|
+
errorResponse.extra = {
|
|
4796
|
+
...errorResponse.extra,
|
|
4797
|
+
alarmStatus: error.response?.status,
|
|
4798
|
+
alarmErrorCode: error.code
|
|
4799
|
+
};
|
|
4600
4800
|
throw errorResponse;
|
|
4601
4801
|
});
|
|
4602
4802
|
}
|
|
4803
|
+
reportRequestFailure(config, error, attempts) {
|
|
4804
|
+
const status = error.extra?.alarmStatus;
|
|
4805
|
+
const axiosCode = error.extra?.alarmErrorCode;
|
|
4806
|
+
const method = (config.method || "get").toUpperCase();
|
|
4807
|
+
const url = config.url || "-";
|
|
4808
|
+
const retriedSuffix = attempts > 0 ? `(已重试${attempts}次仍失败)` : "";
|
|
4809
|
+
reportFeishuAlarm({
|
|
4810
|
+
level: status && ALARM_STATUS.has(status) ? "alarm" : "warning",
|
|
4811
|
+
platform: this.platform || "unknown",
|
|
4812
|
+
source: "http",
|
|
4813
|
+
stage: `${method} ${url}`,
|
|
4814
|
+
errorType: status ? `HTTP_${status}` : axiosCode || "NETWORK_ERROR",
|
|
4815
|
+
code: error.code,
|
|
4816
|
+
msg: `${error.message}${retriedSuffix}`,
|
|
4817
|
+
url: config.url,
|
|
4818
|
+
title: "RPA接口异常"
|
|
4819
|
+
});
|
|
4820
|
+
}
|
|
4603
4821
|
async api(config, options) {
|
|
4604
4822
|
const retries = options?.retries ?? 0;
|
|
4605
4823
|
const retryDelay = options?.retryDelay ?? 500;
|
|
4606
|
-
const reqTimeout = options?.timeout ??
|
|
4824
|
+
const reqTimeout = options?.timeout ?? 60000;
|
|
4825
|
+
const externalSignal = options?.signal;
|
|
4607
4826
|
let agent;
|
|
4608
4827
|
const sessionRt = async (Rtimes)=>{
|
|
4609
4828
|
try {
|
|
4610
4829
|
this.proxyInfo = agent ? `${agent.ip}:${agent.port}` : void 0;
|
|
4611
4830
|
const controller = new AbortController();
|
|
4612
4831
|
const timeoutId = setTimeout(()=>controller.abort(), reqTimeout + 500);
|
|
4832
|
+
const forwardAbort = ()=>controller.abort();
|
|
4833
|
+
if (externalSignal) {
|
|
4834
|
+
if (externalSignal.aborted) controller.abort();
|
|
4835
|
+
else externalSignal.addEventListener("abort", forwardAbort, {
|
|
4836
|
+
once: true
|
|
4837
|
+
});
|
|
4838
|
+
}
|
|
4613
4839
|
const response = await this.apiClient({
|
|
4614
4840
|
...config,
|
|
4615
4841
|
timeout: reqTimeout,
|
|
4616
4842
|
signal: controller.signal,
|
|
4843
|
+
onUploadProgress: options?.onUploadProgress,
|
|
4617
4844
|
...agent ? {
|
|
4618
4845
|
httpAgent: agent.agent,
|
|
4619
4846
|
httpsAgent: agent.agent
|
|
4620
4847
|
} : {}
|
|
4621
4848
|
}).finally(()=>{
|
|
4622
4849
|
clearTimeout(timeoutId);
|
|
4850
|
+
externalSignal?.removeEventListener("abort", forwardAbort);
|
|
4623
4851
|
});
|
|
4624
4852
|
return response.data;
|
|
4625
4853
|
} catch (error) {
|
|
@@ -4634,10 +4862,12 @@ class Http {
|
|
|
4634
4862
|
].includes(handledError.code);
|
|
4635
4863
|
if (Rtimes < retries && isRetry) {
|
|
4636
4864
|
const url = config.url || "";
|
|
4637
|
-
|
|
4638
|
-
|
|
4865
|
+
const backoff = Math.min(retryDelay * 2 ** Rtimes, 5000);
|
|
4866
|
+
this.logger?.warn(`进入第${Rtimes + 1}次重试!错误码: ${handledError.code}, 等待: ${backoff}ms, 请求地址: ${url}`);
|
|
4867
|
+
await new Promise((resolve)=>setTimeout(resolve, backoff));
|
|
4639
4868
|
return sessionRt(Rtimes + 1);
|
|
4640
4869
|
}
|
|
4870
|
+
this.reportRequestFailure(config, handledError, Rtimes);
|
|
4641
4871
|
return Promise.reject(handledError);
|
|
4642
4872
|
}
|
|
4643
4873
|
};
|
|
@@ -5364,7 +5594,7 @@ const NUMBER_FORMAT_RANGES = {
|
|
|
5364
5594
|
Number.MAX_VALUE
|
|
5365
5595
|
]
|
|
5366
5596
|
};
|
|
5367
|
-
function
|
|
5597
|
+
function util_pick(schema, mask) {
|
|
5368
5598
|
const currDef = schema._zod.def;
|
|
5369
5599
|
const def = mergeDefs(schema._zod.def, {
|
|
5370
5600
|
get shape () {
|
|
@@ -5734,7 +5964,7 @@ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
|
5734
5964
|
const xid = /^[0-9a-vA-V]{20}$/;
|
|
5735
5965
|
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
5736
5966
|
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
5737
|
-
const
|
|
5967
|
+
const regexes_duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
5738
5968
|
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
5739
5969
|
const regexes_uuid = (version)=>{
|
|
5740
5970
|
if (!version) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
@@ -6420,7 +6650,7 @@ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def)=>{
|
|
|
6420
6650
|
$ZodStringFormat.init(inst, def);
|
|
6421
6651
|
});
|
|
6422
6652
|
const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def)=>{
|
|
6423
|
-
def.pattern ?? (def.pattern =
|
|
6653
|
+
def.pattern ?? (def.pattern = regexes_duration);
|
|
6424
6654
|
$ZodStringFormat.init(inst, def);
|
|
6425
6655
|
});
|
|
6426
6656
|
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def)=>{
|
|
@@ -8345,7 +8575,7 @@ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def)=>{
|
|
|
8345
8575
|
inst.extend = (incoming)=>extend(inst, incoming);
|
|
8346
8576
|
inst.safeExtend = (incoming)=>safeExtend(inst, incoming);
|
|
8347
8577
|
inst.merge = (other)=>merge(inst, other);
|
|
8348
|
-
inst.pick = (mask)=>
|
|
8578
|
+
inst.pick = (mask)=>util_pick(inst, mask);
|
|
8349
8579
|
inst.omit = (mask)=>omit(inst, mask);
|
|
8350
8580
|
inst.partial = (...args)=>partial(ZodOptional, inst, args[0]);
|
|
8351
8581
|
inst.required = (...args)=>required(ZodNonOptional, inst, args[0]);
|
|
@@ -8358,6 +8588,14 @@ function schemas_object(shape, params) {
|
|
|
8358
8588
|
};
|
|
8359
8589
|
return new ZodObject(def);
|
|
8360
8590
|
}
|
|
8591
|
+
function looseObject(shape, params) {
|
|
8592
|
+
return new ZodObject({
|
|
8593
|
+
type: "object",
|
|
8594
|
+
shape,
|
|
8595
|
+
catchall: unknown(),
|
|
8596
|
+
...normalizeParams(params)
|
|
8597
|
+
});
|
|
8598
|
+
}
|
|
8361
8599
|
const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def)=>{
|
|
8362
8600
|
$ZodUnion.init(inst, def);
|
|
8363
8601
|
ZodType.init(inst, def);
|
|
@@ -9054,6 +9292,13 @@ const mockAction = async (task, params)=>{
|
|
|
9054
9292
|
data: ""
|
|
9055
9293
|
};
|
|
9056
9294
|
const image = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
9295
|
+
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(image);
|
|
9296
|
+
const maxSize = 5242880;
|
|
9297
|
+
if (stats.size > maxSize) throw {
|
|
9298
|
+
code: 414,
|
|
9299
|
+
message: "百家号平台:单张图片不得超过 5MB",
|
|
9300
|
+
data: ""
|
|
9301
|
+
};
|
|
9057
9302
|
const formData = new __WEBPACK_EXTERNAL_MODULE_form_data_cf000082__["default"]();
|
|
9058
9303
|
formData.append("org_file_name", fileName);
|
|
9059
9304
|
formData.append("type", "image");
|
|
@@ -9724,7 +9969,8 @@ const XhsFansExport = async (_task, params)=>{
|
|
|
9724
9969
|
},
|
|
9725
9970
|
_task.logger,
|
|
9726
9971
|
params.proxyLoc,
|
|
9727
|
-
params.accountId
|
|
9972
|
+
params.accountId,
|
|
9973
|
+
"xiaohongshu"
|
|
9728
9974
|
];
|
|
9729
9975
|
const http = new Http(...args);
|
|
9730
9976
|
const fans = {
|
|
@@ -9738,8 +9984,8 @@ const XhsFansExport = async (_task, params)=>{
|
|
|
9738
9984
|
url: "https://creator.xiaohongshu.com/api/galaxy/creator/home/personal_info"
|
|
9739
9985
|
}, {
|
|
9740
9986
|
retries: 3,
|
|
9741
|
-
retryDelay:
|
|
9742
|
-
timeout:
|
|
9987
|
+
retryDelay: 300,
|
|
9988
|
+
timeout: 30000
|
|
9743
9989
|
});
|
|
9744
9990
|
fans.fans_count = Number(res.data.fans_count);
|
|
9745
9991
|
fans.digg_count = Number(res.data.faved_count);
|
|
@@ -10876,7 +11122,8 @@ const XhsSessionCheck = async (_task, params)=>{
|
|
|
10876
11122
|
},
|
|
10877
11123
|
_task.logger,
|
|
10878
11124
|
params.proxyLoc,
|
|
10879
|
-
params.accountId
|
|
11125
|
+
params.accountId,
|
|
11126
|
+
"xiaohongshu"
|
|
10880
11127
|
];
|
|
10881
11128
|
const http = new Http(...args);
|
|
10882
11129
|
http.addResponseInterceptor((response)=>{
|
|
@@ -10924,8 +11171,8 @@ const XhsSessionCheck = async (_task, params)=>{
|
|
|
10924
11171
|
headers: loginBaseXsHeader
|
|
10925
11172
|
}, {
|
|
10926
11173
|
retries: 3,
|
|
10927
|
-
retryDelay:
|
|
10928
|
-
timeout:
|
|
11174
|
+
retryDelay: 300,
|
|
11175
|
+
timeout: 30000
|
|
10929
11176
|
}).catch((e)=>{
|
|
10930
11177
|
const clientTimestamp = Date.now();
|
|
10931
11178
|
const serverDate = e?.extra?.serverDate;
|
|
@@ -10957,8 +11204,8 @@ const XhsSessionCheck = async (_task, params)=>{
|
|
|
10957
11204
|
headers: webSessionXsHeader
|
|
10958
11205
|
}, {
|
|
10959
11206
|
retries: 3,
|
|
10960
|
-
retryDelay:
|
|
10961
|
-
timeout:
|
|
11207
|
+
retryDelay: 300,
|
|
11208
|
+
timeout: 30000
|
|
10962
11209
|
});
|
|
10963
11210
|
const [baseInfo, web_session] = await Promise.all([
|
|
10964
11211
|
_baseInfo,
|
|
@@ -11050,6 +11297,10 @@ const ShipinhaoSessionCheck = async (_task, params)=>{
|
|
|
11050
11297
|
};
|
|
11051
11298
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(data, message);
|
|
11052
11299
|
};
|
|
11300
|
+
const extractEncFileKey = (downloadUrl)=>{
|
|
11301
|
+
if (!downloadUrl) return "";
|
|
11302
|
+
return downloadUrl.split("encfilekey=")[1]?.split("&")[0] || "";
|
|
11303
|
+
};
|
|
11053
11304
|
const rid = ()=>`${Math.floor(Date.now() / 1e3).toString(16)}-${[
|
|
11054
11305
|
...Array(8)
|
|
11055
11306
|
].map(()=>Math.floor(16 * Math.random()).toString(16)).join("")}`;
|
|
@@ -12334,7 +12585,7 @@ const douyinGetVerifyQrCode = async (task, params)=>{
|
|
|
12334
12585
|
});
|
|
12335
12586
|
const qrData = qrCodeResponse?.data;
|
|
12336
12587
|
task.logger.info(`获取二维码响应: error_code=${qrData?.error_code}, message=${qrCodeResponse?.message}`);
|
|
12337
|
-
if (qrData?.error_code !== 0) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414,
|
|
12588
|
+
if (qrData?.error_code !== 0) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, USER_MESSAGE.QRCODE_FETCH_FAILED, "");
|
|
12338
12589
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(0, "获取二维码成功", {
|
|
12339
12590
|
qrcode: qrData.qrcode,
|
|
12340
12591
|
token: qrData.token,
|
|
@@ -12349,7 +12600,7 @@ const douyinGetVerifyQrCode = async (task, params)=>{
|
|
|
12349
12600
|
} catch (err) {
|
|
12350
12601
|
const msg = err instanceof Error ? err.message : String(err);
|
|
12351
12602
|
task.logger.warn(`[douyinGetVerifyQrCode] 获取二维码失败: ${msg}`);
|
|
12352
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(500,
|
|
12603
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(500, USER_MESSAGE.QRCODE_FETCH_FAILED, "");
|
|
12353
12604
|
}
|
|
12354
12605
|
};
|
|
12355
12606
|
const DouyinGetWorkListParamsSchema = ActionCommonParamsSchema.extend({
|
|
@@ -13184,6 +13435,11 @@ class DouyinImageUploader {
|
|
|
13184
13435
|
}
|
|
13185
13436
|
async getImageInfo(localPath) {
|
|
13186
13437
|
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(localPath);
|
|
13438
|
+
const maxSize = 52428800;
|
|
13439
|
+
if (stats.size > maxSize) {
|
|
13440
|
+
__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(localPath);
|
|
13441
|
+
throw new Error("抖音平台:单张图片不得超过 50MB");
|
|
13442
|
+
}
|
|
13187
13443
|
let width = 1080;
|
|
13188
13444
|
let height = 1920;
|
|
13189
13445
|
try {
|
|
@@ -13664,18 +13920,10 @@ const mock_mockAction = async (task, params)=>{
|
|
|
13664
13920
|
});
|
|
13665
13921
|
} catch (error) {
|
|
13666
13922
|
const handledError = Http.handleApiError(error);
|
|
13667
|
-
const
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
503,
|
|
13672
|
-
504
|
|
13673
|
-
].includes(handledError.code);
|
|
13674
|
-
if (isProxyOrNetworkError) {
|
|
13675
|
-
const isProxyRequest = handledError.extra?.isProxyRequest === true;
|
|
13676
|
-
const errorType = 599 === handledError.code || isProxyRequest ? "代理错误" : "网络错误";
|
|
13677
|
-
const message = `图文发布失败,${errorType}:${handledError.message}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
13678
|
-
task.logger.error(`[douyinPublish] ${errorType},直接返回: ${message}`, stringifyError(handledError));
|
|
13923
|
+
const classified = classifyPublishError(handledError);
|
|
13924
|
+
if (classified) {
|
|
13925
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
13926
|
+
task.logger.error(`[douyinPublish] ${classified.category},直接返回: ${handledError.message} (code=${handledError.code})`, stringifyError(handledError));
|
|
13679
13927
|
await updateTaskState?.({
|
|
13680
13928
|
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
13681
13929
|
error: message
|
|
@@ -15207,7 +15455,8 @@ const getXhsUnreadCount = async (_task, params)=>{
|
|
|
15207
15455
|
},
|
|
15208
15456
|
_task.logger,
|
|
15209
15457
|
params.proxyLoc,
|
|
15210
|
-
params.accountId
|
|
15458
|
+
params.accountId,
|
|
15459
|
+
"xiaohongshu"
|
|
15211
15460
|
];
|
|
15212
15461
|
const http = new Http(...args);
|
|
15213
15462
|
let unreadCount = {
|
|
@@ -15236,8 +15485,8 @@ const getXhsUnreadCount = async (_task, params)=>{
|
|
|
15236
15485
|
headers: xsHeader
|
|
15237
15486
|
}, {
|
|
15238
15487
|
retries: 3,
|
|
15239
|
-
retryDelay:
|
|
15240
|
-
timeout:
|
|
15488
|
+
retryDelay: 300,
|
|
15489
|
+
timeout: 30000
|
|
15241
15490
|
});
|
|
15242
15491
|
const isSuccess = 0 === res.code;
|
|
15243
15492
|
if (isSuccess) unreadCount = res.data;
|
|
@@ -15393,7 +15642,7 @@ async function getDouyinData(_task, params) {
|
|
|
15393
15642
|
}
|
|
15394
15643
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
15395
15644
|
_task.logger.error(`抖音账号数据获取失败: ${errMsg}`);
|
|
15396
|
-
return types_errorResponse(
|
|
15645
|
+
return types_errorResponse(USER_MESSAGE.DOUYIN_ACCOUNT_FETCH_FAILED);
|
|
15397
15646
|
}
|
|
15398
15647
|
}
|
|
15399
15648
|
async function getShipinhaoData(_task, params) {
|
|
@@ -15524,7 +15773,7 @@ async function getShipinhaoData(_task, params) {
|
|
|
15524
15773
|
}
|
|
15525
15774
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
15526
15775
|
_task.logger.error(`视频号账号数据获取失败: ${errMsg}`);
|
|
15527
|
-
return types_errorResponse(
|
|
15776
|
+
return types_errorResponse(USER_MESSAGE.SHIPINHAO_ACCOUNT_FETCH_FAILED);
|
|
15528
15777
|
}
|
|
15529
15778
|
}
|
|
15530
15779
|
async function getToutiaoData(_task, params) {
|
|
@@ -15648,7 +15897,8 @@ async function getXiaohongshuData(_task, params) {
|
|
|
15648
15897
|
},
|
|
15649
15898
|
_task.logger,
|
|
15650
15899
|
params.proxyLoc,
|
|
15651
|
-
params.accountId
|
|
15900
|
+
params.accountId,
|
|
15901
|
+
"xiaohongshu"
|
|
15652
15902
|
];
|
|
15653
15903
|
const http = new Http(...args);
|
|
15654
15904
|
const xsEncrypt = new Xhshow();
|
|
@@ -15664,8 +15914,8 @@ async function getXiaohongshuData(_task, params) {
|
|
|
15664
15914
|
url: "https://creator.xiaohongshu.com/api/galaxy/creator/home/personal_info"
|
|
15665
15915
|
}, {
|
|
15666
15916
|
retries: 3,
|
|
15667
|
-
retryDelay:
|
|
15668
|
-
timeout:
|
|
15917
|
+
retryDelay: 300,
|
|
15918
|
+
timeout: 30000
|
|
15669
15919
|
}),
|
|
15670
15920
|
http.api({
|
|
15671
15921
|
method: "get",
|
|
@@ -15674,8 +15924,8 @@ async function getXiaohongshuData(_task, params) {
|
|
|
15674
15924
|
headers: sevenDataXsHeader
|
|
15675
15925
|
}, {
|
|
15676
15926
|
retries: 3,
|
|
15677
|
-
retryDelay:
|
|
15678
|
-
timeout:
|
|
15927
|
+
retryDelay: 300,
|
|
15928
|
+
timeout: 30000
|
|
15679
15929
|
})
|
|
15680
15930
|
]);
|
|
15681
15931
|
const xhsData = {
|
|
@@ -15963,7 +16213,9 @@ async function handleBaijiahaoData(_task, params) {
|
|
|
15963
16213
|
} : null
|
|
15964
16214
|
}, "百家号文章数据获取成功");
|
|
15965
16215
|
} catch (error) {
|
|
15966
|
-
|
|
16216
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
16217
|
+
_task.logger.error(`百家号文章数据获取失败: ${errMsg}`);
|
|
16218
|
+
return searchPublishInfo_types_errorResponse(USER_MESSAGE.BJH_POST_FETCH_FAILED);
|
|
15967
16219
|
}
|
|
15968
16220
|
}
|
|
15969
16221
|
async function handleDouyinData(_task, params) {
|
|
@@ -16058,7 +16310,9 @@ async function handleDouyinData(_task, params) {
|
|
|
16058
16310
|
} : null
|
|
16059
16311
|
}, "抖音数据获取成功");
|
|
16060
16312
|
} catch (error) {
|
|
16061
|
-
|
|
16313
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
16314
|
+
_task.logger.error(`抖音作品数据获取失败: ${errMsg}`);
|
|
16315
|
+
return searchPublishInfo_types_errorResponse(USER_MESSAGE.DOUYIN_POST_FETCH_FAILED);
|
|
16062
16316
|
}
|
|
16063
16317
|
}
|
|
16064
16318
|
async function handleShipinhaoData(_task, params) {
|
|
@@ -16223,8 +16477,9 @@ async function handleShipinhaoData(_task, params) {
|
|
|
16223
16477
|
}, "视频号数据获取成功");
|
|
16224
16478
|
} catch (error) {
|
|
16225
16479
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
16480
|
+
_task.logger.error(`视频号作品数据获取失败: ${errMsg}`);
|
|
16226
16481
|
if (errMsg.startsWith("AUTH_ERROR:")) return searchPublishInfo_types_errorResponse("视频号数据获取失败,请检查账号状态", 414);
|
|
16227
|
-
return searchPublishInfo_types_errorResponse(
|
|
16482
|
+
return searchPublishInfo_types_errorResponse(USER_MESSAGE.SHIPINHAO_POST_FETCH_FAILED);
|
|
16228
16483
|
}
|
|
16229
16484
|
}
|
|
16230
16485
|
async function handleToutiaoData(_task, params) {
|
|
@@ -16309,7 +16564,9 @@ async function handleToutiaoData(_task, params) {
|
|
|
16309
16564
|
} : null
|
|
16310
16565
|
}, "头条号文章文章获取成功");
|
|
16311
16566
|
} catch (error) {
|
|
16312
|
-
|
|
16567
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
16568
|
+
_task.logger.error(`头条号文章数据获取失败: ${errMsg}`);
|
|
16569
|
+
return searchPublishInfo_types_errorResponse(USER_MESSAGE.TT_POST_FETCH_FAILED);
|
|
16313
16570
|
}
|
|
16314
16571
|
}
|
|
16315
16572
|
async function handleWeixinData(_task, params) {
|
|
@@ -18684,18 +18941,10 @@ const shipinhaoPublish_mock_mockAction = async (task, params)=>{
|
|
|
18684
18941
|
});
|
|
18685
18942
|
} catch (error) {
|
|
18686
18943
|
const handledError = Http.handleApiError(error);
|
|
18687
|
-
const
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
503,
|
|
18692
|
-
504
|
|
18693
|
-
].includes(handledError.code);
|
|
18694
|
-
if (isProxyOrNetworkError) {
|
|
18695
|
-
const isProxyRequest = handledError.extra?.isProxyRequest === true;
|
|
18696
|
-
const errorType = 599 === handledError.code || isProxyRequest ? "代理错误" : "网络错误";
|
|
18697
|
-
const message = `图文发布失败,${errorType}:${handledError.message}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
18698
|
-
task.logger.error(`[shipinhaoPublish] ${errorType},直接返回: ${message}`, stringifyError(handledError));
|
|
18944
|
+
const classified = classifyPublishError(handledError);
|
|
18945
|
+
if (classified) {
|
|
18946
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
18947
|
+
task.logger.error(`[shipinhaoPublish] ${classified.category},直接返回: ${handledError.message} (code=${handledError.code})`, stringifyError(handledError));
|
|
18699
18948
|
await updateTaskState?.({
|
|
18700
18949
|
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
18701
18950
|
error: message
|
|
@@ -18713,7 +18962,7 @@ const shipinhaoPublish_mock_mockAction = async (task, params)=>{
|
|
|
18713
18962
|
const resultMsg = publishResult.data?.baseResp?.errmsg ?? publishResult.errMsg;
|
|
18714
18963
|
if (0 === resultCode) {
|
|
18715
18964
|
task.logger.info("[shipinhaoPublish] 发布成功");
|
|
18716
|
-
const publishId = uploadedImages[0]?.thumbUrl
|
|
18965
|
+
const publishId = extractEncFileKey(uploadedImages[0]?.thumbUrl);
|
|
18717
18966
|
await updateTaskState?.({
|
|
18718
18967
|
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.SUCCESS,
|
|
18719
18968
|
result: {
|
|
@@ -19435,167 +19684,1756 @@ const shipinhaoPublish = async (task, params)=>{
|
|
|
19435
19684
|
if ("server" === params.actionType) return rpa_server_rpaAction_Server(task, params);
|
|
19436
19685
|
return executeAction(shipinhaoPublish_mock_mockAction, rpa_server_rpaAction_Server)(task, params);
|
|
19437
19686
|
};
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
sessionId: schemas_string().min(1, "会话ID不能为空"),
|
|
19441
|
-
msgType: schemas_enum([
|
|
19442
|
-
"TEXT",
|
|
19443
|
-
"IMAGE"
|
|
19444
|
-
], {
|
|
19445
|
-
message: "消息类型必须是 TEXT 或 IMAGE"
|
|
19446
|
-
}),
|
|
19447
|
-
content: schemas_string().optional(),
|
|
19448
|
-
imageInfo: schemas_object({
|
|
19449
|
-
pathOrUrl: schemas_string().min(1, "图片路径或URL不能为空")
|
|
19450
|
-
}).optional()
|
|
19451
|
-
});
|
|
19452
|
-
const CHUNK_SIZE = 524288;
|
|
19453
|
-
async function shipinhaoSendMsg_getUserInfo(cookieStr, http) {
|
|
19454
|
-
const url = `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data?_rid=${rid()}`;
|
|
19455
|
-
const headers = {
|
|
19456
|
-
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
19457
|
-
cookie: cookieStr,
|
|
19458
|
-
Origin: "https://channels.weixin.qq.com"
|
|
19459
|
-
};
|
|
19460
|
-
return await http.api({
|
|
19461
|
-
method: "get",
|
|
19462
|
-
url,
|
|
19463
|
-
headers
|
|
19464
|
-
}, {
|
|
19465
|
-
retries: 3,
|
|
19466
|
-
retryDelay: 1000,
|
|
19467
|
-
timeout: 10000
|
|
19468
|
-
});
|
|
19687
|
+
function auth_getTimeStamp(length) {
|
|
19688
|
+
return Date.now().toString().substring(0, length);
|
|
19469
19689
|
}
|
|
19470
|
-
|
|
19471
|
-
|
|
19472
|
-
if (!params.toUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "接收者用户名不能为空", void 0);
|
|
19473
|
-
if (!params.msgType) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型不能为空", void 0);
|
|
19474
|
-
if (![
|
|
19475
|
-
"TEXT",
|
|
19476
|
-
"IMAGE"
|
|
19477
|
-
].includes(params.msgType)) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型必须是 TEXT 或 IMAGE", void 0);
|
|
19478
|
-
if ("TEXT" === params.msgType) {
|
|
19479
|
-
if (!params.content || "" === params.content.trim()) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息内容不能为空", void 0);
|
|
19480
|
-
}
|
|
19481
|
-
if ("IMAGE" === params.msgType) {
|
|
19482
|
-
if (!params.imageInfo?.pathOrUrl) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "图片路径或URL不能为空", void 0);
|
|
19483
|
-
}
|
|
19484
|
-
if (!params.extraParam) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "缺少 extraParam 参数", void 0);
|
|
19485
|
-
if (!params.extraParam.fingerPrintDeviceId || !params.extraParam.aId || !params.extraParam.uin) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "fingerPrintDeviceId、aId 和 uin 不能为空", void 0);
|
|
19486
|
-
const cookieStr = params.cookies.map((it)=>`${it.name}=${it.value}`).join(";");
|
|
19487
|
-
const headers = {
|
|
19488
|
-
cookie: cookieStr,
|
|
19489
|
-
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
19490
|
-
origin: "https://channels.weixin.qq.com",
|
|
19491
|
-
"content-type": "application/json",
|
|
19492
|
-
"finger-print-device-id": params.extraParam.fingerPrintDeviceId,
|
|
19493
|
-
"x-wechat-uin": params.extraParam.uin
|
|
19494
|
-
};
|
|
19495
|
-
const http = new Http({
|
|
19496
|
-
headers
|
|
19497
|
-
});
|
|
19498
|
-
const urlParams = new URLSearchParams({
|
|
19499
|
-
_aid: params.extraParam.aId,
|
|
19500
|
-
_rid: rid(),
|
|
19501
|
-
_pageUrl: "https://channels.weixin.qq.com/micro/interaction/private_msg"
|
|
19502
|
-
}).toString();
|
|
19503
|
-
const generateCliMsgId = ()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (s)=>{
|
|
19504
|
-
const t = 16 * Math.random() | 0;
|
|
19505
|
-
return ("x" === s ? t : 3 & t | 8).toString(16);
|
|
19506
|
-
});
|
|
19507
|
-
let fromUsername = params.extraParam.finderUserName;
|
|
19508
|
-
if (!fromUsername) {
|
|
19509
|
-
_task.logger.info("未提供 finderUserName,尝试获取用户信息");
|
|
19510
|
-
const userInfoRes = await shipinhaoSendMsg_getUserInfo(cookieStr, http);
|
|
19511
|
-
if (!userInfoRes.data?.finderUser?.finderUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(userInfoRes.errCode || -1, userInfoRes.errMsg || "获取用户信息失败", {});
|
|
19512
|
-
fromUsername = userInfoRes.data.finderUser.finderUsername;
|
|
19513
|
-
_task.logger.info(`获取到用户名: ${fromUsername}`);
|
|
19514
|
-
}
|
|
19515
|
-
let imgMsg;
|
|
19516
|
-
if ("IMAGE" === params.msgType) {
|
|
19517
|
-
let imageBuffer;
|
|
19518
|
-
const imagePath = params.imageInfo.pathOrUrl;
|
|
19519
|
-
try {
|
|
19520
|
-
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
|
|
19521
|
-
const resp = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(imagePath, {
|
|
19522
|
-
responseType: "arraybuffer"
|
|
19523
|
-
});
|
|
19524
|
-
imageBuffer = Buffer.from(resp.data);
|
|
19525
|
-
} else {
|
|
19526
|
-
const filePath = imagePath.startsWith("file://") ? imagePath.slice(7) : imagePath;
|
|
19527
|
-
imageBuffer = Buffer.from(await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.readFile(filePath));
|
|
19528
|
-
}
|
|
19529
|
-
} catch (err) {
|
|
19530
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, `读取图片失败: ${err instanceof Error ? err.message : String(err)}`, void 0);
|
|
19531
|
-
}
|
|
19532
|
-
const md5 = (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)("md5").update(imageBuffer).digest("hex");
|
|
19533
|
-
const timestamp = Date.now().toString();
|
|
19534
|
-
const totalChunks = Math.ceil(imageBuffer.length / CHUNK_SIZE);
|
|
19535
|
-
console.log(`分片上传md5${md5}`);
|
|
19536
|
-
let lastRes;
|
|
19537
|
-
for(let i = 0; i < totalChunks; i++){
|
|
19538
|
-
const chunkBuffer = imageBuffer.slice(i * CHUNK_SIZE, (i + 1) * CHUNK_SIZE);
|
|
19539
|
-
const requestData = {
|
|
19540
|
-
content: `data:application/octet-stream;base64,${chunkBuffer.toString("base64")}`,
|
|
19541
|
-
chunk: i,
|
|
19542
|
-
chunks: totalChunks,
|
|
19543
|
-
fromUsername,
|
|
19544
|
-
toUsername: params.toUsername,
|
|
19545
|
-
aesKey: "U2FsdGVkX18cwrWR73LMGhBcmAX8xoNTgbmgkZBYkEs=",
|
|
19546
|
-
mediaSize: imageBuffer.length,
|
|
19547
|
-
mediaType: 3,
|
|
19548
|
-
md5,
|
|
19549
|
-
timestamp,
|
|
19550
|
-
_log_finder_uin: "",
|
|
19551
|
-
_log_finder_id: params.extraParam.finderUserName || "",
|
|
19552
|
-
rawKeyBuff: null,
|
|
19553
|
-
pluginSessionId: null,
|
|
19554
|
-
scene: 7,
|
|
19555
|
-
reqScene: 7
|
|
19556
|
-
};
|
|
19557
|
-
lastRes = await http.api({
|
|
19558
|
-
method: "post",
|
|
19559
|
-
url: `https://channels.weixin.qq.com/micro/interaction/cgi-bin/mmfinderassistant-bin/private-msg/upload-media-info?${urlParams}`,
|
|
19560
|
-
data: requestData
|
|
19561
|
-
});
|
|
19562
|
-
console.log(`分片上传 ${i + 1}/${totalChunks} 响应:`, lastRes);
|
|
19563
|
-
if (lastRes?.errCode !== 0 && i < totalChunks - 1) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || `第 ${i + 1}/${totalChunks} 分片上传失败`, void 0);
|
|
19564
|
-
}
|
|
19565
|
-
if (lastRes?.errCode !== 0) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || "上传图片失败", void 0);
|
|
19566
|
-
const uploadedImgMsg = lastRes.data?.imgMsg;
|
|
19567
|
-
imgMsg = {
|
|
19568
|
-
aeskey: uploadedImgMsg.aesKey ?? uploadedImgMsg.aeskey,
|
|
19569
|
-
url: uploadedImgMsg.cdnUrl ?? uploadedImgMsg.url,
|
|
19570
|
-
hdSize: uploadedImgMsg.hdSize ?? uploadedImgMsg.size,
|
|
19571
|
-
midSize: uploadedImgMsg.midSize ?? uploadedImgMsg.size,
|
|
19572
|
-
thumbSize: uploadedImgMsg.thumbSize ?? uploadedImgMsg.size,
|
|
19573
|
-
thumbHeight: uploadedImgMsg.thumbHeight ?? uploadedImgMsg.height,
|
|
19574
|
-
thumbWidth: uploadedImgMsg.thumbWidth ?? uploadedImgMsg.width,
|
|
19575
|
-
md5: uploadedImgMsg.md5
|
|
19576
|
-
};
|
|
19577
|
-
}
|
|
19578
|
-
console.log("发送私信请求参数1111", {
|
|
19579
|
-
sessionId: params.sessionId,
|
|
19580
|
-
fromUsername
|
|
19581
|
-
});
|
|
19582
|
-
const sendRes = await http.api({
|
|
19690
|
+
async function auth_getUserInfo(cookies, http) {
|
|
19691
|
+
return http.api({
|
|
19583
19692
|
method: "post",
|
|
19584
|
-
url:
|
|
19693
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data",
|
|
19585
19694
|
data: {
|
|
19586
|
-
timestamp:
|
|
19695
|
+
timestamp: auth_getTimeStamp(13),
|
|
19587
19696
|
_log_finder_uin: "",
|
|
19588
|
-
_log_finder_id:
|
|
19697
|
+
_log_finder_id: "",
|
|
19589
19698
|
rawKeyBuff: null,
|
|
19590
19699
|
pluginSessionId: null,
|
|
19591
19700
|
scene: 7,
|
|
19592
|
-
reqScene: 7
|
|
19593
|
-
|
|
19594
|
-
|
|
19595
|
-
|
|
19596
|
-
|
|
19597
|
-
|
|
19598
|
-
|
|
19701
|
+
reqScene: 7
|
|
19702
|
+
},
|
|
19703
|
+
headers: {
|
|
19704
|
+
cookie: cookies,
|
|
19705
|
+
referer: "https://channels.weixin.qq.com",
|
|
19706
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
19707
|
+
},
|
|
19708
|
+
defaultErrorMsg: "获取用户信息失败"
|
|
19709
|
+
});
|
|
19710
|
+
}
|
|
19711
|
+
async function auth_getUploadAuthKey(cookies, finderUsername, http) {
|
|
19712
|
+
return http.api({
|
|
19713
|
+
method: "post",
|
|
19714
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/helper/helper_upload_params",
|
|
19715
|
+
data: {
|
|
19716
|
+
timestamp: auth_getTimeStamp(13),
|
|
19717
|
+
_log_finder_id: finderUsername,
|
|
19718
|
+
rawKeyBuff: null
|
|
19719
|
+
},
|
|
19720
|
+
headers: {
|
|
19721
|
+
cookie: cookies,
|
|
19722
|
+
referer: "https://channels.weixin.qq.com",
|
|
19723
|
+
Accept: "application/json, text/plain, */*",
|
|
19724
|
+
"Content-Type": "application/json",
|
|
19725
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
19726
|
+
},
|
|
19727
|
+
defaultErrorMsg: "获取上传认证密钥失败"
|
|
19728
|
+
});
|
|
19729
|
+
}
|
|
19730
|
+
class ShipinhaoAuthError extends Error {
|
|
19731
|
+
constructor(message, errCode){
|
|
19732
|
+
super(message), this.errCode = errCode;
|
|
19733
|
+
this.name = "ShipinhaoAuthError";
|
|
19734
|
+
}
|
|
19735
|
+
}
|
|
19736
|
+
async function getShipinhaoUploadAuth(cookies, http) {
|
|
19737
|
+
const userInfo = await auth_getUserInfo(cookies, http);
|
|
19738
|
+
if (0 !== userInfo.errCode || !userInfo.data?.finderUser) {
|
|
19739
|
+
const isLoginExpired = 300333 === userInfo.errCode || 300334 === userInfo.errCode;
|
|
19740
|
+
throw new ShipinhaoAuthError(isLoginExpired ? "登录失效" : userInfo.errMsg || "获取用户信息失败", userInfo.errCode || 500);
|
|
19741
|
+
}
|
|
19742
|
+
const finderUsername = userInfo.data.finderUser.finderUsername;
|
|
19743
|
+
const authKeyResponse = await auth_getUploadAuthKey(cookies, finderUsername, http);
|
|
19744
|
+
if (0 !== authKeyResponse.errCode || !authKeyResponse.data?.authKey) throw new ShipinhaoAuthError(`获取上传认证参数失败: ${authKeyResponse.errMsg}`, authKeyResponse.errCode || 500);
|
|
19745
|
+
const uin = authKeyResponse.data.uin;
|
|
19746
|
+
if (!uin) throw new ShipinhaoAuthError("获取用户 uin 失败", 500);
|
|
19747
|
+
const videoFileType = authKeyResponse.data.videoFileType || 20302;
|
|
19748
|
+
const pictureFileType = authKeyResponse.data.pictureFileType || 20304;
|
|
19749
|
+
return {
|
|
19750
|
+
uin,
|
|
19751
|
+
authKey: authKeyResponse.data.authKey,
|
|
19752
|
+
finderUsername,
|
|
19753
|
+
videoFileType,
|
|
19754
|
+
pictureFileType
|
|
19755
|
+
};
|
|
19756
|
+
}
|
|
19757
|
+
const MENTION_TEXT_SUFFIX = "\u0020";
|
|
19758
|
+
const MENTION_XML_SUFFIX = "\u2005";
|
|
19759
|
+
function payload_buildDescription(params) {
|
|
19760
|
+
let description = params.description || "";
|
|
19761
|
+
for (const topic of params.topics || [])description += `#${topic}`;
|
|
19762
|
+
for (const user of params.mentionedUsers || [])description += `@${user.nickname}${MENTION_TEXT_SUFFIX}`;
|
|
19763
|
+
return description;
|
|
19764
|
+
}
|
|
19765
|
+
function buildMentionedUser(mentionedUsers) {
|
|
19766
|
+
return (mentionedUsers || []).map((user)=>({
|
|
19767
|
+
nickname: `${user.nickname}${MENTION_TEXT_SUFFIX}`
|
|
19768
|
+
}));
|
|
19769
|
+
}
|
|
19770
|
+
function payload_buildTopicXml(params) {
|
|
19771
|
+
const values = [];
|
|
19772
|
+
let atIndex = null;
|
|
19773
|
+
if (params.description) values.push(`<![CDATA[${params.description}]]>`);
|
|
19774
|
+
for (const topic of params.topics || [])values.push(`<topic><![CDATA[#${topic}#]]></topic>`);
|
|
19775
|
+
for (const user of params.mentionedUsers || []){
|
|
19776
|
+
if (null === atIndex) atIndex = values.length;
|
|
19777
|
+
values.push(`<![CDATA[@${user.nickname}${MENTION_XML_SUFFIX}]]>`);
|
|
19778
|
+
}
|
|
19779
|
+
let xml = "<finder>";
|
|
19780
|
+
xml += "<version>1</version>";
|
|
19781
|
+
xml += `<valuecount>${values.length}</valuecount>`;
|
|
19782
|
+
xml += `<style><at>${atIndex ?? ""}</at></style>`;
|
|
19783
|
+
values.forEach((value, index)=>{
|
|
19784
|
+
xml += `<value${index}>${value}</value${index}>`;
|
|
19785
|
+
});
|
|
19786
|
+
xml += "</finder>";
|
|
19787
|
+
return xml;
|
|
19788
|
+
}
|
|
19789
|
+
function payload_buildLocation(location) {
|
|
19790
|
+
if (!location) return {
|
|
19791
|
+
latitude: 0,
|
|
19792
|
+
longitude: 0,
|
|
19793
|
+
city: "",
|
|
19794
|
+
poiName: "",
|
|
19795
|
+
address: "",
|
|
19796
|
+
poiClassifyId: ""
|
|
19797
|
+
};
|
|
19798
|
+
return {
|
|
19799
|
+
latitude: location.latitude,
|
|
19800
|
+
longitude: location.longitude,
|
|
19801
|
+
city: location.city,
|
|
19802
|
+
poiName: location.poiName || "",
|
|
19803
|
+
address: location.address || "",
|
|
19804
|
+
poiClassifyId: location.poiClassifyId || ""
|
|
19805
|
+
};
|
|
19806
|
+
}
|
|
19807
|
+
function buildTopic(params) {
|
|
19808
|
+
const topic = {
|
|
19809
|
+
finderTopicInfo: payload_buildTopicXml(params)
|
|
19810
|
+
};
|
|
19811
|
+
if (params.collection) {
|
|
19812
|
+
topic.collectionId = params.collection.collectionId;
|
|
19813
|
+
topic.collectionName = params.collection.collectionName;
|
|
19814
|
+
}
|
|
19815
|
+
return topic;
|
|
19816
|
+
}
|
|
19817
|
+
function buildEvent(event) {
|
|
19818
|
+
if (!event) return {};
|
|
19819
|
+
return {
|
|
19820
|
+
eventTopicId: event.eventTopicId,
|
|
19821
|
+
eventName: event.eventName,
|
|
19822
|
+
eventCreatorNickname: event.eventCreatorNickname || ""
|
|
19823
|
+
};
|
|
19824
|
+
}
|
|
19825
|
+
function buildExtReading(link) {
|
|
19826
|
+
if (!link) return {
|
|
19827
|
+
link: "",
|
|
19828
|
+
title: "",
|
|
19829
|
+
urlType: 1
|
|
19830
|
+
};
|
|
19831
|
+
return {
|
|
19832
|
+
link: link.link.replace(/[\s\u200b]/g, ""),
|
|
19833
|
+
title: link.title,
|
|
19834
|
+
urlType: link.urlType ?? 1
|
|
19835
|
+
};
|
|
19836
|
+
}
|
|
19837
|
+
function buildTagInfo(tagInfo, tagKey) {
|
|
19838
|
+
return {
|
|
19839
|
+
...tagInfo,
|
|
19840
|
+
tagKey
|
|
19841
|
+
};
|
|
19842
|
+
}
|
|
19843
|
+
const CHUNK_SIZE = 8388608;
|
|
19844
|
+
const UPLOAD_STAGE_TIMEOUT = 180000;
|
|
19845
|
+
const DEFAULT_TUNING = {
|
|
19846
|
+
metaTimeout: UPLOAD_STAGE_TIMEOUT,
|
|
19847
|
+
partTimeout: UPLOAD_STAGE_TIMEOUT,
|
|
19848
|
+
partRetries: 3,
|
|
19849
|
+
completeTimeout: UPLOAD_STAGE_TIMEOUT
|
|
19850
|
+
};
|
|
19851
|
+
async function uploader_uploadFile(opts) {
|
|
19852
|
+
const { filePath, fileType, uin, authKey, http, logger, tuning } = opts;
|
|
19853
|
+
const stat = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(filePath);
|
|
19854
|
+
const fileSize = stat.size;
|
|
19855
|
+
const fileName = filePath.split(/[\\/]/).pop() || "file";
|
|
19856
|
+
const metaTimeout = tuning?.metaTimeout ?? DEFAULT_TUNING.metaTimeout;
|
|
19857
|
+
const partTimeout = tuning?.partTimeout ?? DEFAULT_TUNING.partTimeout;
|
|
19858
|
+
const partRetries = tuning?.partRetries ?? DEFAULT_TUNING.partRetries;
|
|
19859
|
+
const completeTimeout = tuning?.completeTimeout ?? DEFAULT_TUNING.completeTimeout;
|
|
19860
|
+
logger?.info(`[shipinhaoPublishVideo] 开始上传: ${fileName} (${fileSize} B, filetype=${fileType})`);
|
|
19861
|
+
const fileMd5 = await computeFileMd5(filePath);
|
|
19862
|
+
const taskId = generateTaskId(fileName, fileSize, fileMd5);
|
|
19863
|
+
const baseUrl = "https://finderassistancea.video.qq.com";
|
|
19864
|
+
const headers = {
|
|
19865
|
+
Authorization: authKey
|
|
19866
|
+
};
|
|
19867
|
+
const xArgs = `apptype=251&filetype=${fileType}&weixinnum=${uin}&filekey=${encodeURIComponent(fileName)}&filesize=${fileSize}&taskid=${taskId}&scene=2`;
|
|
19868
|
+
const chunkCount = Math.ceil(fileSize / CHUNK_SIZE);
|
|
19869
|
+
const blockPartLength = [];
|
|
19870
|
+
for(let i = 0; i < chunkCount; i++)blockPartLength.push(Math.min((i + 1) * CHUNK_SIZE, fileSize));
|
|
19871
|
+
logger?.info(`[shipinhaoPublishVideo] 视频分片: ${chunkCount} 片`);
|
|
19872
|
+
const applyRes = await http.api({
|
|
19873
|
+
method: "PUT",
|
|
19874
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
19875
|
+
headers: {
|
|
19876
|
+
...headers,
|
|
19877
|
+
"X-Arguments": xArgs
|
|
19878
|
+
},
|
|
19879
|
+
data: {
|
|
19880
|
+
BlockSum: chunkCount,
|
|
19881
|
+
BlockPartLength: blockPartLength
|
|
19882
|
+
}
|
|
19883
|
+
}, {
|
|
19884
|
+
timeout: metaTimeout,
|
|
19885
|
+
retries: 2,
|
|
19886
|
+
retryDelay: 2000
|
|
19887
|
+
});
|
|
19888
|
+
if (!applyRes.UploadID && !applyRes.ListPartsResult) throw new Error("申请 UploadID 失败: " + JSON.stringify(applyRes));
|
|
19889
|
+
let uploadId = applyRes.UploadID;
|
|
19890
|
+
const uploadedParts = new Set();
|
|
19891
|
+
if (applyRes.ListPartsResult) {
|
|
19892
|
+
const parts = Array.isArray(applyRes.ListPartsResult.Part) ? applyRes.ListPartsResult.Part : applyRes.ListPartsResult.Part ? [
|
|
19893
|
+
applyRes.ListPartsResult.Part
|
|
19894
|
+
] : [];
|
|
19895
|
+
for (const p of parts)uploadedParts.add(p.PartNumber);
|
|
19896
|
+
const retryRes = await http.api({
|
|
19897
|
+
method: "PUT",
|
|
19898
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
19899
|
+
headers: {
|
|
19900
|
+
...headers,
|
|
19901
|
+
"X-Arguments": xArgs
|
|
19902
|
+
},
|
|
19903
|
+
data: {
|
|
19904
|
+
BlockSum: chunkCount,
|
|
19905
|
+
BlockPartLength: blockPartLength
|
|
19906
|
+
}
|
|
19907
|
+
}, {
|
|
19908
|
+
timeout: metaTimeout,
|
|
19909
|
+
retries: 2,
|
|
19910
|
+
retryDelay: 2000
|
|
19911
|
+
});
|
|
19912
|
+
uploadId = retryRes.UploadID;
|
|
19913
|
+
if (!uploadId) throw new Error("续传获取 UploadID 失败");
|
|
19914
|
+
}
|
|
19915
|
+
const partInfo = [];
|
|
19916
|
+
const fd = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].openSync(filePath, "r");
|
|
19917
|
+
try {
|
|
19918
|
+
for(let i = 0; i < chunkCount; i++){
|
|
19919
|
+
const partNumber = i + 1;
|
|
19920
|
+
if (uploadedParts.has(partNumber)) {
|
|
19921
|
+
const existing = applyRes.ListPartsResult.Part.find((p)=>p.PartNumber === partNumber);
|
|
19922
|
+
if (existing) {
|
|
19923
|
+
partInfo.push({
|
|
19924
|
+
PartNumber: partNumber,
|
|
19925
|
+
ETag: existing.ETag
|
|
19926
|
+
});
|
|
19927
|
+
continue;
|
|
19928
|
+
}
|
|
19929
|
+
}
|
|
19930
|
+
const start = i * CHUNK_SIZE;
|
|
19931
|
+
const end = Math.min(start + CHUNK_SIZE, fileSize);
|
|
19932
|
+
const chunkSize = end - start;
|
|
19933
|
+
const chunk = Buffer.alloc(chunkSize);
|
|
19934
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readSync(fd, chunk, 0, chunkSize, start);
|
|
19935
|
+
const chunkMd5 = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5").update(chunk).digest("hex");
|
|
19936
|
+
const partStart = Date.now();
|
|
19937
|
+
await http.api({
|
|
19938
|
+
method: "PUT",
|
|
19939
|
+
url: `${baseUrl}/uploadpartdfs?PartNumber=${partNumber}&UploadID=${encodeURIComponent(uploadId)}`,
|
|
19940
|
+
headers: {
|
|
19941
|
+
...headers,
|
|
19942
|
+
"X-Arguments": xArgs.replace(/scene=2/, "scene=0"),
|
|
19943
|
+
"Content-MD5": chunkMd5
|
|
19944
|
+
},
|
|
19945
|
+
data: chunk
|
|
19946
|
+
}, {
|
|
19947
|
+
timeout: partTimeout,
|
|
19948
|
+
retries: partRetries,
|
|
19949
|
+
retryDelay: 2000
|
|
19950
|
+
});
|
|
19951
|
+
Date.now();
|
|
19952
|
+
partInfo.push({
|
|
19953
|
+
PartNumber: partNumber,
|
|
19954
|
+
ETag: `"${chunkMd5}"`
|
|
19955
|
+
});
|
|
19956
|
+
}
|
|
19957
|
+
} finally{
|
|
19958
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].closeSync(fd);
|
|
19959
|
+
}
|
|
19960
|
+
const completeRes = await http.api({
|
|
19961
|
+
method: "POST",
|
|
19962
|
+
url: `${baseUrl}/completepartuploaddfs?UploadID=${encodeURIComponent(uploadId)}`,
|
|
19963
|
+
headers: {
|
|
19964
|
+
...headers,
|
|
19965
|
+
"X-Arguments": xArgs
|
|
19966
|
+
},
|
|
19967
|
+
data: {
|
|
19968
|
+
TransFlag: "0_0",
|
|
19969
|
+
PartInfo: partInfo
|
|
19970
|
+
}
|
|
19971
|
+
}, {
|
|
19972
|
+
timeout: completeTimeout,
|
|
19973
|
+
retries: 1,
|
|
19974
|
+
retryDelay: 3000
|
|
19975
|
+
});
|
|
19976
|
+
if (!completeRes.DownloadURL) throw new Error("合并分片失败: " + JSON.stringify(completeRes));
|
|
19977
|
+
logger?.info(`[shipinhaoPublishVideo] ${fileName} 上传成功`);
|
|
19978
|
+
return {
|
|
19979
|
+
downloadUrl: completeRes.DownloadURL,
|
|
19980
|
+
md5: fileMd5,
|
|
19981
|
+
fileSize
|
|
19982
|
+
};
|
|
19983
|
+
}
|
|
19984
|
+
async function computeFileMd5(filePath) {
|
|
19985
|
+
return new Promise((resolve, reject)=>{
|
|
19986
|
+
const hash = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5");
|
|
19987
|
+
const stream = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].createReadStream(filePath);
|
|
19988
|
+
stream.on("data", (chunk)=>hash.update(chunk));
|
|
19989
|
+
stream.on("end", ()=>resolve(hash.digest("hex")));
|
|
19990
|
+
stream.on("error", reject);
|
|
19991
|
+
});
|
|
19992
|
+
}
|
|
19993
|
+
function generateTaskId(fileName, fileSize, fileMd5) {
|
|
19994
|
+
const input = `${fileName}-${fileSize}-${fileMd5}`;
|
|
19995
|
+
return __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5").update(input).digest("hex").slice(0, 32);
|
|
19996
|
+
}
|
|
19997
|
+
const MAX_METADATA_BOX_SIZE = 268435456;
|
|
19998
|
+
function readBoxHeader(fd, offset, limit) {
|
|
19999
|
+
if (offset + 8 > limit) return null;
|
|
20000
|
+
const head = Buffer.alloc(16);
|
|
20001
|
+
const read = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readSync(fd, head, 0, 16, offset);
|
|
20002
|
+
if (read < 8) return null;
|
|
20003
|
+
let size = head.readUInt32BE(0);
|
|
20004
|
+
const type = head.toString("latin1", 4, 8);
|
|
20005
|
+
let headerSize = 8;
|
|
20006
|
+
if (1 === size) {
|
|
20007
|
+
if (read < 16) return null;
|
|
20008
|
+
size = head.readUInt32BE(8) * 2 ** 32 + head.readUInt32BE(12);
|
|
20009
|
+
headerSize = 16;
|
|
20010
|
+
} else if (0 === size) size = limit - offset;
|
|
20011
|
+
if (size < headerSize || offset + size > limit) return null;
|
|
20012
|
+
return {
|
|
20013
|
+
type,
|
|
20014
|
+
size,
|
|
20015
|
+
headerSize
|
|
20016
|
+
};
|
|
20017
|
+
}
|
|
20018
|
+
function parseVideoMeta(filePath) {
|
|
20019
|
+
let fd;
|
|
20020
|
+
let fileSize;
|
|
20021
|
+
try {
|
|
20022
|
+
fd = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].openSync(filePath, "r");
|
|
20023
|
+
} catch {
|
|
20024
|
+
return null;
|
|
20025
|
+
}
|
|
20026
|
+
try {
|
|
20027
|
+
fileSize = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].fstatSync(fd).size;
|
|
20028
|
+
const state = {
|
|
20029
|
+
movie: null,
|
|
20030
|
+
tracks: [],
|
|
20031
|
+
trexDefaults: new Map(),
|
|
20032
|
+
fragmentDurations: new Map(),
|
|
20033
|
+
trafTrackId: 0,
|
|
20034
|
+
trafDefaultSampleDuration: 0
|
|
20035
|
+
};
|
|
20036
|
+
let offset = 0;
|
|
20037
|
+
while(offset + 8 <= fileSize){
|
|
20038
|
+
const header = readBoxHeader(fd, offset, fileSize);
|
|
20039
|
+
if (!header) break;
|
|
20040
|
+
if ("moov" === header.type || "moof" === header.type) {
|
|
20041
|
+
const bodyLength = header.size - header.headerSize;
|
|
20042
|
+
if (bodyLength > 0 && bodyLength <= MAX_METADATA_BOX_SIZE) {
|
|
20043
|
+
const body = Buffer.alloc(bodyLength);
|
|
20044
|
+
const read = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readSync(fd, body, 0, bodyLength, offset + header.headerSize);
|
|
20045
|
+
state.trafTrackId = 0;
|
|
20046
|
+
state.trafDefaultSampleDuration = 0;
|
|
20047
|
+
walkBoxes(body.subarray(0, read), 0, read, state);
|
|
20048
|
+
}
|
|
20049
|
+
}
|
|
20050
|
+
offset += header.size;
|
|
20051
|
+
}
|
|
20052
|
+
const { movie, tracks } = state;
|
|
20053
|
+
const video = tracks.find((t)=>"vide" === t.handler) || tracks.find((t)=>t.width > 0 && t.height > 0);
|
|
20054
|
+
if (!video) return null;
|
|
20055
|
+
let { width, height } = video;
|
|
20056
|
+
if (90 === video.rotation || 270 === video.rotation) [width, height] = [
|
|
20057
|
+
height,
|
|
20058
|
+
width
|
|
20059
|
+
];
|
|
20060
|
+
return {
|
|
20061
|
+
width: Math.round(width),
|
|
20062
|
+
height: Math.round(height),
|
|
20063
|
+
duration: resolveDuration(movie, video, state.fragmentDurations),
|
|
20064
|
+
rotation: video.rotation,
|
|
20065
|
+
fileSize,
|
|
20066
|
+
codec: video.codec
|
|
20067
|
+
};
|
|
20068
|
+
} catch {
|
|
20069
|
+
return null;
|
|
20070
|
+
} finally{
|
|
20071
|
+
try {
|
|
20072
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].closeSync(fd);
|
|
20073
|
+
} catch {}
|
|
20074
|
+
}
|
|
20075
|
+
}
|
|
20076
|
+
function walkBoxes(buf, start, end, state) {
|
|
20077
|
+
let off = start;
|
|
20078
|
+
while(off + 8 <= end){
|
|
20079
|
+
let size = buf.readUInt32BE(off);
|
|
20080
|
+
const type = buf.toString("latin1", off + 4, off + 8);
|
|
20081
|
+
let headerSize = 8;
|
|
20082
|
+
if (1 === size) {
|
|
20083
|
+
if (off + 16 > end) break;
|
|
20084
|
+
const hi = buf.readUInt32BE(off + 8);
|
|
20085
|
+
const lo = buf.readUInt32BE(off + 12);
|
|
20086
|
+
size = hi * 2 ** 32 + lo;
|
|
20087
|
+
headerSize = 16;
|
|
20088
|
+
} else if (0 === size) size = end - off;
|
|
20089
|
+
if (size < headerSize || off + size > end) break;
|
|
20090
|
+
const bodyStart = off + headerSize;
|
|
20091
|
+
const bodyEnd = off + size;
|
|
20092
|
+
switch(type){
|
|
20093
|
+
case "trak":
|
|
20094
|
+
case "mdia":
|
|
20095
|
+
case "minf":
|
|
20096
|
+
case "stbl":
|
|
20097
|
+
case "mvex":
|
|
20098
|
+
case "traf":
|
|
20099
|
+
walkBoxes(buf, bodyStart, bodyEnd, state);
|
|
20100
|
+
break;
|
|
20101
|
+
case "mvhd":
|
|
20102
|
+
state.movie = parseMvhd(buf, bodyStart, bodyEnd);
|
|
20103
|
+
break;
|
|
20104
|
+
case "tkhd":
|
|
20105
|
+
state.tracks.push({
|
|
20106
|
+
...parseTkhd(buf, bodyStart, bodyEnd),
|
|
20107
|
+
handler: null,
|
|
20108
|
+
codec: null,
|
|
20109
|
+
timescale: 0,
|
|
20110
|
+
mdhdDuration: 0,
|
|
20111
|
+
sttsDuration: 0
|
|
20112
|
+
});
|
|
20113
|
+
break;
|
|
20114
|
+
case "mdhd":
|
|
20115
|
+
{
|
|
20116
|
+
const mdhd = parseMvhd(buf, bodyStart, bodyEnd);
|
|
20117
|
+
if (mdhd && state.tracks.length) {
|
|
20118
|
+
const track = state.tracks[state.tracks.length - 1];
|
|
20119
|
+
track.timescale = mdhd.timescale;
|
|
20120
|
+
track.mdhdDuration = mdhd.duration;
|
|
20121
|
+
}
|
|
20122
|
+
break;
|
|
20123
|
+
}
|
|
20124
|
+
case "hdlr":
|
|
20125
|
+
if (bodyEnd - bodyStart >= 12 && state.tracks.length) state.tracks[state.tracks.length - 1].handler = buf.toString("latin1", bodyStart + 8, bodyStart + 12);
|
|
20126
|
+
break;
|
|
20127
|
+
case "stsd":
|
|
20128
|
+
{
|
|
20129
|
+
const codec = parseStsdCodec(buf, bodyStart, bodyEnd);
|
|
20130
|
+
if (codec && state.tracks.length) state.tracks[state.tracks.length - 1].codec = codec;
|
|
20131
|
+
break;
|
|
20132
|
+
}
|
|
20133
|
+
case "stts":
|
|
20134
|
+
if (state.tracks.length) state.tracks[state.tracks.length - 1].sttsDuration = parseSttsDuration(buf, bodyStart, bodyEnd);
|
|
20135
|
+
break;
|
|
20136
|
+
case "trex":
|
|
20137
|
+
if (bodyStart + 20 > bodyEnd) break;
|
|
20138
|
+
state.trexDefaults.set(buf.readUInt32BE(bodyStart + 4), buf.readUInt32BE(bodyStart + 12));
|
|
20139
|
+
break;
|
|
20140
|
+
case "tfhd":
|
|
20141
|
+
{
|
|
20142
|
+
const tfhd = parseTfhd(buf, bodyStart, bodyEnd);
|
|
20143
|
+
state.trafTrackId = tfhd.trackId;
|
|
20144
|
+
state.trafDefaultSampleDuration = tfhd.defaultSampleDuration || state.trexDefaults.get(tfhd.trackId) || 0;
|
|
20145
|
+
break;
|
|
20146
|
+
}
|
|
20147
|
+
case "trun":
|
|
20148
|
+
{
|
|
20149
|
+
const duration = parseTrunDuration(buf, bodyStart, bodyEnd, state.trafDefaultSampleDuration);
|
|
20150
|
+
state.fragmentDurations.set(state.trafTrackId, (state.fragmentDurations.get(state.trafTrackId) || 0) + duration);
|
|
20151
|
+
break;
|
|
20152
|
+
}
|
|
20153
|
+
}
|
|
20154
|
+
off += size;
|
|
20155
|
+
}
|
|
20156
|
+
}
|
|
20157
|
+
const UNKNOWN_DURATION_32 = 0xffffffff;
|
|
20158
|
+
function isUsableDuration(duration) {
|
|
20159
|
+
return duration > 0 && duration !== UNKNOWN_DURATION_32;
|
|
20160
|
+
}
|
|
20161
|
+
function resolveDuration(movie, video, fragmentDurations) {
|
|
20162
|
+
if (movie && movie.timescale && isUsableDuration(movie.duration)) return movie.duration / movie.timescale;
|
|
20163
|
+
if (video.timescale) {
|
|
20164
|
+
if (isUsableDuration(video.mdhdDuration)) return video.mdhdDuration / video.timescale;
|
|
20165
|
+
if (video.sttsDuration > 0) return video.sttsDuration / video.timescale;
|
|
20166
|
+
const fragment = fragmentDurations.get(video.trackId) ?? (1 === fragmentDurations.size ? [
|
|
20167
|
+
...fragmentDurations.values()
|
|
20168
|
+
][0] : 0);
|
|
20169
|
+
if (fragment > 0) return fragment / video.timescale;
|
|
20170
|
+
}
|
|
20171
|
+
return 0;
|
|
20172
|
+
}
|
|
20173
|
+
function parseSttsDuration(buf, start, end) {
|
|
20174
|
+
if (start + 8 > end) return 0;
|
|
20175
|
+
const entryCount = buf.readUInt32BE(start + 4);
|
|
20176
|
+
let total = 0;
|
|
20177
|
+
for(let i = 0; i < entryCount; i++){
|
|
20178
|
+
const off = start + 8 + 8 * i;
|
|
20179
|
+
if (off + 8 > end) break;
|
|
20180
|
+
total += buf.readUInt32BE(off) * buf.readUInt32BE(off + 4);
|
|
20181
|
+
}
|
|
20182
|
+
return total;
|
|
20183
|
+
}
|
|
20184
|
+
function parseTfhd(buf, start, end) {
|
|
20185
|
+
if (start + 8 > end) return {
|
|
20186
|
+
trackId: 0,
|
|
20187
|
+
defaultSampleDuration: 0
|
|
20188
|
+
};
|
|
20189
|
+
const flags = buf.readUIntBE(start + 1, 3);
|
|
20190
|
+
const trackId = buf.readUInt32BE(start + 4);
|
|
20191
|
+
let off = start + 8;
|
|
20192
|
+
if (0x000001 & flags) off += 8;
|
|
20193
|
+
if (0x000002 & flags) off += 4;
|
|
20194
|
+
if (0x000008 & flags && off + 4 <= end) return {
|
|
20195
|
+
trackId,
|
|
20196
|
+
defaultSampleDuration: buf.readUInt32BE(off)
|
|
20197
|
+
};
|
|
20198
|
+
return {
|
|
20199
|
+
trackId,
|
|
20200
|
+
defaultSampleDuration: 0
|
|
20201
|
+
};
|
|
20202
|
+
}
|
|
20203
|
+
function parseTrunDuration(buf, start, end, defaultSampleDuration) {
|
|
20204
|
+
if (start + 8 > end) return 0;
|
|
20205
|
+
const flags = buf.readUIntBE(start + 1, 3);
|
|
20206
|
+
const sampleCount = buf.readUInt32BE(start + 4);
|
|
20207
|
+
let off = start + 8;
|
|
20208
|
+
if (0x000001 & flags) off += 4;
|
|
20209
|
+
if (0x000004 & flags) off += 4;
|
|
20210
|
+
const hasDuration = (0x000100 & flags) !== 0;
|
|
20211
|
+
if (!hasDuration) return sampleCount * defaultSampleDuration;
|
|
20212
|
+
const entrySize = 4 + ((0x000200 & flags) !== 0 ? 4 : 0) + ((0x000400 & flags) !== 0 ? 4 : 0) + ((0x000800 & flags) !== 0 ? 4 : 0);
|
|
20213
|
+
let total = 0;
|
|
20214
|
+
for(let i = 0; i < sampleCount; i++){
|
|
20215
|
+
const entryOff = off + i * entrySize;
|
|
20216
|
+
if (entryOff + 4 > end) break;
|
|
20217
|
+
total += buf.readUInt32BE(entryOff);
|
|
20218
|
+
}
|
|
20219
|
+
return total;
|
|
20220
|
+
}
|
|
20221
|
+
function parseStsdCodec(buf, start, end) {
|
|
20222
|
+
if (start + 16 > end) return null;
|
|
20223
|
+
if (0 === buf.readUInt32BE(start + 4)) return null;
|
|
20224
|
+
return buf.toString("latin1", start + 12, start + 16).toLowerCase();
|
|
20225
|
+
}
|
|
20226
|
+
function parseMvhd(buf, start, end) {
|
|
20227
|
+
const version = buf.readUInt8(start);
|
|
20228
|
+
if (1 === version) {
|
|
20229
|
+
if (start + 28 > end) return null;
|
|
20230
|
+
const timescale = buf.readUInt32BE(start + 20);
|
|
20231
|
+
const hi = buf.readUInt32BE(start + 24);
|
|
20232
|
+
const lo = buf.readUInt32BE(start + 28);
|
|
20233
|
+
return {
|
|
20234
|
+
timescale,
|
|
20235
|
+
duration: hi * 2 ** 32 + lo
|
|
20236
|
+
};
|
|
20237
|
+
}
|
|
20238
|
+
if (start + 20 > end) return null;
|
|
20239
|
+
return {
|
|
20240
|
+
timescale: buf.readUInt32BE(start + 12),
|
|
20241
|
+
duration: buf.readUInt32BE(start + 16)
|
|
20242
|
+
};
|
|
20243
|
+
}
|
|
20244
|
+
function parseTkhd(buf, start, end) {
|
|
20245
|
+
const version = buf.readUInt8(start);
|
|
20246
|
+
const afterDuration = 1 === version ? 36 : 24;
|
|
20247
|
+
const matrixOff = start + afterDuration + 16;
|
|
20248
|
+
const whOff = matrixOff + 36;
|
|
20249
|
+
const trackIdOff = start + (1 === version ? 20 : 12);
|
|
20250
|
+
const trackId = trackIdOff + 4 <= end ? buf.readUInt32BE(trackIdOff) : 0;
|
|
20251
|
+
if (whOff + 8 > end) return {
|
|
20252
|
+
trackId,
|
|
20253
|
+
width: 0,
|
|
20254
|
+
height: 0,
|
|
20255
|
+
rotation: 0
|
|
20256
|
+
};
|
|
20257
|
+
const width = buf.readUInt32BE(whOff) / 65536;
|
|
20258
|
+
const height = buf.readUInt32BE(whOff + 4) / 65536;
|
|
20259
|
+
const a = buf.readInt32BE(matrixOff) / 65536;
|
|
20260
|
+
const b = buf.readInt32BE(matrixOff + 4) / 65536;
|
|
20261
|
+
let rotation = 0;
|
|
20262
|
+
if (Math.abs(a) < 0.01 && Math.abs(b - 1) < 0.01) rotation = 90;
|
|
20263
|
+
else if (Math.abs(a + 1) < 0.01 && Math.abs(b) < 0.01) rotation = 180;
|
|
20264
|
+
else if (Math.abs(a) < 0.01 && Math.abs(b + 1) < 0.01) rotation = 270;
|
|
20265
|
+
return {
|
|
20266
|
+
trackId,
|
|
20267
|
+
width,
|
|
20268
|
+
height,
|
|
20269
|
+
rotation
|
|
20270
|
+
};
|
|
20271
|
+
}
|
|
20272
|
+
function parseVideoCodec(filePath) {
|
|
20273
|
+
return parseVideoMeta(filePath)?.codec ?? null;
|
|
20274
|
+
}
|
|
20275
|
+
function buildVideoMetaFromParams(filePath, metadata) {
|
|
20276
|
+
return {
|
|
20277
|
+
width: Math.round(metadata.width),
|
|
20278
|
+
height: Math.round(metadata.height),
|
|
20279
|
+
duration: metadata.duration,
|
|
20280
|
+
rotation: 0,
|
|
20281
|
+
fileSize: metadata.fileSize,
|
|
20282
|
+
codec: parseVideoCodec(filePath)
|
|
20283
|
+
};
|
|
20284
|
+
}
|
|
20285
|
+
const MAX_DURATION_SECONDS = 28800;
|
|
20286
|
+
const MAX_FILE_SIZE = 21474836480;
|
|
20287
|
+
const ALLOWED_EXTENSIONS = [
|
|
20288
|
+
".mp4"
|
|
20289
|
+
];
|
|
20290
|
+
const ALLOWED_CODECS = [
|
|
20291
|
+
"avc1",
|
|
20292
|
+
"avc3"
|
|
20293
|
+
];
|
|
20294
|
+
const MIN_TITLE_LENGTH = 6;
|
|
20295
|
+
const MAX_TITLE_LENGTH = 16;
|
|
20296
|
+
function formatFileSize(bytes) {
|
|
20297
|
+
if (bytes < 1048576) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
20298
|
+
if (bytes < 1073741824) return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
20299
|
+
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
20300
|
+
}
|
|
20301
|
+
function formatDuration(seconds) {
|
|
20302
|
+
const total = Math.round(seconds);
|
|
20303
|
+
const h = Math.floor(total / 3600);
|
|
20304
|
+
const m = Math.floor(total % 3600 / 60);
|
|
20305
|
+
const s = total % 60;
|
|
20306
|
+
if (h > 0) return `${h}小时${m}分${s}秒`;
|
|
20307
|
+
if (m > 0) return `${m}分${s}秒`;
|
|
20308
|
+
return `${s}秒`;
|
|
20309
|
+
}
|
|
20310
|
+
function validateShipinhaoVideo(filePath, meta) {
|
|
20311
|
+
const fileName = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(filePath);
|
|
20312
|
+
const ext = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(fileName).toLowerCase();
|
|
20313
|
+
if (!ALLOWED_EXTENSIONS.includes(ext)) return `视频格式不支持:${fileName}。视频号仅支持 MP4/H.264 格式,请转换后重试。`;
|
|
20314
|
+
if (meta.duration > MAX_DURATION_SECONDS) return `视频时长超过限制:${fileName}(${formatDuration(meta.duration)})。视频号视频时长不能超过 8 小时,请剪辑后重试。`;
|
|
20315
|
+
if (meta.fileSize > MAX_FILE_SIZE) return `视频大小超过限制:${fileName}(${formatFileSize(meta.fileSize)})。视频号视频不能超过 20GB,请压缩后重试。`;
|
|
20316
|
+
if (meta.codec && !ALLOWED_CODECS.includes(meta.codec)) return `视频编码不支持:${fileName}(${meta.codec})。视频号仅支持 H.264 编码,请转码后重试。`;
|
|
20317
|
+
return null;
|
|
20318
|
+
}
|
|
20319
|
+
function validateShipinhaoTitle(title) {
|
|
20320
|
+
if (void 0 === title) return null;
|
|
20321
|
+
const trimmed = title.trim();
|
|
20322
|
+
if ("" === trimmed) return null;
|
|
20323
|
+
const length = [
|
|
20324
|
+
...trimmed
|
|
20325
|
+
].length;
|
|
20326
|
+
if (length < MIN_TITLE_LENGTH || length > MAX_TITLE_LENGTH) return `视频号标题需要在 ${MIN_TITLE_LENGTH}-${MAX_TITLE_LENGTH} 个字符之间,当前 ${length} 个字符,请调整后重试。`;
|
|
20327
|
+
return null;
|
|
20328
|
+
}
|
|
20329
|
+
const POST_CREATE_PAGE_URL = "https://channels.weixin.qq.com/micro/content/post/create";
|
|
20330
|
+
const MICRO_CONTENT_BASE = "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin";
|
|
20331
|
+
function resolveClientContext(params, fallbackUin) {
|
|
20332
|
+
const extra = params.extraParam || {};
|
|
20333
|
+
const deviceIdCookie = params.cookies.find((c)=>"device_id" === c.name || "finger_print_device_id" === c.name)?.value;
|
|
20334
|
+
return {
|
|
20335
|
+
aId: "string" == typeof extra.aId ? extra.aId : "",
|
|
20336
|
+
fingerPrintDeviceId: "string" == typeof extra.fingerPrintDeviceId ? extra.fingerPrintDeviceId : deviceIdCookie || "",
|
|
20337
|
+
uin: "string" == typeof extra.uin ? extra.uin : String(fallbackUin)
|
|
20338
|
+
};
|
|
20339
|
+
}
|
|
20340
|
+
function buildPublishHeaders(cookieString, client) {
|
|
20341
|
+
const headers = {
|
|
20342
|
+
cookie: cookieString,
|
|
20343
|
+
referer: POST_CREATE_PAGE_URL,
|
|
20344
|
+
origin: "https://channels.weixin.qq.com",
|
|
20345
|
+
"content-type": "application/json"
|
|
20346
|
+
};
|
|
20347
|
+
if (client.fingerPrintDeviceId) headers["finger-print-device-id"] = client.fingerPrintDeviceId;
|
|
20348
|
+
if (client.uin) headers["x-wechat-uin"] = client.uin;
|
|
20349
|
+
return headers;
|
|
20350
|
+
}
|
|
20351
|
+
function buildPublishQuery(client) {
|
|
20352
|
+
const query = {
|
|
20353
|
+
_rid: rid(),
|
|
20354
|
+
_pageUrl: POST_CREATE_PAGE_URL
|
|
20355
|
+
};
|
|
20356
|
+
if (client.aId) query._aid = client.aId;
|
|
20357
|
+
return query;
|
|
20358
|
+
}
|
|
20359
|
+
function buildCommonBody(finderUsername) {
|
|
20360
|
+
return {
|
|
20361
|
+
timestamp: String(Date.now()),
|
|
20362
|
+
_log_finder_uin: "",
|
|
20363
|
+
_log_finder_id: finderUsername,
|
|
20364
|
+
rawKeyBuff: "",
|
|
20365
|
+
pluginSessionId: null,
|
|
20366
|
+
scene: 7,
|
|
20367
|
+
reqScene: 7
|
|
20368
|
+
};
|
|
20369
|
+
}
|
|
20370
|
+
async function getTraceKey(auth, client, http, logger) {
|
|
20371
|
+
const res = await http.api({
|
|
20372
|
+
method: "POST",
|
|
20373
|
+
url: `${MICRO_CONTENT_BASE}/post/get-finder-post-trace-key`,
|
|
20374
|
+
params: buildPublishQuery(client),
|
|
20375
|
+
data: {
|
|
20376
|
+
objectId: "",
|
|
20377
|
+
...buildCommonBody(auth.finderUsername)
|
|
20378
|
+
},
|
|
20379
|
+
defaultErrorMsg: "获取 traceKey 失败"
|
|
20380
|
+
});
|
|
20381
|
+
if (0 !== res.errCode || !res.data?.traceKey) {
|
|
20382
|
+
logger.error("[getTraceKey] 获取失败:", JSON.stringify(res));
|
|
20383
|
+
throw new Error(`获取 traceKey 失败: ${JSON.stringify(res)}`);
|
|
20384
|
+
}
|
|
20385
|
+
return res.data.traceKey;
|
|
20386
|
+
}
|
|
20387
|
+
async function getObjectTagKey(auth, client, http, logger) {
|
|
20388
|
+
try {
|
|
20389
|
+
const res = await http.api({
|
|
20390
|
+
method: "POST",
|
|
20391
|
+
url: `${MICRO_CONTENT_BASE}/post/finder_get_object_tag_list`,
|
|
20392
|
+
params: buildPublishQuery(client),
|
|
20393
|
+
data: {
|
|
20394
|
+
source: 1,
|
|
20395
|
+
...buildCommonBody(auth.finderUsername)
|
|
20396
|
+
},
|
|
20397
|
+
defaultErrorMsg: "获取内容声明标注失败"
|
|
20398
|
+
});
|
|
20399
|
+
if (0 !== res.errCode || !res.data?.tagKey) {
|
|
20400
|
+
logger.warn(`[getObjectTagKey] 未取到 tagKey: ${JSON.stringify(res)}`);
|
|
20401
|
+
return null;
|
|
20402
|
+
}
|
|
20403
|
+
return res.data.tagKey;
|
|
20404
|
+
} catch (error) {
|
|
20405
|
+
logger.warn(`[getObjectTagKey] 获取 tagKey 异常: ${stringifyError(error)}`);
|
|
20406
|
+
return null;
|
|
20407
|
+
}
|
|
20408
|
+
}
|
|
20409
|
+
async function submitAndPollTranscode(opts) {
|
|
20410
|
+
const { videoUrl, videoMeta, traceKey, uploadStartTime, uploadEndTime, finderUsername, client, http, logger } = opts;
|
|
20411
|
+
const finderUrl = videoUrl.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${videoUrl.split("qq.com")[1]}` : videoUrl;
|
|
20412
|
+
logger.info(`[submitAndPollTranscode] 视频尺寸: ${videoMeta.width}x${videoMeta.height}, 时长: ${videoMeta.duration}s`);
|
|
20413
|
+
const submitRes = await http.api({
|
|
20414
|
+
method: "POST",
|
|
20415
|
+
url: `${MICRO_CONTENT_BASE}/post/post_clip_video`,
|
|
20416
|
+
params: buildPublishQuery(client),
|
|
20417
|
+
data: {
|
|
20418
|
+
url: finderUrl,
|
|
20419
|
+
timeStart: 0,
|
|
20420
|
+
cropDuration: 0,
|
|
20421
|
+
height: videoMeta.height,
|
|
20422
|
+
width: videoMeta.width,
|
|
20423
|
+
x: 0,
|
|
20424
|
+
y: 0,
|
|
20425
|
+
clipOriginVideoInfo: {
|
|
20426
|
+
width: videoMeta.width,
|
|
20427
|
+
height: videoMeta.height,
|
|
20428
|
+
duration: videoMeta.duration,
|
|
20429
|
+
fileSize: videoMeta.fileSize
|
|
20430
|
+
},
|
|
20431
|
+
traceInfo: {
|
|
20432
|
+
traceKey,
|
|
20433
|
+
uploadCdnStart: uploadStartTime,
|
|
20434
|
+
uploadCdnEnd: uploadEndTime
|
|
20435
|
+
},
|
|
20436
|
+
targetWidth: videoMeta.width,
|
|
20437
|
+
targetHeight: videoMeta.height,
|
|
20438
|
+
type: 4,
|
|
20439
|
+
useAstraThumbCover: 1,
|
|
20440
|
+
...buildCommonBody(finderUsername)
|
|
20441
|
+
},
|
|
20442
|
+
defaultErrorMsg: "提交转码失败"
|
|
20443
|
+
});
|
|
20444
|
+
if (0 !== submitRes.errCode || !submitRes.data?.clipKey) {
|
|
20445
|
+
logger.error("[submitAndPollTranscode] 提交转码失败:", JSON.stringify(submitRes));
|
|
20446
|
+
throw new Error(`提交转码失败: ${JSON.stringify(submitRes)}`);
|
|
20447
|
+
}
|
|
20448
|
+
const { clipKey, draftId } = submitRes.data;
|
|
20449
|
+
const pollInterval = 5000;
|
|
20450
|
+
const pollBudget = Math.min(1800000, 300000 + 1000 * Math.ceil(1.5 * videoMeta.duration));
|
|
20451
|
+
const maxPolls = Math.ceil(pollBudget / pollInterval);
|
|
20452
|
+
let pollCount = 0;
|
|
20453
|
+
while(pollCount < maxPolls){
|
|
20454
|
+
await sleep(pollInterval);
|
|
20455
|
+
pollCount++;
|
|
20456
|
+
const pollRes = await http.api({
|
|
20457
|
+
method: "POST",
|
|
20458
|
+
url: `${MICRO_CONTENT_BASE}/post/post_clip_video_result`,
|
|
20459
|
+
params: buildPublishQuery(client),
|
|
20460
|
+
data: {
|
|
20461
|
+
clipKey,
|
|
20462
|
+
draftId,
|
|
20463
|
+
...buildCommonBody(finderUsername)
|
|
20464
|
+
},
|
|
20465
|
+
defaultErrorMsg: "转码轮询失败"
|
|
20466
|
+
}, {
|
|
20467
|
+
timeout: 60000,
|
|
20468
|
+
retries: 2,
|
|
20469
|
+
retryDelay: 3000
|
|
20470
|
+
});
|
|
20471
|
+
if (0 !== pollRes.errCode) {
|
|
20472
|
+
logger.error(`[submitAndPollTranscode] 转码轮询失败 (poll ${pollCount}):`, JSON.stringify(pollRes));
|
|
20473
|
+
throw new Error(`转码轮询失败 (poll ${pollCount}): ${JSON.stringify(pollRes)}`);
|
|
20474
|
+
}
|
|
20475
|
+
const { flag, url, width, height, duration, md5, fileSize } = pollRes.data || {};
|
|
20476
|
+
if (1 === flag) {
|
|
20477
|
+
if (!url || !width || !height || !duration || !md5 || !fileSize) {
|
|
20478
|
+
logger.error("[submitAndPollTranscode] 转码完成但返回数据不完整:", JSON.stringify(pollRes.data));
|
|
20479
|
+
throw new Error(`转码完成但返回数据不完整: ${JSON.stringify(pollRes.data)}`);
|
|
20480
|
+
}
|
|
20481
|
+
logger.info(`[submitAndPollTranscode] 转码完成! 用时: ${pollCount * pollInterval / 1000}s`);
|
|
20482
|
+
return {
|
|
20483
|
+
clipKey,
|
|
20484
|
+
url,
|
|
20485
|
+
width,
|
|
20486
|
+
height,
|
|
20487
|
+
duration,
|
|
20488
|
+
md5,
|
|
20489
|
+
fileSize
|
|
20490
|
+
};
|
|
20491
|
+
}
|
|
20492
|
+
if (2 === flag) ;
|
|
20493
|
+
else {
|
|
20494
|
+
logger.error(`[submitAndPollTranscode] 转码失败,未知 flag=${flag}:`, JSON.stringify(pollRes.data));
|
|
20495
|
+
throw new Error(`转码失败,未知 flag=${flag}: ${JSON.stringify(pollRes.data)}`);
|
|
20496
|
+
}
|
|
20497
|
+
}
|
|
20498
|
+
logger.error(`[submitAndPollTranscode] 转码超时,已轮询 ${maxPolls} 次,用时: ${maxPolls * pollInterval / 1000}s`);
|
|
20499
|
+
throw new Error(`转码超时 (${maxPolls * pollInterval / 1000}s)`);
|
|
20500
|
+
}
|
|
20501
|
+
async function publishVideo(opts) {
|
|
20502
|
+
const { params, auth, client, clipResult, videoUpload, coverUpload, verticalCoverUpload, videoMeta, traceKey, tagKey, uploadStartTime, uploadEndTime, proxyHttp, logger } = opts;
|
|
20503
|
+
const toFinderUrl = (url)=>url.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${url.split("qq.com")[1]}` : url;
|
|
20504
|
+
const thumbFinderUrl = toFinderUrl(coverUpload.downloadUrl);
|
|
20505
|
+
const coverFinderUrl = toFinderUrl(verticalCoverUpload.downloadUrl);
|
|
20506
|
+
const md5sumUuid = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].randomUUID();
|
|
20507
|
+
const description = params.description;
|
|
20508
|
+
const objectDesc = {
|
|
20509
|
+
mpTitle: "",
|
|
20510
|
+
description,
|
|
20511
|
+
extReading: buildExtReading(params.link),
|
|
20512
|
+
mediaType: 4,
|
|
20513
|
+
location: payload_buildLocation(params.location),
|
|
20514
|
+
topic: buildTopic({
|
|
20515
|
+
description: params.description,
|
|
20516
|
+
topics: params.topics,
|
|
20517
|
+
mentionedUsers: params.mentionedUsers,
|
|
20518
|
+
collection: params.collection
|
|
20519
|
+
}),
|
|
20520
|
+
event: buildEvent(params.event),
|
|
20521
|
+
mentionedUser: buildMentionedUser(params.mentionedUsers),
|
|
20522
|
+
media: [
|
|
20523
|
+
{
|
|
20524
|
+
url: clipResult.url,
|
|
20525
|
+
fileSize: clipResult.fileSize,
|
|
20526
|
+
thumbUrl: thumbFinderUrl,
|
|
20527
|
+
fullThumbUrl: thumbFinderUrl,
|
|
20528
|
+
coverUrl: coverFinderUrl,
|
|
20529
|
+
fullCoverUrl: coverFinderUrl,
|
|
20530
|
+
shareCoverUrl: coverFinderUrl,
|
|
20531
|
+
mediaType: 4,
|
|
20532
|
+
videoPlayLen: Math.round(clipResult.duration),
|
|
20533
|
+
width: clipResult.width,
|
|
20534
|
+
height: clipResult.height,
|
|
20535
|
+
md5sum: md5sumUuid,
|
|
20536
|
+
cardShowStyle: 2,
|
|
20537
|
+
urlCdnTaskId: clipResult.clipKey
|
|
20538
|
+
}
|
|
20539
|
+
],
|
|
20540
|
+
shortTitle: params.title ? [
|
|
20541
|
+
{
|
|
20542
|
+
shortTitle: params.title
|
|
20543
|
+
}
|
|
20544
|
+
] : [],
|
|
20545
|
+
member: {}
|
|
20546
|
+
};
|
|
20547
|
+
const publishData = {
|
|
20548
|
+
objectType: 0,
|
|
20549
|
+
longitude: 0,
|
|
20550
|
+
latitude: 0,
|
|
20551
|
+
feedLongitude: 0,
|
|
20552
|
+
feedLatitude: 0,
|
|
20553
|
+
originalFlag: params.originalFlag ?? 0,
|
|
20554
|
+
topics: params.topics || [],
|
|
20555
|
+
isFullPost: 1,
|
|
20556
|
+
handleFlag: 2,
|
|
20557
|
+
videoClipTaskId: clipResult.clipKey,
|
|
20558
|
+
traceInfo: {
|
|
20559
|
+
traceKey,
|
|
20560
|
+
uploadCdnStart: uploadStartTime,
|
|
20561
|
+
uploadCdnEnd: uploadEndTime
|
|
20562
|
+
},
|
|
20563
|
+
objectDesc,
|
|
20564
|
+
report: {
|
|
20565
|
+
clipKey: clipResult.clipKey,
|
|
20566
|
+
draftId: clipResult.clipKey,
|
|
20567
|
+
...buildCommonBody(auth.finderUsername),
|
|
20568
|
+
height: videoMeta.height,
|
|
20569
|
+
width: videoMeta.width,
|
|
20570
|
+
duration: videoMeta.duration,
|
|
20571
|
+
fileSize: videoUpload.fileSize,
|
|
20572
|
+
uploadCost: (uploadEndTime - uploadStartTime) * 1000
|
|
20573
|
+
},
|
|
20574
|
+
postFlag: 0,
|
|
20575
|
+
mode: 1,
|
|
20576
|
+
clientid: __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].randomUUID(),
|
|
20577
|
+
...buildCommonBody(auth.finderUsername)
|
|
20578
|
+
};
|
|
20579
|
+
if (params.scheduledTime) publishData.effectiveTime = params.scheduledTime;
|
|
20580
|
+
if (params.tagInfo && tagKey) publishData.tagInfo = buildTagInfo(params.tagInfo, tagKey);
|
|
20581
|
+
const publishRes = await proxyHttp.api({
|
|
20582
|
+
method: "POST",
|
|
20583
|
+
url: `${MICRO_CONTENT_BASE}/post/post_create`,
|
|
20584
|
+
params: buildPublishQuery(client),
|
|
20585
|
+
data: publishData,
|
|
20586
|
+
defaultErrorMsg: "发布视频失败"
|
|
20587
|
+
});
|
|
20588
|
+
logger.info(`[publishVideo] 发布结果: errCode=${publishRes.errCode}, baseResp.errcode=${publishRes.data?.baseResp?.errcode}`);
|
|
20589
|
+
return publishRes;
|
|
20590
|
+
}
|
|
20591
|
+
function sleep(ms) {
|
|
20592
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
20593
|
+
}
|
|
20594
|
+
async function resolveLocalCoverPath(coverPath, label, tmpCachePath, logger) {
|
|
20595
|
+
if (!/^https?:\/\//i.test(coverPath)) return coverPath;
|
|
20596
|
+
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(coverPath);
|
|
20597
|
+
const savePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, `${Date.now()}-${label}-${fileName}`);
|
|
20598
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(coverPath, savePath);
|
|
20599
|
+
return savePath;
|
|
20600
|
+
}
|
|
20601
|
+
const shipinhaoPublishVideo_mock_mockAction = async (task, params)=>{
|
|
20602
|
+
const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
|
|
20603
|
+
let currentStep = "初始化";
|
|
20604
|
+
try {
|
|
20605
|
+
currentStep = "解析认证信息";
|
|
20606
|
+
const cookieString = params.cookies.map((c)=>`${c.name}=${c.value}`).join("; ");
|
|
20607
|
+
const http = new Http({
|
|
20608
|
+
headers: {
|
|
20609
|
+
cookie: cookieString
|
|
20610
|
+
}
|
|
20611
|
+
});
|
|
20612
|
+
currentStep = "验证发布参数";
|
|
20613
|
+
if (!params.videoPath) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "视频文件路径不能为空", "");
|
|
20614
|
+
if (!params.coverPath) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "横屏封面图片路径不能为空", "");
|
|
20615
|
+
currentStep = "获取上传认证";
|
|
20616
|
+
const auth = await getShipinhaoUploadAuth(cookieString, http);
|
|
20617
|
+
const client = resolveClientContext(params, auth.uin);
|
|
20618
|
+
const publishHeaders = buildPublishHeaders(cookieString, client);
|
|
20619
|
+
const microHttp = new Http({
|
|
20620
|
+
headers: publishHeaders
|
|
20621
|
+
});
|
|
20622
|
+
const args = [
|
|
20623
|
+
{
|
|
20624
|
+
headers: publishHeaders
|
|
20625
|
+
},
|
|
20626
|
+
task.logger,
|
|
20627
|
+
params.proxyLoc,
|
|
20628
|
+
params.accountId,
|
|
20629
|
+
"shipinhao"
|
|
20630
|
+
];
|
|
20631
|
+
const proxyHttp = new Http(...args);
|
|
20632
|
+
currentStep = "组装视频元数据";
|
|
20633
|
+
const videoMeta = buildVideoMetaFromParams(params.videoPath, params.videoMetadata);
|
|
20634
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
20635
|
+
currentStep = "校验视频限制";
|
|
20636
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
20637
|
+
if (validationError) {
|
|
20638
|
+
await updateTaskState?.({
|
|
20639
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20640
|
+
error: validationError
|
|
20641
|
+
});
|
|
20642
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, validationError, "");
|
|
20643
|
+
}
|
|
20644
|
+
currentStep = "校验标题";
|
|
20645
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
20646
|
+
if (titleError) {
|
|
20647
|
+
await updateTaskState?.({
|
|
20648
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20649
|
+
error: titleError
|
|
20650
|
+
});
|
|
20651
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, titleError, "");
|
|
20652
|
+
}
|
|
20653
|
+
currentStep = "获取 traceKey";
|
|
20654
|
+
const traceKey = await getTraceKey(auth, client, microHttp, task.logger);
|
|
20655
|
+
let tagKey = null;
|
|
20656
|
+
if (params.tagInfo) {
|
|
20657
|
+
currentStep = "获取内容声明 tagKey";
|
|
20658
|
+
tagKey = await getObjectTagKey(auth, client, microHttp, task.logger);
|
|
20659
|
+
}
|
|
20660
|
+
const uploadStartTime = Math.floor(Date.now() / 1000);
|
|
20661
|
+
currentStep = "上传视频";
|
|
20662
|
+
const videoUpload = await uploader_uploadFile({
|
|
20663
|
+
filePath: params.videoPath,
|
|
20664
|
+
fileType: auth.videoFileType,
|
|
20665
|
+
uin: auth.uin,
|
|
20666
|
+
authKey: auth.authKey,
|
|
20667
|
+
http,
|
|
20668
|
+
logger: task.logger
|
|
20669
|
+
});
|
|
20670
|
+
const uploadEndTime = Math.floor(Date.now() / 1000);
|
|
20671
|
+
task.logger.info(`[shipinhaoPublishVideo] 耗时: ${uploadEndTime - uploadStartTime}s`);
|
|
20672
|
+
currentStep = "上传横屏封面";
|
|
20673
|
+
const localCoverPath = await resolveLocalCoverPath(params.coverPath, "横屏封面", task.getTmpPath(), task.logger);
|
|
20674
|
+
const coverUpload = await uploader_uploadFile({
|
|
20675
|
+
filePath: localCoverPath,
|
|
20676
|
+
fileType: auth.pictureFileType,
|
|
20677
|
+
uin: auth.uin,
|
|
20678
|
+
authKey: auth.authKey,
|
|
20679
|
+
http,
|
|
20680
|
+
logger: task.logger
|
|
20681
|
+
});
|
|
20682
|
+
let verticalCoverUpload = coverUpload;
|
|
20683
|
+
if (params.verticalCoverPath) {
|
|
20684
|
+
currentStep = "上传竖屏封面";
|
|
20685
|
+
const localVerticalPath = await resolveLocalCoverPath(params.verticalCoverPath, "竖屏封面", task.getTmpPath(), task.logger);
|
|
20686
|
+
verticalCoverUpload = await uploader_uploadFile({
|
|
20687
|
+
filePath: localVerticalPath,
|
|
20688
|
+
fileType: auth.pictureFileType,
|
|
20689
|
+
uin: auth.uin,
|
|
20690
|
+
authKey: auth.authKey,
|
|
20691
|
+
http,
|
|
20692
|
+
logger: task.logger
|
|
20693
|
+
});
|
|
20694
|
+
}
|
|
20695
|
+
currentStep = "提交转码";
|
|
20696
|
+
const clipResult = await submitAndPollTranscode({
|
|
20697
|
+
videoUrl: videoUpload.downloadUrl,
|
|
20698
|
+
videoMeta,
|
|
20699
|
+
traceKey,
|
|
20700
|
+
uploadStartTime,
|
|
20701
|
+
uploadEndTime,
|
|
20702
|
+
finderUsername: auth.finderUsername,
|
|
20703
|
+
client,
|
|
20704
|
+
http: microHttp,
|
|
20705
|
+
logger: task.logger
|
|
20706
|
+
});
|
|
20707
|
+
currentStep = "发布视频";
|
|
20708
|
+
let publishResult;
|
|
20709
|
+
try {
|
|
20710
|
+
publishResult = await publishVideo({
|
|
20711
|
+
params,
|
|
20712
|
+
auth,
|
|
20713
|
+
client,
|
|
20714
|
+
clipResult,
|
|
20715
|
+
videoUpload,
|
|
20716
|
+
coverUpload,
|
|
20717
|
+
verticalCoverUpload,
|
|
20718
|
+
videoMeta,
|
|
20719
|
+
traceKey,
|
|
20720
|
+
tagKey,
|
|
20721
|
+
uploadStartTime,
|
|
20722
|
+
uploadEndTime,
|
|
20723
|
+
proxyHttp,
|
|
20724
|
+
logger: task.logger
|
|
20725
|
+
});
|
|
20726
|
+
} catch (error) {
|
|
20727
|
+
const handledError = Http.handleApiError(error);
|
|
20728
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布请求失败: ${handledError.message}`, stringifyError(handledError));
|
|
20729
|
+
const classified = classifyPublishError(handledError);
|
|
20730
|
+
if (classified) {
|
|
20731
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
20732
|
+
await updateTaskState?.({
|
|
20733
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20734
|
+
error: message
|
|
20735
|
+
});
|
|
20736
|
+
return {
|
|
20737
|
+
code: 414,
|
|
20738
|
+
data: "",
|
|
20739
|
+
message
|
|
20740
|
+
};
|
|
20741
|
+
}
|
|
20742
|
+
throw error;
|
|
20743
|
+
}
|
|
20744
|
+
task.logger.info(`[shipinhaoPublishVideo] publishResult: ${JSON.stringify(publishResult)}`);
|
|
20745
|
+
const resultCode = publishResult.data?.baseResp?.errcode ?? publishResult.errCode;
|
|
20746
|
+
const resultMsg = publishResult.data?.baseResp?.errmsg ?? (0 === resultCode ? "发布成功" : `发布失败(errCode=${resultCode})`);
|
|
20747
|
+
if (0 === resultCode) {
|
|
20748
|
+
const publishId = extractEncFileKey(coverUpload.downloadUrl);
|
|
20749
|
+
if (!publishId) task.logger.error(`[shipinhaoPublishVideo] 封面 DownloadURL 中未解析到 encfilekey,关联 id 为空: ${coverUpload.downloadUrl}`);
|
|
20750
|
+
await updateTaskState?.({
|
|
20751
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.SUCCESS,
|
|
20752
|
+
result: {
|
|
20753
|
+
response: resultMsg
|
|
20754
|
+
}
|
|
20755
|
+
});
|
|
20756
|
+
reportLogger({
|
|
20757
|
+
token: params.huiwenToken || "",
|
|
20758
|
+
enverionment: task.enverionment || "development",
|
|
20759
|
+
postId: params.articleId,
|
|
20760
|
+
eip: proxyHttp.proxyInfo,
|
|
20761
|
+
accountId: params.accountId,
|
|
20762
|
+
uid: params.uid,
|
|
20763
|
+
publishParams: {
|
|
20764
|
+
videoPath: params.videoPath,
|
|
20765
|
+
coverPath: params.coverPath,
|
|
20766
|
+
verticalCoverPath: params.verticalCoverPath,
|
|
20767
|
+
title: params.title,
|
|
20768
|
+
topics: params.topics,
|
|
20769
|
+
mentionedUsers: params.mentionedUsers,
|
|
20770
|
+
collection: params.collection,
|
|
20771
|
+
event: params.event,
|
|
20772
|
+
link: params.link,
|
|
20773
|
+
tagInfo: params.tagInfo,
|
|
20774
|
+
originalFlag: params.originalFlag,
|
|
20775
|
+
scheduledTime: params.scheduledTime
|
|
20776
|
+
},
|
|
20777
|
+
platform: "shipinhao"
|
|
20778
|
+
});
|
|
20779
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(0, "发布成功", publishId);
|
|
20780
|
+
}
|
|
20781
|
+
let errorMessage = resultMsg;
|
|
20782
|
+
if (-11224 === resultCode) errorMessage = "视频号管理员完成实名且绑定手机号后才可以发表";
|
|
20783
|
+
else if (300333 === resultCode || 300334 === resultCode) errorMessage = "登录失效";
|
|
20784
|
+
else if (300330 === resultCode) errorMessage = "未登录";
|
|
20785
|
+
else if (300002 === resultCode) errorMessage = "官方平台在校验音乐/位置/定时信息时失败了,请重新编辑后发布";
|
|
20786
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布失败: ${errorMessage} (errCode=${resultCode})`);
|
|
20787
|
+
await updateTaskState?.({
|
|
20788
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20789
|
+
error: errorMessage
|
|
20790
|
+
});
|
|
20791
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, errorMessage, "");
|
|
20792
|
+
} catch (error) {
|
|
20793
|
+
const handledError = Http.handleApiError(error);
|
|
20794
|
+
const errorMsg = handledError.message || "发布失败,请稍后重试";
|
|
20795
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布流程异常 [${currentStep}]: ${errorMsg}`, stringifyError(error), handledError.extra);
|
|
20796
|
+
await updateTaskState?.({
|
|
20797
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20798
|
+
error: errorMsg
|
|
20799
|
+
});
|
|
20800
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, errorMsg, "");
|
|
20801
|
+
}
|
|
20802
|
+
};
|
|
20803
|
+
const shipinhaoPublishVideo_rpa_rpaAction = async (task, params)=>{
|
|
20804
|
+
task.logger.info("开始微信视频号视频发布(RPA 模式)");
|
|
20805
|
+
const videoMeta = buildVideoMetaFromParams(params.videoPath, params.videoMetadata);
|
|
20806
|
+
task.logger.info(`视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
20807
|
+
if (!videoMeta.codec) task.logger.warn("未能读取视频编码格式,跳过 H.264 预检,交由服务端判断");
|
|
20808
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
20809
|
+
if (validationError) {
|
|
20810
|
+
task.logger.error(`视频校验未通过: ${validationError}`);
|
|
20811
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, validationError, "");
|
|
20812
|
+
}
|
|
20813
|
+
task.logger.info("视频校验通过");
|
|
20814
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
20815
|
+
if (titleError) {
|
|
20816
|
+
task.logger.error(`标题校验未通过: ${titleError}`);
|
|
20817
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, titleError, "");
|
|
20818
|
+
}
|
|
20819
|
+
const unsupported = [
|
|
20820
|
+
params.verticalCoverPath && "verticalCoverPath",
|
|
20821
|
+
params.collection && "collection",
|
|
20822
|
+
params.originalFlag && "originalFlag",
|
|
20823
|
+
params.postWithMemberZoneLink && "postWithMemberZoneLink"
|
|
20824
|
+
].filter(Boolean);
|
|
20825
|
+
if (unsupported.length) task.logger.warn(`RPA 模式不支持以下参数,将被忽略: ${unsupported.join("、")};如需生效请使用 mockApi 模式`);
|
|
20826
|
+
if (params.tagInfo && 5 === params.tagInfo.tagType) {
|
|
20827
|
+
const shootInfo = params.tagInfo.shootInfo;
|
|
20828
|
+
if (shootInfo && (shootInfo.provinceCode || shootInfo.cityCode)) task.logger.warn("tagInfo.tagType=5 在 RPA 模式下仅支持拍摄时间和国家选择,省市选择需要使用 mockApi 模式");
|
|
20829
|
+
}
|
|
20830
|
+
const tmpCachePath = task.getTmpPath();
|
|
20831
|
+
const page = await task.createPage({
|
|
20832
|
+
url: "https://channels.weixin.qq.com/platform/post/create",
|
|
20833
|
+
show: task.debug,
|
|
20834
|
+
cookies: params.cookies
|
|
20835
|
+
});
|
|
20836
|
+
try {
|
|
20837
|
+
const waitForElement = async (selector, timeout = 10000)=>{
|
|
20838
|
+
try {
|
|
20839
|
+
const element = page.locator(selector);
|
|
20840
|
+
await element.waitFor({
|
|
20841
|
+
state: "visible",
|
|
20842
|
+
timeout
|
|
20843
|
+
});
|
|
20844
|
+
return element;
|
|
20845
|
+
} catch {
|
|
20846
|
+
task.logger.warn(`元素未找到: ${selector}`);
|
|
20847
|
+
return null;
|
|
20848
|
+
}
|
|
20849
|
+
};
|
|
20850
|
+
const retryAction = async (action, maxRetries = 3, delay = 1000)=>{
|
|
20851
|
+
let lastError;
|
|
20852
|
+
for(let i = 0; i < maxRetries; i++)try {
|
|
20853
|
+
return await action();
|
|
20854
|
+
} catch (error) {
|
|
20855
|
+
lastError = error;
|
|
20856
|
+
task.logger.warn(`重试 ${i + 1}/${maxRetries}: ${lastError.message}`);
|
|
20857
|
+
if (i < maxRetries - 1) await page.waitForTimeout(delay);
|
|
20858
|
+
}
|
|
20859
|
+
throw lastError;
|
|
20860
|
+
};
|
|
20861
|
+
task.logger.info("等待页面加载...");
|
|
20862
|
+
task.logger.info("检查登录状态...");
|
|
20863
|
+
if (task.debug) {
|
|
20864
|
+
task.logger.info(`当前页面 URL: ${page.url()}`);
|
|
20865
|
+
const title = await page.title();
|
|
20866
|
+
task.logger.info(`页面标题: ${title}`);
|
|
20867
|
+
}
|
|
20868
|
+
try {
|
|
20869
|
+
await page.waitForSelector(".post-edit-wrap", {
|
|
20870
|
+
state: "visible",
|
|
20871
|
+
timeout: 30000
|
|
20872
|
+
});
|
|
20873
|
+
task.logger.info("✓ 登录状态正常,找到编辑器容器");
|
|
20874
|
+
} catch {
|
|
20875
|
+
task.logger.error("✗ 未找到编辑器,可能登录失效");
|
|
20876
|
+
return {
|
|
20877
|
+
code: 414,
|
|
20878
|
+
message: "登录失效或页面加载异常",
|
|
20879
|
+
data: page.url()
|
|
20880
|
+
};
|
|
20881
|
+
}
|
|
20882
|
+
task.logger.info("页面加载完成,开始填充内容");
|
|
20883
|
+
task.logger.info("开始上传视频");
|
|
20884
|
+
await retryAction(async ()=>{
|
|
20885
|
+
const videoUploadSelectors = [
|
|
20886
|
+
'.ant-upload-btn input[type="file"][accept*="video"]',
|
|
20887
|
+
'.upload input[type="file"][accept*="video"]',
|
|
20888
|
+
'input[type="file"][accept*="video"]'
|
|
20889
|
+
];
|
|
20890
|
+
let uploadInput = null;
|
|
20891
|
+
if (task.debug) {
|
|
20892
|
+
const allFileInputs = await page.locator('input[type="file"]').count();
|
|
20893
|
+
task.logger.info(`页面中共找到 ${allFileInputs} 个文件上传输入框`);
|
|
20894
|
+
}
|
|
20895
|
+
for (const selector of videoUploadSelectors){
|
|
20896
|
+
const input = page.locator(selector);
|
|
20897
|
+
const count = await input.count();
|
|
20898
|
+
if (count > 0) {
|
|
20899
|
+
uploadInput = input.first();
|
|
20900
|
+
task.logger.info(`找到视频上传输入框: ${selector}`);
|
|
20901
|
+
break;
|
|
20902
|
+
}
|
|
20903
|
+
}
|
|
20904
|
+
if (!uploadInput) {
|
|
20905
|
+
task.logger.warn("未找到视频上传输入框,等待 3 秒后重试...");
|
|
20906
|
+
await page.waitForTimeout(3000);
|
|
20907
|
+
const anyFileInput = page.locator('input[type="file"]');
|
|
20908
|
+
const inputCount = await anyFileInput.count();
|
|
20909
|
+
if (inputCount > 0) {
|
|
20910
|
+
uploadInput = anyFileInput.first();
|
|
20911
|
+
task.logger.info(`找到文件输入框(共 ${inputCount} 个)`);
|
|
20912
|
+
} else {
|
|
20913
|
+
if (task.debug) {
|
|
20914
|
+
const screenshotPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, `upload-error-${Date.now()}.png`);
|
|
20915
|
+
await page.screenshot({
|
|
20916
|
+
path: screenshotPath,
|
|
20917
|
+
fullPage: true
|
|
20918
|
+
});
|
|
20919
|
+
task.logger.error(`未找到上传输入框,已截图保存至: ${screenshotPath}`);
|
|
20920
|
+
}
|
|
20921
|
+
throw new Error("未找到视频上传输入框");
|
|
20922
|
+
}
|
|
20923
|
+
}
|
|
20924
|
+
await uploadInput.setInputFiles(params.videoPath);
|
|
20925
|
+
task.logger.info("视频上传成功");
|
|
20926
|
+
await page.waitForTimeout(5000);
|
|
20927
|
+
});
|
|
20928
|
+
if (params.coverPath) {
|
|
20929
|
+
task.logger.info("开始上传封面");
|
|
20930
|
+
await retryAction(async ()=>{
|
|
20931
|
+
const coverUploadBtn = await waitForElement(".cover-upload-btn", 10000);
|
|
20932
|
+
if (coverUploadBtn) {
|
|
20933
|
+
const coverInput = page.locator('.cover-upload-btn input[type="file"]');
|
|
20934
|
+
await coverInput.setInputFiles(params.coverPath);
|
|
20935
|
+
task.logger.info("封面上传成功");
|
|
20936
|
+
await page.waitForTimeout(2000);
|
|
20937
|
+
}
|
|
20938
|
+
});
|
|
20939
|
+
}
|
|
20940
|
+
const descriptionText = payload_buildDescription({
|
|
20941
|
+
description: params.description,
|
|
20942
|
+
topics: params.topics,
|
|
20943
|
+
mentionedUsers: params.mentionedUsers
|
|
20944
|
+
});
|
|
20945
|
+
if (descriptionText) {
|
|
20946
|
+
task.logger.info("填写视频描述");
|
|
20947
|
+
await retryAction(async ()=>{
|
|
20948
|
+
const descEditor = await waitForElement(".input-editor", 10000);
|
|
20949
|
+
if (!descEditor) throw new Error("未找到描述编辑器");
|
|
20950
|
+
await descEditor.click();
|
|
20951
|
+
await page.waitForTimeout(500);
|
|
20952
|
+
await descEditor.evaluate((el)=>{
|
|
20953
|
+
el.textContent = "";
|
|
20954
|
+
});
|
|
20955
|
+
await page.waitForTimeout(300);
|
|
20956
|
+
task.logger.info("已清空编辑器内容");
|
|
20957
|
+
await descEditor.pressSequentially(descriptionText, {
|
|
20958
|
+
delay: 10
|
|
20959
|
+
});
|
|
20960
|
+
await page.waitForTimeout(500);
|
|
20961
|
+
task.logger.info("描述填写完成");
|
|
20962
|
+
});
|
|
20963
|
+
}
|
|
20964
|
+
if (params.title) {
|
|
20965
|
+
task.logger.info(`填写标题: ${params.title}`);
|
|
20966
|
+
const title = params.title;
|
|
20967
|
+
await retryAction(async ()=>{
|
|
20968
|
+
const titleInput = await waitForElement("#container-wrap div.form-item-body.short-title-wrap input", 10000);
|
|
20969
|
+
if (!titleInput) throw new Error("未找到标题输入框");
|
|
20970
|
+
await titleInput.click();
|
|
20971
|
+
await titleInput.clear({
|
|
20972
|
+
timeout: 3000
|
|
20973
|
+
});
|
|
20974
|
+
await titleInput.fill(title, {
|
|
20975
|
+
timeout: 5000
|
|
20976
|
+
});
|
|
20977
|
+
task.logger.info("标题填写完成");
|
|
20978
|
+
});
|
|
20979
|
+
}
|
|
20980
|
+
if (params.location) {
|
|
20981
|
+
task.logger.info(`选择地点: ${params.location.city}`);
|
|
20982
|
+
const instance = page.locator(".position-display-wrap");
|
|
20983
|
+
await instance.click();
|
|
20984
|
+
await page.waitForTimeout(1000);
|
|
20985
|
+
await page.locator(".location-filter-wrap input").fill(params.location.city);
|
|
20986
|
+
await page.waitForTimeout(2000);
|
|
20987
|
+
const poperInstance = page.locator(".location-filter-wrap .common-option-list-wrap .option-item");
|
|
20988
|
+
await poperInstance.nth(1).waitFor();
|
|
20989
|
+
await poperInstance.nth(1).click();
|
|
20990
|
+
task.logger.info("地点选择完成");
|
|
20991
|
+
}
|
|
20992
|
+
if (params.collection) {
|
|
20993
|
+
task.logger.info(`选择合集: ${params.collection.collectionName}`);
|
|
20994
|
+
const instanceCollection = page.locator(".post-album-display-wrap");
|
|
20995
|
+
await instanceCollection.click();
|
|
20996
|
+
await page.waitForTimeout(1000);
|
|
20997
|
+
page.locator(".post-album-wrap .option-item").filter({
|
|
20998
|
+
hasText: params.collection.collectionName
|
|
20999
|
+
}).first().click({
|
|
21000
|
+
force: true
|
|
21001
|
+
});
|
|
21002
|
+
}
|
|
21003
|
+
if (params.link) {
|
|
21004
|
+
task.logger.info(`设置扩展阅读链接: ${params.link.title}`);
|
|
21005
|
+
await page.locator(".post-link-wrap .link-display-wrap").click();
|
|
21006
|
+
await page.waitForTimeout(300);
|
|
21007
|
+
const linkTypeText = 2 === params.link.urlType ? "红包封面" : "公众号文章";
|
|
21008
|
+
await page.locator(".link-option-item .title-wrap span").filter({
|
|
21009
|
+
hasText: linkTypeText
|
|
21010
|
+
}).click();
|
|
21011
|
+
await page.waitForTimeout(300);
|
|
21012
|
+
const placeholder = 2 === params.link.urlType ? "粘贴红包封面链接" : "粘贴公众号文章链接";
|
|
21013
|
+
await page.locator(`.link-input-wrap input[placeholder="${placeholder}"]`).fill(params.link.link);
|
|
21014
|
+
await page.waitForTimeout(500);
|
|
21015
|
+
task.logger.info(`已设置${linkTypeText}: ${params.link.link}`);
|
|
21016
|
+
}
|
|
21017
|
+
if (params.event) {
|
|
21018
|
+
task.logger.info(`选择活动: ${params.event.eventName}`);
|
|
21019
|
+
await page.locator(".post-activity-wrap .activity-display").click();
|
|
21020
|
+
await page.waitForTimeout(500);
|
|
21021
|
+
await page.locator(".activity-filter-wrap .weui-desktop-form__input[placeholder='搜索活动']").fill(params.event.eventName);
|
|
21022
|
+
await page.waitForTimeout(500);
|
|
21023
|
+
const searchLoading = page.locator(".search-loading");
|
|
21024
|
+
await searchLoading.waitFor({
|
|
21025
|
+
state: "hidden",
|
|
21026
|
+
timeout: 5000
|
|
21027
|
+
}).catch(()=>{
|
|
21028
|
+
task.logger.warn("活动搜索加载超时,继续尝试选择");
|
|
21029
|
+
});
|
|
21030
|
+
const activityItem = page.locator(".option-item .activity-item .activity-item-info .name").filter({
|
|
21031
|
+
hasText: params.event.eventName
|
|
21032
|
+
});
|
|
21033
|
+
const count = await activityItem.count();
|
|
21034
|
+
if (count > 0) {
|
|
21035
|
+
await activityItem.first().click();
|
|
21036
|
+
await page.waitForTimeout(300);
|
|
21037
|
+
task.logger.info(`已选择活动: ${params.event.eventName}`);
|
|
21038
|
+
} else {
|
|
21039
|
+
task.logger.warn(`未找到活动: ${params.event.eventName},将不参与活动`);
|
|
21040
|
+
await page.locator(".post-activity-wrap .activity-display").click();
|
|
21041
|
+
await page.waitForTimeout(300);
|
|
21042
|
+
}
|
|
21043
|
+
}
|
|
21044
|
+
if (params.scheduledTime) {
|
|
21045
|
+
task.logger.info("设置定时发布");
|
|
21046
|
+
const timingRadio = page.locator(".weui-desktop-form__check-label").filter({
|
|
21047
|
+
hasNotText: "不定时"
|
|
21048
|
+
}).first();
|
|
21049
|
+
await timingRadio.click();
|
|
21050
|
+
await page.waitForTimeout(500);
|
|
21051
|
+
const instance = page.locator(".weui-desktop-picker__date");
|
|
21052
|
+
await instance.click();
|
|
21053
|
+
const dateD = utils_TimeFormatter.format(1000 * params.scheduledTime, "d");
|
|
21054
|
+
const nowMonth = utils_TimeFormatter.format(Date.now(), "MM月");
|
|
21055
|
+
const nowMonthText = utils_TimeFormatter.format(Date.now(), "M月");
|
|
21056
|
+
const month = utils_TimeFormatter.format(1000 * params.scheduledTime, "MM月");
|
|
21057
|
+
const monthLocator = await page.locator("weui-desktop-picker__panel__label").filter({
|
|
21058
|
+
hasText: month
|
|
21059
|
+
}).first();
|
|
21060
|
+
if (!monthLocator) {
|
|
21061
|
+
await page.locator(".weui-desktop-picker__panel__label").filter({
|
|
21062
|
+
hasText: nowMonth
|
|
21063
|
+
}).first().click();
|
|
21064
|
+
await page.waitForTimeout(500);
|
|
21065
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
21066
|
+
hasText: nowMonthText
|
|
21067
|
+
}).first().click();
|
|
21068
|
+
}
|
|
21069
|
+
await page.waitForTimeout(500);
|
|
21070
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
21071
|
+
hasText: dateD
|
|
21072
|
+
}).first().click();
|
|
21073
|
+
await page.locator(".weui-desktop-form__input-wrp input[placeholder*='请选择时间']").fill(utils_TimeFormatter.format(1000 * params.scheduledTime, "hh:mm"));
|
|
21074
|
+
await page.locator("i.weui-desktop-icon__time").click();
|
|
21075
|
+
await page.locator(".post-time-wrap .form-item .label").filter({
|
|
21076
|
+
hasText: "发表时间"
|
|
21077
|
+
}).click();
|
|
21078
|
+
}
|
|
21079
|
+
if (params.tagInfo) {
|
|
21080
|
+
task.logger.info(`设置视频标注: tagType=${params.tagInfo.tagType}`);
|
|
21081
|
+
await page.locator(".mark-tag-select").click();
|
|
21082
|
+
await page.waitForTimeout(300);
|
|
21083
|
+
const tagTypeTextMap = {
|
|
21084
|
+
0: "无需标注",
|
|
21085
|
+
1: "含AI生成内容",
|
|
21086
|
+
2: "内容包含营销广告",
|
|
21087
|
+
3: "内容为虚构剧情,仅供娱乐",
|
|
21088
|
+
5: "内容为自行拍摄",
|
|
21089
|
+
7: "内容为转载",
|
|
21090
|
+
8: "个人观点,仅供参考"
|
|
21091
|
+
};
|
|
21092
|
+
const tagText = tagTypeTextMap[params.tagInfo.tagType];
|
|
21093
|
+
if (tagText) {
|
|
21094
|
+
await page.locator(".mark-tag-option .option-main").filter({
|
|
21095
|
+
hasText: tagText
|
|
21096
|
+
}).click();
|
|
21097
|
+
await page.waitForTimeout(300);
|
|
21098
|
+
if (5 === params.tagInfo.tagType) {
|
|
21099
|
+
const shootInfo = params.tagInfo.shootInfo;
|
|
21100
|
+
if (shootInfo) {
|
|
21101
|
+
task.logger.info("填写拍摄时间和地点...");
|
|
21102
|
+
await page.waitForTimeout(500);
|
|
21103
|
+
if (shootInfo.postTimestamp) {
|
|
21104
|
+
task.logger.info(`设置拍摄时间: ${shootInfo.postTimestamp}`);
|
|
21105
|
+
const timestamp = 1000 * parseInt(shootInfo.postTimestamp, 10);
|
|
21106
|
+
const date = new Date(timestamp);
|
|
21107
|
+
await page.locator(".original-dialog-content .weui-desktop-picker__date input[placeholder*='请选择拍摄时间']").click();
|
|
21108
|
+
await page.waitForTimeout(300);
|
|
21109
|
+
const dayNum = date.getDate();
|
|
21110
|
+
await page.locator(".weui-desktop-picker__table a").filter({
|
|
21111
|
+
hasText: new RegExp(`^\\s*${dayNum}\\s*$`)
|
|
21112
|
+
}).first().click();
|
|
21113
|
+
await page.waitForTimeout(300);
|
|
21114
|
+
}
|
|
21115
|
+
if (shootInfo.countryCode || shootInfo.provinceCode || shootInfo.cityCode) {
|
|
21116
|
+
task.logger.info("设置拍摄地点...");
|
|
21117
|
+
await page.locator(".original-dialog-content .weui-desktop-form__dropdowncascade .weui-desktop-form__dropdowncascade__dt").click();
|
|
21118
|
+
await page.waitForTimeout(300);
|
|
21119
|
+
if (1156 === shootInfo.countryCode) {
|
|
21120
|
+
await page.locator(".weui-desktop-dropdown__list-ele .weui-desktop-dropdown__list-ele__text").filter({
|
|
21121
|
+
hasText: "中国"
|
|
21122
|
+
}).click();
|
|
21123
|
+
await page.waitForTimeout(300);
|
|
21124
|
+
task.logger.warn("RPA 模式下暂不支持选择具体省份和城市,仅选择了国家");
|
|
21125
|
+
} else task.logger.warn(`不支持的国家代码: ${shootInfo.countryCode},跳过地点设置`);
|
|
21126
|
+
}
|
|
21127
|
+
const confirmBtn = await waitForElement(".weui-desktop-dialog .weui-desktop-btn_primary");
|
|
21128
|
+
if (confirmBtn) {
|
|
21129
|
+
await confirmBtn.click();
|
|
21130
|
+
await page.waitForTimeout(300);
|
|
21131
|
+
}
|
|
21132
|
+
} else task.logger.warn("tagType=5 需要提供 shootInfo 字段(拍摄时间和地点)");
|
|
21133
|
+
}
|
|
21134
|
+
if (7 === params.tagInfo.tagType) {
|
|
21135
|
+
const repostSource = params.tagInfo.repostSource;
|
|
21136
|
+
if (repostSource) {
|
|
21137
|
+
task.logger.info(`填写转载来源: ${repostSource}`);
|
|
21138
|
+
await page.waitForTimeout(500);
|
|
21139
|
+
await page.locator(".repost-dialog-content .repost-textarea").fill(repostSource);
|
|
21140
|
+
await page.waitForTimeout(300);
|
|
21141
|
+
const confirmBtn = await waitForElement(".weui-desktop-dialog .weui-desktop-btn_primary");
|
|
21142
|
+
if (confirmBtn) {
|
|
21143
|
+
await confirmBtn.click();
|
|
21144
|
+
await page.waitForTimeout(300);
|
|
21145
|
+
}
|
|
21146
|
+
} else task.logger.warn("tagType=7 需要提供 repostSource 字段(转载来源)");
|
|
21147
|
+
}
|
|
21148
|
+
} else task.logger.warn(`未知的 tagType: ${params.tagInfo.tagType},跳过标注设置`);
|
|
21149
|
+
}
|
|
21150
|
+
task.logger.info("准备发布...");
|
|
21151
|
+
await page.waitForTimeout(500);
|
|
21152
|
+
let videoId = "";
|
|
21153
|
+
const handleResponse = async (response)=>{
|
|
21154
|
+
const url = response.url();
|
|
21155
|
+
if (url.includes("/post/post_create")) {
|
|
21156
|
+
const jsonResponse = await response.json();
|
|
21157
|
+
page.off("response", handleResponse);
|
|
21158
|
+
videoId = jsonResponse.object?.id || jsonResponse.data?.objectId || "";
|
|
21159
|
+
}
|
|
21160
|
+
};
|
|
21161
|
+
page.on("response", handleResponse);
|
|
21162
|
+
task._timerRecord.PrePublish = Date.now();
|
|
21163
|
+
const MEDIA_OPR_SELECTOR = "#container-wrap > div.container-center > div > div > div.main-body-wrap.post-create > div.main-body > div > div.post-edit-wrap.material-edit-wrap > div.material > div.preview > div > div.media-opr > div > span > div > div > div";
|
|
21164
|
+
task.logger.info("等待视频上传完成(预览区媒体操作栏出现)...");
|
|
21165
|
+
const uploadTimeout = 600000;
|
|
21166
|
+
const uploadWaitStart = Date.now();
|
|
21167
|
+
let lastProgressLog = 0;
|
|
21168
|
+
while(true){
|
|
21169
|
+
const ready = await page.evaluate((selector)=>{
|
|
21170
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
21171
|
+
const root = host?.shadowRoot;
|
|
21172
|
+
if (!root) return false;
|
|
21173
|
+
return !!root.querySelector(selector);
|
|
21174
|
+
}, MEDIA_OPR_SELECTOR);
|
|
21175
|
+
if (ready) break;
|
|
21176
|
+
const elapsed = Date.now() - uploadWaitStart;
|
|
21177
|
+
if (elapsed > uploadTimeout) throw new Error(`视频上传超时,预览区未就绪(已等待 ${Math.round(elapsed / 1000)}s)`);
|
|
21178
|
+
if (elapsed - lastProgressLog >= 15000) {
|
|
21179
|
+
lastProgressLog = elapsed;
|
|
21180
|
+
task.logger.info(`视频仍在上传中... 已等待 ${Math.round(elapsed / 1000)}s`);
|
|
21181
|
+
}
|
|
21182
|
+
await page.waitForTimeout(1000);
|
|
21183
|
+
}
|
|
21184
|
+
task.logger.info(`视频上传完成(等待 ${Math.round((Date.now() - uploadWaitStart) / 1000)}s)`);
|
|
21185
|
+
const clicked = await page.evaluate(()=>{
|
|
21186
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
21187
|
+
const root = host?.shadowRoot;
|
|
21188
|
+
if (!root) return "未找到 wujie-app shadowRoot";
|
|
21189
|
+
const btns = Array.from(root.querySelectorAll(".form-btns .weui-desktop-btn"));
|
|
21190
|
+
const target = btns.find((el)=>(el.textContent || "").includes("发表"));
|
|
21191
|
+
if (!target) return "未找到发表按钮";
|
|
21192
|
+
if (target.classList.contains("weui-desktop-btn_disabled")) return "发表按钮仍处于禁用状态";
|
|
21193
|
+
target.click();
|
|
21194
|
+
return null;
|
|
21195
|
+
});
|
|
21196
|
+
if (clicked) throw new Error(clicked);
|
|
21197
|
+
task.logger.info("已点击发布按钮,等待响应...");
|
|
21198
|
+
try {
|
|
21199
|
+
await page.waitForURL((url)=>url.href !== page.url(), {
|
|
21200
|
+
timeout: 30000
|
|
21201
|
+
});
|
|
21202
|
+
task.logger.info(`发布成功,页面已跳转: ${page.url()}`);
|
|
21203
|
+
} catch {
|
|
21204
|
+
task.logger.warn("等待页面跳转超时,可能发布失败或网络慢,继续关闭页面");
|
|
21205
|
+
}
|
|
21206
|
+
await page.close();
|
|
21207
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(videoId, "发布成功");
|
|
21208
|
+
} catch (error) {
|
|
21209
|
+
let errorMsg = error instanceof Error ? error.message : String(error);
|
|
21210
|
+
if (errorMsg.includes("context or browser has been closed")) errorMsg = "浏览器上下文已被关闭";
|
|
21211
|
+
task.logger.error(`微信视频号视频发布失败: ${errorMsg}`);
|
|
21212
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, `微信视频号视频发布失败: ${errorMsg}`, "");
|
|
21213
|
+
}
|
|
21214
|
+
};
|
|
21215
|
+
const ShipinhaoPublishVideoParamsSchema = ActionCommonParamsSchema.extend({
|
|
21216
|
+
videoPath: schemas_string().min(1),
|
|
21217
|
+
videoMetadata: schemas_object({
|
|
21218
|
+
duration: schemas_number().positive(),
|
|
21219
|
+
width: schemas_number().int().positive(),
|
|
21220
|
+
height: schemas_number().int().positive(),
|
|
21221
|
+
fileSize: schemas_number().int().positive(),
|
|
21222
|
+
path: schemas_string().min(1).optional(),
|
|
21223
|
+
fileName: schemas_string().min(1)
|
|
21224
|
+
}),
|
|
21225
|
+
coverPath: schemas_string().min(1),
|
|
21226
|
+
verticalCoverPath: schemas_string().min(1).optional(),
|
|
21227
|
+
description: schemas_string(),
|
|
21228
|
+
title: schemas_string().optional(),
|
|
21229
|
+
scheduledTime: schemas_number().int().positive().optional(),
|
|
21230
|
+
isImmediatelyPublish: schemas_boolean().optional(),
|
|
21231
|
+
topics: schemas_array(schemas_string()).optional(),
|
|
21232
|
+
mentionedUsers: schemas_array(schemas_object({
|
|
21233
|
+
nickname: schemas_string()
|
|
21234
|
+
})).optional(),
|
|
21235
|
+
collection: schemas_object({
|
|
21236
|
+
collectionId: schemas_string(),
|
|
21237
|
+
collectionName: schemas_string()
|
|
21238
|
+
}).optional(),
|
|
21239
|
+
event: schemas_object({
|
|
21240
|
+
eventTopicId: schemas_string(),
|
|
21241
|
+
eventName: schemas_string(),
|
|
21242
|
+
eventCreatorNickname: schemas_string().optional()
|
|
21243
|
+
}).optional(),
|
|
21244
|
+
link: schemas_object({
|
|
21245
|
+
link: schemas_string(),
|
|
21246
|
+
title: schemas_string(),
|
|
21247
|
+
urlType: schemas_number().int().default(1)
|
|
21248
|
+
}).optional(),
|
|
21249
|
+
tagInfo: looseObject({
|
|
21250
|
+
tagType: schemas_number().int()
|
|
21251
|
+
}).optional(),
|
|
21252
|
+
originalFlag: union([
|
|
21253
|
+
literal(0),
|
|
21254
|
+
literal(1)
|
|
21255
|
+
]).optional(),
|
|
21256
|
+
postWithMemberZoneLink: union([
|
|
21257
|
+
literal(0),
|
|
21258
|
+
literal(1)
|
|
21259
|
+
]).optional(),
|
|
21260
|
+
location: schemas_object({
|
|
21261
|
+
latitude: schemas_number(),
|
|
21262
|
+
longitude: schemas_number(),
|
|
21263
|
+
city: schemas_string(),
|
|
21264
|
+
poiName: schemas_string().optional(),
|
|
21265
|
+
address: schemas_string().optional(),
|
|
21266
|
+
poiClassifyId: schemas_string().optional()
|
|
21267
|
+
}).optional()
|
|
21268
|
+
});
|
|
21269
|
+
const shipinhaoPublishVideo = async (task, params)=>{
|
|
21270
|
+
task.logger.info(`[shipinhaoPublishVideo] actionType: ${params.actionType}`);
|
|
21271
|
+
if ("rpa" === params.actionType) return shipinhaoPublishVideo_rpa_rpaAction(task, params);
|
|
21272
|
+
if ("mockApi" === params.actionType) return shipinhaoPublishVideo_mock_mockAction(task, params);
|
|
21273
|
+
return executeAction(shipinhaoPublishVideo_mock_mockAction, shipinhaoPublishVideo_rpa_rpaAction)(task, params);
|
|
21274
|
+
};
|
|
21275
|
+
const ShipinhaoSendMsgParamsSchema = ActionCommonParamsSchema.extend({
|
|
21276
|
+
toUsername: schemas_string().min(1, "接收者用户名不能为空"),
|
|
21277
|
+
sessionId: schemas_string().min(1, "会话ID不能为空"),
|
|
21278
|
+
msgType: schemas_enum([
|
|
21279
|
+
"TEXT",
|
|
21280
|
+
"IMAGE"
|
|
21281
|
+
], {
|
|
21282
|
+
message: "消息类型必须是 TEXT 或 IMAGE"
|
|
21283
|
+
}),
|
|
21284
|
+
content: schemas_string().optional(),
|
|
21285
|
+
imageInfo: schemas_object({
|
|
21286
|
+
pathOrUrl: schemas_string().min(1, "图片路径或URL不能为空")
|
|
21287
|
+
}).optional()
|
|
21288
|
+
});
|
|
21289
|
+
const shipinhaoSendMsg_CHUNK_SIZE = 524288;
|
|
21290
|
+
async function shipinhaoSendMsg_getUserInfo(cookieStr, http) {
|
|
21291
|
+
const url = `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data?_rid=${rid()}`;
|
|
21292
|
+
const headers = {
|
|
21293
|
+
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
21294
|
+
cookie: cookieStr,
|
|
21295
|
+
Origin: "https://channels.weixin.qq.com"
|
|
21296
|
+
};
|
|
21297
|
+
return await http.api({
|
|
21298
|
+
method: "get",
|
|
21299
|
+
url,
|
|
21300
|
+
headers
|
|
21301
|
+
}, {
|
|
21302
|
+
retries: 3,
|
|
21303
|
+
retryDelay: 1000,
|
|
21304
|
+
timeout: 10000
|
|
21305
|
+
});
|
|
21306
|
+
}
|
|
21307
|
+
const shipinhaoSendMsg = async (_task, params)=>{
|
|
21308
|
+
if (!params.sessionId) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "sessionId 不能为空", void 0);
|
|
21309
|
+
if (!params.toUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "接收者用户名不能为空", void 0);
|
|
21310
|
+
if (!params.msgType) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型不能为空", void 0);
|
|
21311
|
+
if (![
|
|
21312
|
+
"TEXT",
|
|
21313
|
+
"IMAGE"
|
|
21314
|
+
].includes(params.msgType)) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型必须是 TEXT 或 IMAGE", void 0);
|
|
21315
|
+
if ("TEXT" === params.msgType) {
|
|
21316
|
+
if (!params.content || "" === params.content.trim()) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息内容不能为空", void 0);
|
|
21317
|
+
}
|
|
21318
|
+
if ("IMAGE" === params.msgType) {
|
|
21319
|
+
if (!params.imageInfo?.pathOrUrl) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "图片路径或URL不能为空", void 0);
|
|
21320
|
+
}
|
|
21321
|
+
if (!params.extraParam) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "缺少 extraParam 参数", void 0);
|
|
21322
|
+
if (!params.extraParam.fingerPrintDeviceId || !params.extraParam.aId || !params.extraParam.uin) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "fingerPrintDeviceId、aId 和 uin 不能为空", void 0);
|
|
21323
|
+
const cookieStr = params.cookies.map((it)=>`${it.name}=${it.value}`).join(";");
|
|
21324
|
+
const headers = {
|
|
21325
|
+
cookie: cookieStr,
|
|
21326
|
+
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
21327
|
+
origin: "https://channels.weixin.qq.com",
|
|
21328
|
+
"content-type": "application/json",
|
|
21329
|
+
"finger-print-device-id": params.extraParam.fingerPrintDeviceId,
|
|
21330
|
+
"x-wechat-uin": params.extraParam.uin
|
|
21331
|
+
};
|
|
21332
|
+
const http = new Http({
|
|
21333
|
+
headers
|
|
21334
|
+
});
|
|
21335
|
+
const urlParams = new URLSearchParams({
|
|
21336
|
+
_aid: params.extraParam.aId,
|
|
21337
|
+
_rid: rid(),
|
|
21338
|
+
_pageUrl: "https://channels.weixin.qq.com/micro/interaction/private_msg"
|
|
21339
|
+
}).toString();
|
|
21340
|
+
const generateCliMsgId = ()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (s)=>{
|
|
21341
|
+
const t = 16 * Math.random() | 0;
|
|
21342
|
+
return ("x" === s ? t : 3 & t | 8).toString(16);
|
|
21343
|
+
});
|
|
21344
|
+
let fromUsername = params.extraParam.finderUserName;
|
|
21345
|
+
if (!fromUsername) {
|
|
21346
|
+
_task.logger.info("未提供 finderUserName,尝试获取用户信息");
|
|
21347
|
+
const userInfoRes = await shipinhaoSendMsg_getUserInfo(cookieStr, http);
|
|
21348
|
+
if (!userInfoRes.data?.finderUser?.finderUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(userInfoRes.errCode || -1, userInfoRes.errMsg || "获取用户信息失败", {});
|
|
21349
|
+
fromUsername = userInfoRes.data.finderUser.finderUsername;
|
|
21350
|
+
_task.logger.info(`获取到用户名: ${fromUsername}`);
|
|
21351
|
+
}
|
|
21352
|
+
let imgMsg;
|
|
21353
|
+
if ("IMAGE" === params.msgType) {
|
|
21354
|
+
let imageBuffer;
|
|
21355
|
+
const imagePath = params.imageInfo.pathOrUrl;
|
|
21356
|
+
try {
|
|
21357
|
+
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
|
|
21358
|
+
const resp = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(imagePath, {
|
|
21359
|
+
responseType: "arraybuffer"
|
|
21360
|
+
});
|
|
21361
|
+
imageBuffer = Buffer.from(resp.data);
|
|
21362
|
+
} else {
|
|
21363
|
+
const filePath = imagePath.startsWith("file://") ? imagePath.slice(7) : imagePath;
|
|
21364
|
+
imageBuffer = Buffer.from(await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.readFile(filePath));
|
|
21365
|
+
}
|
|
21366
|
+
} catch (err) {
|
|
21367
|
+
_task.logger.error(`读取图片失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
21368
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, USER_MESSAGE.IMAGE_UPLOAD_FAILED, void 0);
|
|
21369
|
+
}
|
|
21370
|
+
const md5 = (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)("md5").update(imageBuffer).digest("hex");
|
|
21371
|
+
const timestamp = Date.now().toString();
|
|
21372
|
+
const totalChunks = Math.ceil(imageBuffer.length / shipinhaoSendMsg_CHUNK_SIZE);
|
|
21373
|
+
console.log(`分片上传md5${md5}`);
|
|
21374
|
+
let lastRes;
|
|
21375
|
+
for(let i = 0; i < totalChunks; i++){
|
|
21376
|
+
const chunkBuffer = imageBuffer.slice(i * shipinhaoSendMsg_CHUNK_SIZE, (i + 1) * shipinhaoSendMsg_CHUNK_SIZE);
|
|
21377
|
+
const requestData = {
|
|
21378
|
+
content: `data:application/octet-stream;base64,${chunkBuffer.toString("base64")}`,
|
|
21379
|
+
chunk: i,
|
|
21380
|
+
chunks: totalChunks,
|
|
21381
|
+
fromUsername,
|
|
21382
|
+
toUsername: params.toUsername,
|
|
21383
|
+
aesKey: "U2FsdGVkX18cwrWR73LMGhBcmAX8xoNTgbmgkZBYkEs=",
|
|
21384
|
+
mediaSize: imageBuffer.length,
|
|
21385
|
+
mediaType: 3,
|
|
21386
|
+
md5,
|
|
21387
|
+
timestamp,
|
|
21388
|
+
_log_finder_uin: "",
|
|
21389
|
+
_log_finder_id: params.extraParam.finderUserName || "",
|
|
21390
|
+
rawKeyBuff: null,
|
|
21391
|
+
pluginSessionId: null,
|
|
21392
|
+
scene: 7,
|
|
21393
|
+
reqScene: 7
|
|
21394
|
+
};
|
|
21395
|
+
lastRes = await http.api({
|
|
21396
|
+
method: "post",
|
|
21397
|
+
url: `https://channels.weixin.qq.com/micro/interaction/cgi-bin/mmfinderassistant-bin/private-msg/upload-media-info?${urlParams}`,
|
|
21398
|
+
data: requestData
|
|
21399
|
+
});
|
|
21400
|
+
console.log(`分片上传 ${i + 1}/${totalChunks} 响应:`, lastRes);
|
|
21401
|
+
if (lastRes?.errCode !== 0 && i < totalChunks - 1) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || `第 ${i + 1}/${totalChunks} 分片上传失败`, void 0);
|
|
21402
|
+
}
|
|
21403
|
+
if (lastRes?.errCode !== 0) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || "上传图片失败", void 0);
|
|
21404
|
+
const uploadedImgMsg = lastRes.data?.imgMsg;
|
|
21405
|
+
imgMsg = {
|
|
21406
|
+
aeskey: uploadedImgMsg.aesKey ?? uploadedImgMsg.aeskey,
|
|
21407
|
+
url: uploadedImgMsg.cdnUrl ?? uploadedImgMsg.url,
|
|
21408
|
+
hdSize: uploadedImgMsg.hdSize ?? uploadedImgMsg.size,
|
|
21409
|
+
midSize: uploadedImgMsg.midSize ?? uploadedImgMsg.size,
|
|
21410
|
+
thumbSize: uploadedImgMsg.thumbSize ?? uploadedImgMsg.size,
|
|
21411
|
+
thumbHeight: uploadedImgMsg.thumbHeight ?? uploadedImgMsg.height,
|
|
21412
|
+
thumbWidth: uploadedImgMsg.thumbWidth ?? uploadedImgMsg.width,
|
|
21413
|
+
md5: uploadedImgMsg.md5
|
|
21414
|
+
};
|
|
21415
|
+
}
|
|
21416
|
+
console.log("发送私信请求参数1111", {
|
|
21417
|
+
sessionId: params.sessionId,
|
|
21418
|
+
fromUsername
|
|
21419
|
+
});
|
|
21420
|
+
const sendRes = await http.api({
|
|
21421
|
+
method: "post",
|
|
21422
|
+
url: `https://channels.weixin.qq.com/micro/interaction/cgi-bin/mmfinderassistant-bin/private-msg/send-private-msg?${urlParams}`,
|
|
21423
|
+
data: {
|
|
21424
|
+
timestamp: Date.now().toString(),
|
|
21425
|
+
_log_finder_uin: "",
|
|
21426
|
+
_log_finder_id: params.extraParam.finderUserName || "",
|
|
21427
|
+
rawKeyBuff: null,
|
|
21428
|
+
pluginSessionId: null,
|
|
21429
|
+
scene: 7,
|
|
21430
|
+
reqScene: 7,
|
|
21431
|
+
msgPack: {
|
|
21432
|
+
sessionId: params.sessionId,
|
|
21433
|
+
fromUsername,
|
|
21434
|
+
toUsername: params.toUsername,
|
|
21435
|
+
cliMsgId: generateCliMsgId(),
|
|
21436
|
+
msgType: "TEXT" === params.msgType ? 1 : 3,
|
|
19599
21437
|
imgMsg: "IMAGE" === params.msgType ? imgMsg : void 0,
|
|
19600
21438
|
textMsg: "TEXT" === params.msgType ? {
|
|
19601
21439
|
content: params.content
|
|
@@ -19988,6 +21826,13 @@ const toutiaoPublish_mock_mockAction = async (task, params)=>{
|
|
|
19988
21826
|
const uploadImages = async (images)=>await Promise.all(images.map(async (url)=>{
|
|
19989
21827
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
19990
21828
|
const image = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
21829
|
+
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(image);
|
|
21830
|
+
const maxSize = 20971520;
|
|
21831
|
+
if (stats.size > maxSize) throw {
|
|
21832
|
+
code: 414,
|
|
21833
|
+
message: "头条号平台:单张图片不得超过 20MB",
|
|
21834
|
+
data: ""
|
|
21835
|
+
};
|
|
19991
21836
|
const formData = new __WEBPACK_EXTERNAL_MODULE_form_data_cf000082__["default"]();
|
|
19992
21837
|
formData.append("image", __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].createReadStream(image));
|
|
19993
21838
|
const response = await http.api({
|
|
@@ -22038,18 +23883,10 @@ const weixinPublish_mock_mockAction = async (task, params)=>{
|
|
|
22038
23883
|
});
|
|
22039
23884
|
} catch (error) {
|
|
22040
23885
|
const handledError = Http.handleApiError(error);
|
|
22041
|
-
const
|
|
22042
|
-
|
|
22043
|
-
|
|
22044
|
-
|
|
22045
|
-
503,
|
|
22046
|
-
504
|
|
22047
|
-
].includes(handledError.code);
|
|
22048
|
-
if (isProxyOrNetworkError) {
|
|
22049
|
-
const isProxyRequest = handledError.extra?.isProxyRequest === true;
|
|
22050
|
-
const errorType = 599 === handledError.code || isProxyRequest ? "代理错误" : "网络错误";
|
|
22051
|
-
const message = `文章发布失败,${errorType}:${handledError.message}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
22052
|
-
task.logger.error(`[weixinPublish] ${errorType},直接返回: ${message}`, stringifyError(handledError));
|
|
23886
|
+
const classified = classifyPublishError(handledError);
|
|
23887
|
+
if (classified) {
|
|
23888
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
23889
|
+
task.logger.error(`[weixinPublish] ${classified.category},直接返回: ${handledError.message} (code=${handledError.code})`, stringifyError(handledError));
|
|
22053
23890
|
await updateTaskState?.({
|
|
22054
23891
|
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
22055
23892
|
error: message
|
|
@@ -23279,6 +25116,12 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23279
25116
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
23280
25117
|
const localUrl = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
23281
25118
|
const fileBuffer = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(localUrl);
|
|
25119
|
+
const maxSize = 33554432;
|
|
25120
|
+
if (fileBuffer.byteLength > maxSize) throw {
|
|
25121
|
+
code: 414,
|
|
25122
|
+
message: "小红书平台:单张图片不得超过 32MB",
|
|
25123
|
+
data: ""
|
|
25124
|
+
};
|
|
23282
25125
|
let width = 0;
|
|
23283
25126
|
let height = 0;
|
|
23284
25127
|
try {
|
|
@@ -23517,6 +25360,7 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23517
25360
|
});
|
|
23518
25361
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(data, message);
|
|
23519
25362
|
}
|
|
25363
|
+
task.logger.info(`[xiaohongshuPublish] publishData: ${JSON.stringify(publishData)} `);
|
|
23520
25364
|
let publishResult;
|
|
23521
25365
|
try {
|
|
23522
25366
|
publishResult = await proxyHttp.api({
|
|
@@ -23527,23 +25371,15 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23527
25371
|
defaultErrorMsg: "文章发布异常,请稍后重试。"
|
|
23528
25372
|
}, {
|
|
23529
25373
|
retries: 2,
|
|
23530
|
-
retryDelay:
|
|
23531
|
-
timeout:
|
|
25374
|
+
retryDelay: 3000,
|
|
25375
|
+
timeout: 30000
|
|
23532
25376
|
});
|
|
23533
25377
|
} catch (error) {
|
|
23534
25378
|
const handledError = Http.handleApiError(error);
|
|
23535
|
-
const
|
|
23536
|
-
|
|
23537
|
-
|
|
23538
|
-
|
|
23539
|
-
503,
|
|
23540
|
-
504
|
|
23541
|
-
].includes(handledError.code);
|
|
23542
|
-
if (isProxyOrNetworkError) {
|
|
23543
|
-
const isProxyRequest = handledError.extra?.isProxyRequest === true;
|
|
23544
|
-
const errorType = 599 === handledError.code || isProxyRequest ? "代理错误" : "网络错误";
|
|
23545
|
-
const message = `文章发布失败,${errorType}:${handledError.message}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
23546
|
-
task.logger.error(`[xiaohongshuPublish] ${errorType},直接返回: ${message}`, stringifyError(handledError));
|
|
25379
|
+
const classified = classifyPublishError(handledError);
|
|
25380
|
+
if (classified) {
|
|
25381
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
25382
|
+
task.logger.error(`[xiaohongshuPublish] ${classified.category},直接返回: ${handledError.message} (code=${handledError.code})`, stringifyError(handledError));
|
|
23547
25383
|
await updateTaskState?.({
|
|
23548
25384
|
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
23549
25385
|
error: message
|
|
@@ -25239,6 +27075,14 @@ class Action {
|
|
|
25239
27075
|
this.task = task;
|
|
25240
27076
|
this.task.logger.info(`当前包版本:Share=>${__WEBPACK_EXTERNAL_MODULE__iflyrpa_share_package_json_58ae5f06__["default"].version} Action=>${package_namespaceObject.i8}`);
|
|
25241
27077
|
}
|
|
27078
|
+
getActionVersionMarker() {
|
|
27079
|
+
return {
|
|
27080
|
+
version: package_namespaceObject.i8,
|
|
27081
|
+
shareVersion: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_package_json_58ae5f06__["default"].version,
|
|
27082
|
+
marker: `Action_${package_namespaceObject.i8}_${__WEBPACK_EXTERNAL_MODULE__iflyrpa_share_package_json_58ae5f06__["default"].version}`,
|
|
27083
|
+
timestamp: new Date().toLocaleString()
|
|
27084
|
+
};
|
|
27085
|
+
}
|
|
25242
27086
|
async bindTask(func, params) {
|
|
25243
27087
|
let responseData;
|
|
25244
27088
|
this.task.isBeta = this.task?.isFeatOn ? this.task?.isFeatOn(BetaFlag) : false;
|
|
@@ -25462,6 +27306,9 @@ class Action {
|
|
|
25462
27306
|
shipinhaoPublish(params) {
|
|
25463
27307
|
return this.bindTask(shipinhaoPublish, params);
|
|
25464
27308
|
}
|
|
27309
|
+
shipinhaoPublishVideo(params) {
|
|
27310
|
+
return this.bindTask(shipinhaoPublishVideo, params);
|
|
27311
|
+
}
|
|
25465
27312
|
douyinGetTopics(params) {
|
|
25466
27313
|
return this.bindTask(douyinGetTopics, params);
|
|
25467
27314
|
}
|
|
@@ -25515,7 +27362,7 @@ class Action {
|
|
|
25515
27362
|
}
|
|
25516
27363
|
}
|
|
25517
27364
|
var __webpack_exports__version = package_namespaceObject.i8;
|
|
25518
|
-
export { Action, ActionCommonParamsSchema, BaijiahaoPublishParamsSchema, BetaFlag, CollectionDetailSchema, ConfigDataSchema, DouyinCheckVerifyQrCodeParamsSchema, DouyinCreateCommentReplyParamsSchema, DouyinGetCollectionParamsSchema, DouyinGetCommentListParamsSchema, DouyinGetCommentReplyListParamsSchema, DouyinGetHotParamsSchema, DouyinGetLocationParamsSchema, DouyinGetMusicByCategoryParamsSchema, DouyinGetMusicCategoryParamsSchema, DouyinGetMusicParamsSchema, DouyinGetTopicsParamsSchema, DouyinGetVerifyQrCodeParamsSchema, DouyinGetWorkListParamsSchema, DouyinPublishParamsSchema, FetchArticlesDataSchema, FetchArticlesParamsSchema, Http, ProxyAgent, SearchAccountInfoParamsSchema, SessionCheckResultSchema, ShipinhaoCheckLinkValidateParamsSchema, ShipinhaoGetLocationParamsSchema, ShipinhaoGetMsgParamsSchema, ShipinhaoPublishParamsSchema, ShipinhaoSendMsgParamsSchema, ToutiaoPublishParamsSchema, UnreadCountSchema, WeixinPublishParamsSchema, WxBjhSessionParamsSchema, XhsWebSearchParamsSchema, XiaohongshuPublishParamsSchema, bjhConfigDataSchema, douyinConfigDataSchema, getFileState, reportLogger, rpaAction_Server_Mock, shipinhaoConfigDataSchema, ttConfigDataSchema, wxConfigDataSchema, xhsConfigDataSchema, __webpack_exports__version as version };
|
|
27365
|
+
export { Action, ActionCommonParamsSchema, BaijiahaoPublishParamsSchema, BetaFlag, CollectionDetailSchema, ConfigDataSchema, DouyinCheckVerifyQrCodeParamsSchema, DouyinCreateCommentReplyParamsSchema, DouyinGetCollectionParamsSchema, DouyinGetCommentListParamsSchema, DouyinGetCommentReplyListParamsSchema, DouyinGetHotParamsSchema, DouyinGetLocationParamsSchema, DouyinGetMusicByCategoryParamsSchema, DouyinGetMusicCategoryParamsSchema, DouyinGetMusicParamsSchema, DouyinGetTopicsParamsSchema, DouyinGetVerifyQrCodeParamsSchema, DouyinGetWorkListParamsSchema, DouyinPublishParamsSchema, FetchArticlesDataSchema, FetchArticlesParamsSchema, Http, ProxyAgent, SearchAccountInfoParamsSchema, SessionCheckResultSchema, ShipinhaoCheckLinkValidateParamsSchema, ShipinhaoGetLocationParamsSchema, ShipinhaoGetMsgParamsSchema, ShipinhaoPublishParamsSchema, ShipinhaoPublishVideoParamsSchema, ShipinhaoSendMsgParamsSchema, ToutiaoPublishParamsSchema, UnreadCountSchema, WeixinPublishParamsSchema, WxBjhSessionParamsSchema, XhsWebSearchParamsSchema, XiaohongshuPublishParamsSchema, bjhConfigDataSchema, douyinConfigDataSchema, getFileState, reportLogger, rpaAction_Server_Mock, shipinhaoConfigDataSchema, ttConfigDataSchema, wxConfigDataSchema, xhsConfigDataSchema, __webpack_exports__version as version };
|
|
25519
27366
|
|
|
25520
27367
|
//# sourceMappingURL=index.mjs.map
|
|
25521
|
-
//# debugId=
|
|
27368
|
+
//# debugId=d7b84b2c-f6d7-5874-b962-65e4fb23456c
|