@iflyrpa/actions 4.0.9-beta.4 → 4.1.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +35 -0
- package/dist/bundle.js +1693 -9
- package/dist/bundle.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1895 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1895 -212
- package/dist/index.mjs.map +1 -1
- package/dist/utils/http.d.ts +7 -0
- package/dist/utils/imageValidator.d.ts +67 -0
- package/dist/utils/shipinhao/auth.d.ts +31 -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]="4c43edf6-56aa-502f-8c51-85f87e629735")}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,7 +4352,7 @@ function __webpack_require__(moduleId) {
|
|
|
4352
4352
|
return module;
|
|
4353
4353
|
};
|
|
4354
4354
|
})();
|
|
4355
|
-
var package_namespaceObject = JSON.parse('{"i8":"4.0
|
|
4355
|
+
var package_namespaceObject = JSON.parse('{"i8":"4.1.0-beta.6"}');
|
|
4356
4356
|
const USER_MESSAGE = {
|
|
4357
4357
|
PROXY_UNAVAILABLE: "代理暂时不可用,请稍后重试或使用本地IP",
|
|
4358
4358
|
NETWORK_ERROR: "网络异常,请稍后重试",
|
|
@@ -4804,23 +4804,33 @@ class Http {
|
|
|
4804
4804
|
async api(config, options) {
|
|
4805
4805
|
const retries = options?.retries ?? 0;
|
|
4806
4806
|
const retryDelay = options?.retryDelay ?? 500;
|
|
4807
|
-
const reqTimeout = options?.timeout ??
|
|
4807
|
+
const reqTimeout = options?.timeout ?? 60000;
|
|
4808
|
+
const externalSignal = options?.signal;
|
|
4808
4809
|
let agent;
|
|
4809
4810
|
const sessionRt = async (Rtimes)=>{
|
|
4810
4811
|
try {
|
|
4811
4812
|
this.proxyInfo = agent ? `${agent.ip}:${agent.port}` : void 0;
|
|
4812
4813
|
const controller = new AbortController();
|
|
4813
4814
|
const timeoutId = setTimeout(()=>controller.abort(), reqTimeout + 500);
|
|
4815
|
+
const forwardAbort = ()=>controller.abort();
|
|
4816
|
+
if (externalSignal) {
|
|
4817
|
+
if (externalSignal.aborted) controller.abort();
|
|
4818
|
+
else externalSignal.addEventListener("abort", forwardAbort, {
|
|
4819
|
+
once: true
|
|
4820
|
+
});
|
|
4821
|
+
}
|
|
4814
4822
|
const response = await this.apiClient({
|
|
4815
4823
|
...config,
|
|
4816
4824
|
timeout: reqTimeout,
|
|
4817
4825
|
signal: controller.signal,
|
|
4826
|
+
onUploadProgress: options?.onUploadProgress,
|
|
4818
4827
|
...agent ? {
|
|
4819
4828
|
httpAgent: agent.agent,
|
|
4820
4829
|
httpsAgent: agent.agent
|
|
4821
4830
|
} : {}
|
|
4822
4831
|
}).finally(()=>{
|
|
4823
4832
|
clearTimeout(timeoutId);
|
|
4833
|
+
externalSignal?.removeEventListener("abort", forwardAbort);
|
|
4824
4834
|
});
|
|
4825
4835
|
return response.data;
|
|
4826
4836
|
} catch (error) {
|
|
@@ -5935,7 +5945,7 @@ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
|
5935
5945
|
const xid = /^[0-9a-vA-V]{20}$/;
|
|
5936
5946
|
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
5937
5947
|
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
5938
|
-
const
|
|
5948
|
+
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)?)?)$/;
|
|
5939
5949
|
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})$/;
|
|
5940
5950
|
const regexes_uuid = (version)=>{
|
|
5941
5951
|
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)$/;
|
|
@@ -6621,7 +6631,7 @@ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def)=>{
|
|
|
6621
6631
|
$ZodStringFormat.init(inst, def);
|
|
6622
6632
|
});
|
|
6623
6633
|
const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def)=>{
|
|
6624
|
-
def.pattern ?? (def.pattern =
|
|
6634
|
+
def.pattern ?? (def.pattern = regexes_duration);
|
|
6625
6635
|
$ZodStringFormat.init(inst, def);
|
|
6626
6636
|
});
|
|
6627
6637
|
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def)=>{
|
|
@@ -8559,6 +8569,14 @@ function schemas_object(shape, params) {
|
|
|
8559
8569
|
};
|
|
8560
8570
|
return new ZodObject(def);
|
|
8561
8571
|
}
|
|
8572
|
+
function looseObject(shape, params) {
|
|
8573
|
+
return new ZodObject({
|
|
8574
|
+
type: "object",
|
|
8575
|
+
shape,
|
|
8576
|
+
catchall: unknown(),
|
|
8577
|
+
...normalizeParams(params)
|
|
8578
|
+
});
|
|
8579
|
+
}
|
|
8562
8580
|
const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def)=>{
|
|
8563
8581
|
$ZodUnion.init(inst, def);
|
|
8564
8582
|
ZodType.init(inst, def);
|
|
@@ -9255,6 +9273,13 @@ const mockAction = async (task, params)=>{
|
|
|
9255
9273
|
data: ""
|
|
9256
9274
|
};
|
|
9257
9275
|
const image = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
9276
|
+
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(image);
|
|
9277
|
+
const maxSize = 5242880;
|
|
9278
|
+
if (stats.size > maxSize) throw {
|
|
9279
|
+
code: 414,
|
|
9280
|
+
message: "百家号平台:单张图片不得超过 5MB",
|
|
9281
|
+
data: ""
|
|
9282
|
+
};
|
|
9258
9283
|
const formData = new __WEBPACK_EXTERNAL_MODULE_form_data_cf000082__["default"]();
|
|
9259
9284
|
formData.append("org_file_name", fileName);
|
|
9260
9285
|
formData.append("type", "image");
|
|
@@ -13385,6 +13410,11 @@ class DouyinImageUploader {
|
|
|
13385
13410
|
}
|
|
13386
13411
|
async getImageInfo(localPath) {
|
|
13387
13412
|
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(localPath);
|
|
13413
|
+
const maxSize = 52428800;
|
|
13414
|
+
if (stats.size > maxSize) {
|
|
13415
|
+
__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(localPath);
|
|
13416
|
+
throw new Error("抖音平台:单张图片不得超过 50MB");
|
|
13417
|
+
}
|
|
13388
13418
|
let width = 1080;
|
|
13389
13419
|
let height = 1920;
|
|
13390
13420
|
try {
|
|
@@ -19627,223 +19657,1860 @@ const shipinhaoPublish = async (task, params)=>{
|
|
|
19627
19657
|
if ("server" === params.actionType) return rpa_server_rpaAction_Server(task, params);
|
|
19628
19658
|
return executeAction(shipinhaoPublish_mock_mockAction, rpa_server_rpaAction_Server)(task, params);
|
|
19629
19659
|
};
|
|
19630
|
-
|
|
19631
|
-
|
|
19632
|
-
sessionId: schemas_string().min(1, "会话ID不能为空"),
|
|
19633
|
-
msgType: schemas_enum([
|
|
19634
|
-
"TEXT",
|
|
19635
|
-
"IMAGE"
|
|
19636
|
-
], {
|
|
19637
|
-
message: "消息类型必须是 TEXT 或 IMAGE"
|
|
19638
|
-
}),
|
|
19639
|
-
content: schemas_string().optional(),
|
|
19640
|
-
imageInfo: schemas_object({
|
|
19641
|
-
pathOrUrl: schemas_string().min(1, "图片路径或URL不能为空")
|
|
19642
|
-
}).optional()
|
|
19643
|
-
});
|
|
19644
|
-
const CHUNK_SIZE = 524288;
|
|
19645
|
-
async function shipinhaoSendMsg_getUserInfo(cookieStr, http) {
|
|
19646
|
-
const url = `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data?_rid=${rid()}`;
|
|
19647
|
-
const headers = {
|
|
19648
|
-
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
19649
|
-
cookie: cookieStr,
|
|
19650
|
-
Origin: "https://channels.weixin.qq.com"
|
|
19651
|
-
};
|
|
19652
|
-
return await http.api({
|
|
19653
|
-
method: "get",
|
|
19654
|
-
url,
|
|
19655
|
-
headers
|
|
19656
|
-
}, {
|
|
19657
|
-
retries: 3,
|
|
19658
|
-
retryDelay: 1000,
|
|
19659
|
-
timeout: 10000
|
|
19660
|
-
});
|
|
19660
|
+
function auth_getTimeStamp(length) {
|
|
19661
|
+
return Date.now().toString().substring(0, length);
|
|
19661
19662
|
}
|
|
19662
|
-
|
|
19663
|
-
|
|
19664
|
-
if (!params.toUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "接收者用户名不能为空", void 0);
|
|
19665
|
-
if (!params.msgType) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型不能为空", void 0);
|
|
19666
|
-
if (![
|
|
19667
|
-
"TEXT",
|
|
19668
|
-
"IMAGE"
|
|
19669
|
-
].includes(params.msgType)) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型必须是 TEXT 或 IMAGE", void 0);
|
|
19670
|
-
if ("TEXT" === params.msgType) {
|
|
19671
|
-
if (!params.content || "" === params.content.trim()) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息内容不能为空", void 0);
|
|
19672
|
-
}
|
|
19673
|
-
if ("IMAGE" === params.msgType) {
|
|
19674
|
-
if (!params.imageInfo?.pathOrUrl) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "图片路径或URL不能为空", void 0);
|
|
19675
|
-
}
|
|
19676
|
-
if (!params.extraParam) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "缺少 extraParam 参数", void 0);
|
|
19677
|
-
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);
|
|
19678
|
-
const cookieStr = params.cookies.map((it)=>`${it.name}=${it.value}`).join(";");
|
|
19679
|
-
const headers = {
|
|
19680
|
-
cookie: cookieStr,
|
|
19681
|
-
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
19682
|
-
origin: "https://channels.weixin.qq.com",
|
|
19683
|
-
"content-type": "application/json",
|
|
19684
|
-
"finger-print-device-id": params.extraParam.fingerPrintDeviceId,
|
|
19685
|
-
"x-wechat-uin": params.extraParam.uin
|
|
19686
|
-
};
|
|
19687
|
-
const http = new Http({
|
|
19688
|
-
headers
|
|
19689
|
-
});
|
|
19690
|
-
const urlParams = new URLSearchParams({
|
|
19691
|
-
_aid: params.extraParam.aId,
|
|
19692
|
-
_rid: rid(),
|
|
19693
|
-
_pageUrl: "https://channels.weixin.qq.com/micro/interaction/private_msg"
|
|
19694
|
-
}).toString();
|
|
19695
|
-
const generateCliMsgId = ()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (s)=>{
|
|
19696
|
-
const t = 16 * Math.random() | 0;
|
|
19697
|
-
return ("x" === s ? t : 3 & t | 8).toString(16);
|
|
19698
|
-
});
|
|
19699
|
-
let fromUsername = params.extraParam.finderUserName;
|
|
19700
|
-
if (!fromUsername) {
|
|
19701
|
-
_task.logger.info("未提供 finderUserName,尝试获取用户信息");
|
|
19702
|
-
const userInfoRes = await shipinhaoSendMsg_getUserInfo(cookieStr, http);
|
|
19703
|
-
if (!userInfoRes.data?.finderUser?.finderUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(userInfoRes.errCode || -1, userInfoRes.errMsg || "获取用户信息失败", {});
|
|
19704
|
-
fromUsername = userInfoRes.data.finderUser.finderUsername;
|
|
19705
|
-
_task.logger.info(`获取到用户名: ${fromUsername}`);
|
|
19706
|
-
}
|
|
19707
|
-
let imgMsg;
|
|
19708
|
-
if ("IMAGE" === params.msgType) {
|
|
19709
|
-
let imageBuffer;
|
|
19710
|
-
const imagePath = params.imageInfo.pathOrUrl;
|
|
19711
|
-
try {
|
|
19712
|
-
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
|
|
19713
|
-
const resp = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(imagePath, {
|
|
19714
|
-
responseType: "arraybuffer"
|
|
19715
|
-
});
|
|
19716
|
-
imageBuffer = Buffer.from(resp.data);
|
|
19717
|
-
} else {
|
|
19718
|
-
const filePath = imagePath.startsWith("file://") ? imagePath.slice(7) : imagePath;
|
|
19719
|
-
imageBuffer = Buffer.from(await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.readFile(filePath));
|
|
19720
|
-
}
|
|
19721
|
-
} catch (err) {
|
|
19722
|
-
_task.logger.error(`读取图片失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
19723
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, USER_MESSAGE.IMAGE_UPLOAD_FAILED, void 0);
|
|
19724
|
-
}
|
|
19725
|
-
const md5 = (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)("md5").update(imageBuffer).digest("hex");
|
|
19726
|
-
const timestamp = Date.now().toString();
|
|
19727
|
-
const totalChunks = Math.ceil(imageBuffer.length / CHUNK_SIZE);
|
|
19728
|
-
console.log(`分片上传md5${md5}`);
|
|
19729
|
-
let lastRes;
|
|
19730
|
-
for(let i = 0; i < totalChunks; i++){
|
|
19731
|
-
const chunkBuffer = imageBuffer.slice(i * CHUNK_SIZE, (i + 1) * CHUNK_SIZE);
|
|
19732
|
-
const requestData = {
|
|
19733
|
-
content: `data:application/octet-stream;base64,${chunkBuffer.toString("base64")}`,
|
|
19734
|
-
chunk: i,
|
|
19735
|
-
chunks: totalChunks,
|
|
19736
|
-
fromUsername,
|
|
19737
|
-
toUsername: params.toUsername,
|
|
19738
|
-
aesKey: "U2FsdGVkX18cwrWR73LMGhBcmAX8xoNTgbmgkZBYkEs=",
|
|
19739
|
-
mediaSize: imageBuffer.length,
|
|
19740
|
-
mediaType: 3,
|
|
19741
|
-
md5,
|
|
19742
|
-
timestamp,
|
|
19743
|
-
_log_finder_uin: "",
|
|
19744
|
-
_log_finder_id: params.extraParam.finderUserName || "",
|
|
19745
|
-
rawKeyBuff: null,
|
|
19746
|
-
pluginSessionId: null,
|
|
19747
|
-
scene: 7,
|
|
19748
|
-
reqScene: 7
|
|
19749
|
-
};
|
|
19750
|
-
lastRes = await http.api({
|
|
19751
|
-
method: "post",
|
|
19752
|
-
url: `https://channels.weixin.qq.com/micro/interaction/cgi-bin/mmfinderassistant-bin/private-msg/upload-media-info?${urlParams}`,
|
|
19753
|
-
data: requestData
|
|
19754
|
-
});
|
|
19755
|
-
console.log(`分片上传 ${i + 1}/${totalChunks} 响应:`, lastRes);
|
|
19756
|
-
if (lastRes?.errCode !== 0 && i < totalChunks - 1) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || `第 ${i + 1}/${totalChunks} 分片上传失败`, void 0);
|
|
19757
|
-
}
|
|
19758
|
-
if (lastRes?.errCode !== 0) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || "上传图片失败", void 0);
|
|
19759
|
-
const uploadedImgMsg = lastRes.data?.imgMsg;
|
|
19760
|
-
imgMsg = {
|
|
19761
|
-
aeskey: uploadedImgMsg.aesKey ?? uploadedImgMsg.aeskey,
|
|
19762
|
-
url: uploadedImgMsg.cdnUrl ?? uploadedImgMsg.url,
|
|
19763
|
-
hdSize: uploadedImgMsg.hdSize ?? uploadedImgMsg.size,
|
|
19764
|
-
midSize: uploadedImgMsg.midSize ?? uploadedImgMsg.size,
|
|
19765
|
-
thumbSize: uploadedImgMsg.thumbSize ?? uploadedImgMsg.size,
|
|
19766
|
-
thumbHeight: uploadedImgMsg.thumbHeight ?? uploadedImgMsg.height,
|
|
19767
|
-
thumbWidth: uploadedImgMsg.thumbWidth ?? uploadedImgMsg.width,
|
|
19768
|
-
md5: uploadedImgMsg.md5
|
|
19769
|
-
};
|
|
19770
|
-
}
|
|
19771
|
-
console.log("发送私信请求参数1111", {
|
|
19772
|
-
sessionId: params.sessionId,
|
|
19773
|
-
fromUsername
|
|
19774
|
-
});
|
|
19775
|
-
const sendRes = await http.api({
|
|
19663
|
+
async function auth_getUserInfo(cookies, http) {
|
|
19664
|
+
return http.api({
|
|
19776
19665
|
method: "post",
|
|
19777
|
-
url:
|
|
19666
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data",
|
|
19778
19667
|
data: {
|
|
19779
|
-
timestamp:
|
|
19668
|
+
timestamp: auth_getTimeStamp(13),
|
|
19780
19669
|
_log_finder_uin: "",
|
|
19781
|
-
_log_finder_id:
|
|
19670
|
+
_log_finder_id: "",
|
|
19782
19671
|
rawKeyBuff: null,
|
|
19783
19672
|
pluginSessionId: null,
|
|
19784
19673
|
scene: 7,
|
|
19785
|
-
reqScene: 7
|
|
19786
|
-
|
|
19787
|
-
|
|
19788
|
-
|
|
19789
|
-
|
|
19790
|
-
|
|
19791
|
-
|
|
19792
|
-
|
|
19793
|
-
textMsg: "TEXT" === params.msgType ? {
|
|
19794
|
-
content: params.content
|
|
19795
|
-
} : void 0
|
|
19796
|
-
}
|
|
19797
|
-
}
|
|
19674
|
+
reqScene: 7
|
|
19675
|
+
},
|
|
19676
|
+
headers: {
|
|
19677
|
+
cookie: cookies,
|
|
19678
|
+
referer: "https://channels.weixin.qq.com",
|
|
19679
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
19680
|
+
},
|
|
19681
|
+
defaultErrorMsg: "获取用户信息失败"
|
|
19798
19682
|
});
|
|
19799
|
-
|
|
19800
|
-
|
|
19801
|
-
return
|
|
19802
|
-
|
|
19803
|
-
|
|
19804
|
-
|
|
19805
|
-
|
|
19806
|
-
|
|
19807
|
-
|
|
19808
|
-
|
|
19809
|
-
|
|
19810
|
-
|
|
19683
|
+
}
|
|
19684
|
+
async function auth_getUploadAuthKey(cookies, finderUsername, http) {
|
|
19685
|
+
return http.api({
|
|
19686
|
+
method: "post",
|
|
19687
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/helper/helper_upload_params",
|
|
19688
|
+
data: {
|
|
19689
|
+
timestamp: auth_getTimeStamp(13),
|
|
19690
|
+
_log_finder_id: finderUsername,
|
|
19691
|
+
rawKeyBuff: null
|
|
19692
|
+
},
|
|
19693
|
+
headers: {
|
|
19694
|
+
cookie: cookies,
|
|
19695
|
+
referer: "https://channels.weixin.qq.com",
|
|
19696
|
+
Accept: "application/json, text/plain, */*",
|
|
19697
|
+
"Content-Type": "application/json",
|
|
19698
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
19699
|
+
},
|
|
19700
|
+
defaultErrorMsg: "获取上传认证密钥失败"
|
|
19701
|
+
});
|
|
19702
|
+
}
|
|
19703
|
+
class ShipinhaoAuthError extends Error {
|
|
19704
|
+
constructor(message, errCode){
|
|
19705
|
+
super(message), this.errCode = errCode;
|
|
19706
|
+
this.name = "ShipinhaoAuthError";
|
|
19707
|
+
}
|
|
19708
|
+
}
|
|
19709
|
+
async function getShipinhaoUploadAuth(cookies, http) {
|
|
19710
|
+
const userInfo = await auth_getUserInfo(cookies, http);
|
|
19711
|
+
if (0 !== userInfo.errCode || !userInfo.data?.finderUser) {
|
|
19712
|
+
const isLoginExpired = 300333 === userInfo.errCode || 300334 === userInfo.errCode;
|
|
19713
|
+
throw new ShipinhaoAuthError(isLoginExpired ? "登录失效" : userInfo.errMsg || "获取用户信息失败", userInfo.errCode || 500);
|
|
19714
|
+
}
|
|
19715
|
+
const finderUsername = userInfo.data.finderUser.finderUsername;
|
|
19716
|
+
const authKeyResponse = await auth_getUploadAuthKey(cookies, finderUsername, http);
|
|
19717
|
+
if (0 !== authKeyResponse.errCode || !authKeyResponse.data?.authKey) throw new ShipinhaoAuthError(`获取上传认证参数失败: ${authKeyResponse.errMsg}`, authKeyResponse.errCode || 500);
|
|
19718
|
+
const uin = authKeyResponse.data.uin;
|
|
19719
|
+
if (!uin) throw new ShipinhaoAuthError("获取用户 uin 失败", 500);
|
|
19720
|
+
const videoFileType = authKeyResponse.data.videoFileType || 20302;
|
|
19721
|
+
const pictureFileType = authKeyResponse.data.pictureFileType || 20304;
|
|
19722
|
+
return {
|
|
19723
|
+
uin,
|
|
19724
|
+
authKey: authKeyResponse.data.authKey,
|
|
19725
|
+
finderUsername,
|
|
19726
|
+
videoFileType,
|
|
19727
|
+
pictureFileType
|
|
19811
19728
|
};
|
|
19812
|
-
|
|
19813
|
-
|
|
19814
|
-
|
|
19815
|
-
|
|
19816
|
-
|
|
19817
|
-
|
|
19818
|
-
|
|
19819
|
-
|
|
19820
|
-
|
|
19821
|
-
|
|
19822
|
-
|
|
19823
|
-
|
|
19824
|
-
|
|
19825
|
-
|
|
19826
|
-
|
|
19827
|
-
|
|
19729
|
+
}
|
|
19730
|
+
const MENTION_TEXT_SUFFIX = "\u0020";
|
|
19731
|
+
const MENTION_XML_SUFFIX = "\u2005";
|
|
19732
|
+
function payload_buildDescription(params) {
|
|
19733
|
+
let description = params.description || "";
|
|
19734
|
+
for (const topic of params.topics || [])description += `#${topic}`;
|
|
19735
|
+
for (const user of params.mentionedUsers || [])description += `@${user.nickname}${MENTION_TEXT_SUFFIX}`;
|
|
19736
|
+
return description;
|
|
19737
|
+
}
|
|
19738
|
+
function buildMentionedUser(mentionedUsers) {
|
|
19739
|
+
return (mentionedUsers || []).map((user)=>({
|
|
19740
|
+
nickname: `${user.nickname}${MENTION_TEXT_SUFFIX}`
|
|
19741
|
+
}));
|
|
19742
|
+
}
|
|
19743
|
+
function payload_buildTopicXml(params) {
|
|
19744
|
+
const values = [];
|
|
19745
|
+
let atIndex = null;
|
|
19746
|
+
if (params.description) values.push(`<![CDATA[${params.description}]]>`);
|
|
19747
|
+
for (const topic of params.topics || [])values.push(`<topic><![CDATA[#${topic}#]]></topic>`);
|
|
19748
|
+
for (const user of params.mentionedUsers || []){
|
|
19749
|
+
if (null === atIndex) atIndex = values.length;
|
|
19750
|
+
values.push(`<![CDATA[@${user.nickname}${MENTION_XML_SUFFIX}]]>`);
|
|
19828
19751
|
}
|
|
19829
|
-
|
|
19830
|
-
|
|
19831
|
-
|
|
19832
|
-
|
|
19833
|
-
|
|
19834
|
-
|
|
19835
|
-
}).toString();
|
|
19836
|
-
task.reportService?.settingSessionID?.(task._session?.id || "");
|
|
19837
|
-
await page.route(/\/welcome.*\.(png|mp4)$/i, (route)=>route.abort());
|
|
19838
|
-
await reporter(0, "浏览器启动成功,请使用头条号App扫码登录……", {
|
|
19839
|
-
connectAddress
|
|
19752
|
+
let xml = "<finder>";
|
|
19753
|
+
xml += "<version>1</version>";
|
|
19754
|
+
xml += `<valuecount>${values.length}</valuecount>`;
|
|
19755
|
+
xml += `<style><at>${atIndex ?? ""}</at></style>`;
|
|
19756
|
+
values.forEach((value, index)=>{
|
|
19757
|
+
xml += `<value${index}>${value}</value${index}>`;
|
|
19840
19758
|
});
|
|
19841
|
-
|
|
19842
|
-
|
|
19843
|
-
|
|
19844
|
-
|
|
19759
|
+
xml += "</finder>";
|
|
19760
|
+
return xml;
|
|
19761
|
+
}
|
|
19762
|
+
function payload_buildLocation(location) {
|
|
19763
|
+
if (!location) return {
|
|
19764
|
+
latitude: 0,
|
|
19765
|
+
longitude: 0,
|
|
19766
|
+
city: "",
|
|
19767
|
+
poiName: "",
|
|
19768
|
+
address: "",
|
|
19769
|
+
poiClassifyId: ""
|
|
19845
19770
|
};
|
|
19846
|
-
|
|
19771
|
+
return {
|
|
19772
|
+
latitude: location.latitude,
|
|
19773
|
+
longitude: location.longitude,
|
|
19774
|
+
city: location.city,
|
|
19775
|
+
poiName: location.poiName || "",
|
|
19776
|
+
address: location.address || "",
|
|
19777
|
+
poiClassifyId: location.poiClassifyId || ""
|
|
19778
|
+
};
|
|
19779
|
+
}
|
|
19780
|
+
function buildTopic(params) {
|
|
19781
|
+
const topic = {
|
|
19782
|
+
finderTopicInfo: payload_buildTopicXml(params)
|
|
19783
|
+
};
|
|
19784
|
+
if (params.collection) {
|
|
19785
|
+
topic.collectionId = params.collection.collectionId;
|
|
19786
|
+
topic.collectionName = params.collection.collectionName;
|
|
19787
|
+
}
|
|
19788
|
+
return topic;
|
|
19789
|
+
}
|
|
19790
|
+
function buildEvent(event) {
|
|
19791
|
+
if (!event) return {};
|
|
19792
|
+
return {
|
|
19793
|
+
eventTopicId: event.eventTopicId,
|
|
19794
|
+
eventName: event.eventName,
|
|
19795
|
+
eventCreatorNickname: event.eventCreatorNickname || ""
|
|
19796
|
+
};
|
|
19797
|
+
}
|
|
19798
|
+
function buildExtReading(link) {
|
|
19799
|
+
if (!link) return {
|
|
19800
|
+
link: "",
|
|
19801
|
+
title: "",
|
|
19802
|
+
urlType: 1
|
|
19803
|
+
};
|
|
19804
|
+
return {
|
|
19805
|
+
link: link.link.replace(/[\s\u200b]/g, ""),
|
|
19806
|
+
title: link.title,
|
|
19807
|
+
urlType: link.urlType ?? 1
|
|
19808
|
+
};
|
|
19809
|
+
}
|
|
19810
|
+
function buildTagInfo(tagInfo, tagKey) {
|
|
19811
|
+
return {
|
|
19812
|
+
...tagInfo,
|
|
19813
|
+
tagKey
|
|
19814
|
+
};
|
|
19815
|
+
}
|
|
19816
|
+
const CHUNK_SIZE = 8388608;
|
|
19817
|
+
const UPLOAD_STAGE_TIMEOUT = 180000;
|
|
19818
|
+
const DEFAULT_TUNING = {
|
|
19819
|
+
metaTimeout: UPLOAD_STAGE_TIMEOUT,
|
|
19820
|
+
partTimeout: UPLOAD_STAGE_TIMEOUT,
|
|
19821
|
+
partRetries: 3,
|
|
19822
|
+
completeTimeout: UPLOAD_STAGE_TIMEOUT
|
|
19823
|
+
};
|
|
19824
|
+
async function uploader_uploadFile(opts) {
|
|
19825
|
+
const { filePath, fileType, uin, authKey, http, logger, tuning } = opts;
|
|
19826
|
+
const stat = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(filePath);
|
|
19827
|
+
const fileSize = stat.size;
|
|
19828
|
+
const fileName = filePath.split(/[\\/]/).pop() || "file";
|
|
19829
|
+
const metaTimeout = tuning?.metaTimeout ?? DEFAULT_TUNING.metaTimeout;
|
|
19830
|
+
const partTimeout = tuning?.partTimeout ?? DEFAULT_TUNING.partTimeout;
|
|
19831
|
+
const partRetries = tuning?.partRetries ?? DEFAULT_TUNING.partRetries;
|
|
19832
|
+
const completeTimeout = tuning?.completeTimeout ?? DEFAULT_TUNING.completeTimeout;
|
|
19833
|
+
logger?.info(`开始上传: ${fileName} (${fileSize} B, filetype=${fileType})`);
|
|
19834
|
+
logger?.info(`上传超时策略: 单片 ${partTimeout / 1000}s(重试 ${partRetries} 次)、合并 ${completeTimeout / 1000}s`);
|
|
19835
|
+
const fileMd5 = await computeFileMd5(filePath);
|
|
19836
|
+
const taskId = generateTaskId(fileName, fileSize, fileMd5);
|
|
19837
|
+
const baseUrl = "https://finderassistancea.video.qq.com";
|
|
19838
|
+
const headers = {
|
|
19839
|
+
Authorization: authKey
|
|
19840
|
+
};
|
|
19841
|
+
const xArgs = `apptype=251&filetype=${fileType}&weixinnum=${uin}&filekey=${encodeURIComponent(fileName)}&filesize=${fileSize}&taskid=${taskId}&scene=2`;
|
|
19842
|
+
const chunkCount = Math.ceil(fileSize / CHUNK_SIZE);
|
|
19843
|
+
const blockPartLength = [];
|
|
19844
|
+
for(let i = 0; i < chunkCount; i++)blockPartLength.push(Math.min((i + 1) * CHUNK_SIZE, fileSize));
|
|
19845
|
+
logger?.info(`申请 UploadID: ${chunkCount} 片`);
|
|
19846
|
+
const applyRes = await http.api({
|
|
19847
|
+
method: "PUT",
|
|
19848
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
19849
|
+
headers: {
|
|
19850
|
+
...headers,
|
|
19851
|
+
"X-Arguments": xArgs
|
|
19852
|
+
},
|
|
19853
|
+
data: {
|
|
19854
|
+
BlockSum: chunkCount,
|
|
19855
|
+
BlockPartLength: blockPartLength
|
|
19856
|
+
}
|
|
19857
|
+
}, {
|
|
19858
|
+
timeout: metaTimeout,
|
|
19859
|
+
retries: 2,
|
|
19860
|
+
retryDelay: 2000
|
|
19861
|
+
});
|
|
19862
|
+
if (!applyRes.UploadID && !applyRes.ListPartsResult) throw new Error("申请 UploadID 失败: " + JSON.stringify(applyRes));
|
|
19863
|
+
let uploadId = applyRes.UploadID;
|
|
19864
|
+
const uploadedParts = new Set();
|
|
19865
|
+
if (applyRes.ListPartsResult) {
|
|
19866
|
+
logger?.info("检测到已上传分片,执行续传");
|
|
19867
|
+
const parts = Array.isArray(applyRes.ListPartsResult.Part) ? applyRes.ListPartsResult.Part : applyRes.ListPartsResult.Part ? [
|
|
19868
|
+
applyRes.ListPartsResult.Part
|
|
19869
|
+
] : [];
|
|
19870
|
+
for (const p of parts)uploadedParts.add(p.PartNumber);
|
|
19871
|
+
const retryRes = await http.api({
|
|
19872
|
+
method: "PUT",
|
|
19873
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
19874
|
+
headers: {
|
|
19875
|
+
...headers,
|
|
19876
|
+
"X-Arguments": xArgs
|
|
19877
|
+
},
|
|
19878
|
+
data: {
|
|
19879
|
+
BlockSum: chunkCount,
|
|
19880
|
+
BlockPartLength: blockPartLength
|
|
19881
|
+
}
|
|
19882
|
+
}, {
|
|
19883
|
+
timeout: metaTimeout,
|
|
19884
|
+
retries: 2,
|
|
19885
|
+
retryDelay: 2000
|
|
19886
|
+
});
|
|
19887
|
+
uploadId = retryRes.UploadID;
|
|
19888
|
+
if (!uploadId) throw new Error("续传获取 UploadID 失败");
|
|
19889
|
+
}
|
|
19890
|
+
const partInfo = [];
|
|
19891
|
+
const fd = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].openSync(filePath, "r");
|
|
19892
|
+
try {
|
|
19893
|
+
for(let i = 0; i < chunkCount; i++){
|
|
19894
|
+
const partNumber = i + 1;
|
|
19895
|
+
if (uploadedParts.has(partNumber)) {
|
|
19896
|
+
const existing = applyRes.ListPartsResult.Part.find((p)=>p.PartNumber === partNumber);
|
|
19897
|
+
if (existing) {
|
|
19898
|
+
partInfo.push({
|
|
19899
|
+
PartNumber: partNumber,
|
|
19900
|
+
ETag: existing.ETag
|
|
19901
|
+
});
|
|
19902
|
+
logger?.info(`分片 ${partNumber}/${chunkCount} 已存在,跳过`);
|
|
19903
|
+
continue;
|
|
19904
|
+
}
|
|
19905
|
+
}
|
|
19906
|
+
const start = i * CHUNK_SIZE;
|
|
19907
|
+
const end = Math.min(start + CHUNK_SIZE, fileSize);
|
|
19908
|
+
const chunkSize = end - start;
|
|
19909
|
+
const chunk = Buffer.alloc(chunkSize);
|
|
19910
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readSync(fd, chunk, 0, chunkSize, start);
|
|
19911
|
+
const chunkMd5 = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5").update(chunk).digest("hex");
|
|
19912
|
+
const partStart = Date.now();
|
|
19913
|
+
await http.api({
|
|
19914
|
+
method: "PUT",
|
|
19915
|
+
url: `${baseUrl}/uploadpartdfs?PartNumber=${partNumber}&UploadID=${encodeURIComponent(uploadId)}`,
|
|
19916
|
+
headers: {
|
|
19917
|
+
...headers,
|
|
19918
|
+
"X-Arguments": xArgs.replace(/scene=2/, "scene=0"),
|
|
19919
|
+
"Content-MD5": chunkMd5
|
|
19920
|
+
},
|
|
19921
|
+
data: chunk
|
|
19922
|
+
}, {
|
|
19923
|
+
timeout: partTimeout,
|
|
19924
|
+
retries: partRetries,
|
|
19925
|
+
retryDelay: 2000
|
|
19926
|
+
});
|
|
19927
|
+
const partElapsed = Date.now() - partStart;
|
|
19928
|
+
const throughput = Math.round(chunkSize / (partElapsed / 1000));
|
|
19929
|
+
partInfo.push({
|
|
19930
|
+
PartNumber: partNumber,
|
|
19931
|
+
ETag: `"${chunkMd5}"`
|
|
19932
|
+
});
|
|
19933
|
+
logger?.info(`分片 ${partNumber}/${chunkCount} 完成 (${chunkSize} B, ${partElapsed}ms, ${Math.round(throughput / 1024)}KB/s)`);
|
|
19934
|
+
}
|
|
19935
|
+
} finally{
|
|
19936
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].closeSync(fd);
|
|
19937
|
+
}
|
|
19938
|
+
logger?.info("合并分片...");
|
|
19939
|
+
const completeRes = await http.api({
|
|
19940
|
+
method: "POST",
|
|
19941
|
+
url: `${baseUrl}/completepartuploaddfs?UploadID=${encodeURIComponent(uploadId)}`,
|
|
19942
|
+
headers: {
|
|
19943
|
+
...headers,
|
|
19944
|
+
"X-Arguments": xArgs
|
|
19945
|
+
},
|
|
19946
|
+
data: {
|
|
19947
|
+
TransFlag: "0_0",
|
|
19948
|
+
PartInfo: partInfo
|
|
19949
|
+
}
|
|
19950
|
+
}, {
|
|
19951
|
+
timeout: completeTimeout,
|
|
19952
|
+
retries: 1,
|
|
19953
|
+
retryDelay: 3000
|
|
19954
|
+
});
|
|
19955
|
+
if (!completeRes.DownloadURL) throw new Error("合并分片失败: " + JSON.stringify(completeRes));
|
|
19956
|
+
logger?.info("上传成功");
|
|
19957
|
+
return {
|
|
19958
|
+
downloadUrl: completeRes.DownloadURL,
|
|
19959
|
+
md5: fileMd5,
|
|
19960
|
+
fileSize
|
|
19961
|
+
};
|
|
19962
|
+
}
|
|
19963
|
+
async function computeFileMd5(filePath) {
|
|
19964
|
+
return new Promise((resolve, reject)=>{
|
|
19965
|
+
const hash = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5");
|
|
19966
|
+
const stream = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].createReadStream(filePath);
|
|
19967
|
+
stream.on("data", (chunk)=>hash.update(chunk));
|
|
19968
|
+
stream.on("end", ()=>resolve(hash.digest("hex")));
|
|
19969
|
+
stream.on("error", reject);
|
|
19970
|
+
});
|
|
19971
|
+
}
|
|
19972
|
+
function generateTaskId(fileName, fileSize, fileMd5) {
|
|
19973
|
+
const input = `${fileName}-${fileSize}-${fileMd5}`;
|
|
19974
|
+
return __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5").update(input).digest("hex").slice(0, 32);
|
|
19975
|
+
}
|
|
19976
|
+
const MAX_METADATA_BOX_SIZE = 268435456;
|
|
19977
|
+
function readBoxHeader(fd, offset, limit) {
|
|
19978
|
+
if (offset + 8 > limit) return null;
|
|
19979
|
+
const head = Buffer.alloc(16);
|
|
19980
|
+
const read = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readSync(fd, head, 0, 16, offset);
|
|
19981
|
+
if (read < 8) return null;
|
|
19982
|
+
let size = head.readUInt32BE(0);
|
|
19983
|
+
const type = head.toString("latin1", 4, 8);
|
|
19984
|
+
let headerSize = 8;
|
|
19985
|
+
if (1 === size) {
|
|
19986
|
+
if (read < 16) return null;
|
|
19987
|
+
size = head.readUInt32BE(8) * 2 ** 32 + head.readUInt32BE(12);
|
|
19988
|
+
headerSize = 16;
|
|
19989
|
+
} else if (0 === size) size = limit - offset;
|
|
19990
|
+
if (size < headerSize || offset + size > limit) return null;
|
|
19991
|
+
return {
|
|
19992
|
+
type,
|
|
19993
|
+
size,
|
|
19994
|
+
headerSize
|
|
19995
|
+
};
|
|
19996
|
+
}
|
|
19997
|
+
function parseVideoMeta(filePath) {
|
|
19998
|
+
let fd;
|
|
19999
|
+
let fileSize;
|
|
20000
|
+
try {
|
|
20001
|
+
fd = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].openSync(filePath, "r");
|
|
20002
|
+
} catch {
|
|
20003
|
+
return null;
|
|
20004
|
+
}
|
|
20005
|
+
try {
|
|
20006
|
+
fileSize = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].fstatSync(fd).size;
|
|
20007
|
+
const state = {
|
|
20008
|
+
movie: null,
|
|
20009
|
+
tracks: [],
|
|
20010
|
+
trexDefaults: new Map(),
|
|
20011
|
+
fragmentDurations: new Map(),
|
|
20012
|
+
trafTrackId: 0,
|
|
20013
|
+
trafDefaultSampleDuration: 0
|
|
20014
|
+
};
|
|
20015
|
+
let offset = 0;
|
|
20016
|
+
while(offset + 8 <= fileSize){
|
|
20017
|
+
const header = readBoxHeader(fd, offset, fileSize);
|
|
20018
|
+
if (!header) break;
|
|
20019
|
+
if ("moov" === header.type || "moof" === header.type) {
|
|
20020
|
+
const bodyLength = header.size - header.headerSize;
|
|
20021
|
+
if (bodyLength > 0 && bodyLength <= MAX_METADATA_BOX_SIZE) {
|
|
20022
|
+
const body = Buffer.alloc(bodyLength);
|
|
20023
|
+
const read = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readSync(fd, body, 0, bodyLength, offset + header.headerSize);
|
|
20024
|
+
state.trafTrackId = 0;
|
|
20025
|
+
state.trafDefaultSampleDuration = 0;
|
|
20026
|
+
walkBoxes(body.subarray(0, read), 0, read, state);
|
|
20027
|
+
}
|
|
20028
|
+
}
|
|
20029
|
+
offset += header.size;
|
|
20030
|
+
}
|
|
20031
|
+
const { movie, tracks } = state;
|
|
20032
|
+
const video = tracks.find((t)=>"vide" === t.handler) || tracks.find((t)=>t.width > 0 && t.height > 0);
|
|
20033
|
+
if (!video) return null;
|
|
20034
|
+
let { width, height } = video;
|
|
20035
|
+
if (90 === video.rotation || 270 === video.rotation) [width, height] = [
|
|
20036
|
+
height,
|
|
20037
|
+
width
|
|
20038
|
+
];
|
|
20039
|
+
return {
|
|
20040
|
+
width: Math.round(width),
|
|
20041
|
+
height: Math.round(height),
|
|
20042
|
+
duration: resolveDuration(movie, video, state.fragmentDurations),
|
|
20043
|
+
rotation: video.rotation,
|
|
20044
|
+
fileSize,
|
|
20045
|
+
codec: video.codec
|
|
20046
|
+
};
|
|
20047
|
+
} catch {
|
|
20048
|
+
return null;
|
|
20049
|
+
} finally{
|
|
20050
|
+
try {
|
|
20051
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].closeSync(fd);
|
|
20052
|
+
} catch {}
|
|
20053
|
+
}
|
|
20054
|
+
}
|
|
20055
|
+
function walkBoxes(buf, start, end, state) {
|
|
20056
|
+
let off = start;
|
|
20057
|
+
while(off + 8 <= end){
|
|
20058
|
+
let size = buf.readUInt32BE(off);
|
|
20059
|
+
const type = buf.toString("latin1", off + 4, off + 8);
|
|
20060
|
+
let headerSize = 8;
|
|
20061
|
+
if (1 === size) {
|
|
20062
|
+
if (off + 16 > end) break;
|
|
20063
|
+
const hi = buf.readUInt32BE(off + 8);
|
|
20064
|
+
const lo = buf.readUInt32BE(off + 12);
|
|
20065
|
+
size = hi * 2 ** 32 + lo;
|
|
20066
|
+
headerSize = 16;
|
|
20067
|
+
} else if (0 === size) size = end - off;
|
|
20068
|
+
if (size < headerSize || off + size > end) break;
|
|
20069
|
+
const bodyStart = off + headerSize;
|
|
20070
|
+
const bodyEnd = off + size;
|
|
20071
|
+
switch(type){
|
|
20072
|
+
case "trak":
|
|
20073
|
+
case "mdia":
|
|
20074
|
+
case "minf":
|
|
20075
|
+
case "stbl":
|
|
20076
|
+
case "mvex":
|
|
20077
|
+
case "traf":
|
|
20078
|
+
walkBoxes(buf, bodyStart, bodyEnd, state);
|
|
20079
|
+
break;
|
|
20080
|
+
case "mvhd":
|
|
20081
|
+
state.movie = parseMvhd(buf, bodyStart, bodyEnd);
|
|
20082
|
+
break;
|
|
20083
|
+
case "tkhd":
|
|
20084
|
+
state.tracks.push({
|
|
20085
|
+
...parseTkhd(buf, bodyStart, bodyEnd),
|
|
20086
|
+
handler: null,
|
|
20087
|
+
codec: null,
|
|
20088
|
+
timescale: 0,
|
|
20089
|
+
mdhdDuration: 0,
|
|
20090
|
+
sttsDuration: 0
|
|
20091
|
+
});
|
|
20092
|
+
break;
|
|
20093
|
+
case "mdhd":
|
|
20094
|
+
{
|
|
20095
|
+
const mdhd = parseMvhd(buf, bodyStart, bodyEnd);
|
|
20096
|
+
if (mdhd && state.tracks.length) {
|
|
20097
|
+
const track = state.tracks[state.tracks.length - 1];
|
|
20098
|
+
track.timescale = mdhd.timescale;
|
|
20099
|
+
track.mdhdDuration = mdhd.duration;
|
|
20100
|
+
}
|
|
20101
|
+
break;
|
|
20102
|
+
}
|
|
20103
|
+
case "hdlr":
|
|
20104
|
+
if (bodyEnd - bodyStart >= 12 && state.tracks.length) state.tracks[state.tracks.length - 1].handler = buf.toString("latin1", bodyStart + 8, bodyStart + 12);
|
|
20105
|
+
break;
|
|
20106
|
+
case "stsd":
|
|
20107
|
+
{
|
|
20108
|
+
const codec = parseStsdCodec(buf, bodyStart, bodyEnd);
|
|
20109
|
+
if (codec && state.tracks.length) state.tracks[state.tracks.length - 1].codec = codec;
|
|
20110
|
+
break;
|
|
20111
|
+
}
|
|
20112
|
+
case "stts":
|
|
20113
|
+
if (state.tracks.length) state.tracks[state.tracks.length - 1].sttsDuration = parseSttsDuration(buf, bodyStart, bodyEnd);
|
|
20114
|
+
break;
|
|
20115
|
+
case "trex":
|
|
20116
|
+
if (bodyStart + 20 > bodyEnd) break;
|
|
20117
|
+
state.trexDefaults.set(buf.readUInt32BE(bodyStart + 4), buf.readUInt32BE(bodyStart + 12));
|
|
20118
|
+
break;
|
|
20119
|
+
case "tfhd":
|
|
20120
|
+
{
|
|
20121
|
+
const tfhd = parseTfhd(buf, bodyStart, bodyEnd);
|
|
20122
|
+
state.trafTrackId = tfhd.trackId;
|
|
20123
|
+
state.trafDefaultSampleDuration = tfhd.defaultSampleDuration || state.trexDefaults.get(tfhd.trackId) || 0;
|
|
20124
|
+
break;
|
|
20125
|
+
}
|
|
20126
|
+
case "trun":
|
|
20127
|
+
{
|
|
20128
|
+
const duration = parseTrunDuration(buf, bodyStart, bodyEnd, state.trafDefaultSampleDuration);
|
|
20129
|
+
state.fragmentDurations.set(state.trafTrackId, (state.fragmentDurations.get(state.trafTrackId) || 0) + duration);
|
|
20130
|
+
break;
|
|
20131
|
+
}
|
|
20132
|
+
}
|
|
20133
|
+
off += size;
|
|
20134
|
+
}
|
|
20135
|
+
}
|
|
20136
|
+
const UNKNOWN_DURATION_32 = 0xffffffff;
|
|
20137
|
+
function isUsableDuration(duration) {
|
|
20138
|
+
return duration > 0 && duration !== UNKNOWN_DURATION_32;
|
|
20139
|
+
}
|
|
20140
|
+
function resolveDuration(movie, video, fragmentDurations) {
|
|
20141
|
+
if (movie && movie.timescale && isUsableDuration(movie.duration)) return movie.duration / movie.timescale;
|
|
20142
|
+
if (video.timescale) {
|
|
20143
|
+
if (isUsableDuration(video.mdhdDuration)) return video.mdhdDuration / video.timescale;
|
|
20144
|
+
if (video.sttsDuration > 0) return video.sttsDuration / video.timescale;
|
|
20145
|
+
const fragment = fragmentDurations.get(video.trackId) ?? (1 === fragmentDurations.size ? [
|
|
20146
|
+
...fragmentDurations.values()
|
|
20147
|
+
][0] : 0);
|
|
20148
|
+
if (fragment > 0) return fragment / video.timescale;
|
|
20149
|
+
}
|
|
20150
|
+
return 0;
|
|
20151
|
+
}
|
|
20152
|
+
function parseSttsDuration(buf, start, end) {
|
|
20153
|
+
if (start + 8 > end) return 0;
|
|
20154
|
+
const entryCount = buf.readUInt32BE(start + 4);
|
|
20155
|
+
let total = 0;
|
|
20156
|
+
for(let i = 0; i < entryCount; i++){
|
|
20157
|
+
const off = start + 8 + 8 * i;
|
|
20158
|
+
if (off + 8 > end) break;
|
|
20159
|
+
total += buf.readUInt32BE(off) * buf.readUInt32BE(off + 4);
|
|
20160
|
+
}
|
|
20161
|
+
return total;
|
|
20162
|
+
}
|
|
20163
|
+
function parseTfhd(buf, start, end) {
|
|
20164
|
+
if (start + 8 > end) return {
|
|
20165
|
+
trackId: 0,
|
|
20166
|
+
defaultSampleDuration: 0
|
|
20167
|
+
};
|
|
20168
|
+
const flags = buf.readUIntBE(start + 1, 3);
|
|
20169
|
+
const trackId = buf.readUInt32BE(start + 4);
|
|
20170
|
+
let off = start + 8;
|
|
20171
|
+
if (0x000001 & flags) off += 8;
|
|
20172
|
+
if (0x000002 & flags) off += 4;
|
|
20173
|
+
if (0x000008 & flags && off + 4 <= end) return {
|
|
20174
|
+
trackId,
|
|
20175
|
+
defaultSampleDuration: buf.readUInt32BE(off)
|
|
20176
|
+
};
|
|
20177
|
+
return {
|
|
20178
|
+
trackId,
|
|
20179
|
+
defaultSampleDuration: 0
|
|
20180
|
+
};
|
|
20181
|
+
}
|
|
20182
|
+
function parseTrunDuration(buf, start, end, defaultSampleDuration) {
|
|
20183
|
+
if (start + 8 > end) return 0;
|
|
20184
|
+
const flags = buf.readUIntBE(start + 1, 3);
|
|
20185
|
+
const sampleCount = buf.readUInt32BE(start + 4);
|
|
20186
|
+
let off = start + 8;
|
|
20187
|
+
if (0x000001 & flags) off += 4;
|
|
20188
|
+
if (0x000004 & flags) off += 4;
|
|
20189
|
+
const hasDuration = (0x000100 & flags) !== 0;
|
|
20190
|
+
if (!hasDuration) return sampleCount * defaultSampleDuration;
|
|
20191
|
+
const entrySize = 4 + ((0x000200 & flags) !== 0 ? 4 : 0) + ((0x000400 & flags) !== 0 ? 4 : 0) + ((0x000800 & flags) !== 0 ? 4 : 0);
|
|
20192
|
+
let total = 0;
|
|
20193
|
+
for(let i = 0; i < sampleCount; i++){
|
|
20194
|
+
const entryOff = off + i * entrySize;
|
|
20195
|
+
if (entryOff + 4 > end) break;
|
|
20196
|
+
total += buf.readUInt32BE(entryOff);
|
|
20197
|
+
}
|
|
20198
|
+
return total;
|
|
20199
|
+
}
|
|
20200
|
+
function parseStsdCodec(buf, start, end) {
|
|
20201
|
+
if (start + 16 > end) return null;
|
|
20202
|
+
if (0 === buf.readUInt32BE(start + 4)) return null;
|
|
20203
|
+
return buf.toString("latin1", start + 12, start + 16).toLowerCase();
|
|
20204
|
+
}
|
|
20205
|
+
function parseMvhd(buf, start, end) {
|
|
20206
|
+
const version = buf.readUInt8(start);
|
|
20207
|
+
if (1 === version) {
|
|
20208
|
+
if (start + 28 > end) return null;
|
|
20209
|
+
const timescale = buf.readUInt32BE(start + 20);
|
|
20210
|
+
const hi = buf.readUInt32BE(start + 24);
|
|
20211
|
+
const lo = buf.readUInt32BE(start + 28);
|
|
20212
|
+
return {
|
|
20213
|
+
timescale,
|
|
20214
|
+
duration: hi * 2 ** 32 + lo
|
|
20215
|
+
};
|
|
20216
|
+
}
|
|
20217
|
+
if (start + 20 > end) return null;
|
|
20218
|
+
return {
|
|
20219
|
+
timescale: buf.readUInt32BE(start + 12),
|
|
20220
|
+
duration: buf.readUInt32BE(start + 16)
|
|
20221
|
+
};
|
|
20222
|
+
}
|
|
20223
|
+
function parseTkhd(buf, start, end) {
|
|
20224
|
+
const version = buf.readUInt8(start);
|
|
20225
|
+
const afterDuration = 1 === version ? 36 : 24;
|
|
20226
|
+
const matrixOff = start + afterDuration + 16;
|
|
20227
|
+
const whOff = matrixOff + 36;
|
|
20228
|
+
const trackIdOff = start + (1 === version ? 20 : 12);
|
|
20229
|
+
const trackId = trackIdOff + 4 <= end ? buf.readUInt32BE(trackIdOff) : 0;
|
|
20230
|
+
if (whOff + 8 > end) return {
|
|
20231
|
+
trackId,
|
|
20232
|
+
width: 0,
|
|
20233
|
+
height: 0,
|
|
20234
|
+
rotation: 0
|
|
20235
|
+
};
|
|
20236
|
+
const width = buf.readUInt32BE(whOff) / 65536;
|
|
20237
|
+
const height = buf.readUInt32BE(whOff + 4) / 65536;
|
|
20238
|
+
const a = buf.readInt32BE(matrixOff) / 65536;
|
|
20239
|
+
const b = buf.readInt32BE(matrixOff + 4) / 65536;
|
|
20240
|
+
let rotation = 0;
|
|
20241
|
+
if (Math.abs(a) < 0.01 && Math.abs(b - 1) < 0.01) rotation = 90;
|
|
20242
|
+
else if (Math.abs(a + 1) < 0.01 && Math.abs(b) < 0.01) rotation = 180;
|
|
20243
|
+
else if (Math.abs(a) < 0.01 && Math.abs(b + 1) < 0.01) rotation = 270;
|
|
20244
|
+
return {
|
|
20245
|
+
trackId,
|
|
20246
|
+
width,
|
|
20247
|
+
height,
|
|
20248
|
+
rotation
|
|
20249
|
+
};
|
|
20250
|
+
}
|
|
20251
|
+
function parseVideoCodec(filePath) {
|
|
20252
|
+
return parseVideoMeta(filePath)?.codec ?? null;
|
|
20253
|
+
}
|
|
20254
|
+
function buildVideoMetaFromParams(filePath, metadata) {
|
|
20255
|
+
return {
|
|
20256
|
+
width: Math.round(metadata.width),
|
|
20257
|
+
height: Math.round(metadata.height),
|
|
20258
|
+
duration: metadata.duration,
|
|
20259
|
+
rotation: 0,
|
|
20260
|
+
fileSize: metadata.fileSize,
|
|
20261
|
+
codec: parseVideoCodec(filePath)
|
|
20262
|
+
};
|
|
20263
|
+
}
|
|
20264
|
+
const MAX_DURATION_SECONDS = 28800;
|
|
20265
|
+
const MAX_FILE_SIZE = 21474836480;
|
|
20266
|
+
const ALLOWED_EXTENSIONS = [
|
|
20267
|
+
".mp4"
|
|
20268
|
+
];
|
|
20269
|
+
const ALLOWED_CODECS = [
|
|
20270
|
+
"avc1",
|
|
20271
|
+
"avc3"
|
|
20272
|
+
];
|
|
20273
|
+
const MIN_TITLE_LENGTH = 6;
|
|
20274
|
+
function formatFileSize(bytes) {
|
|
20275
|
+
if (bytes < 1048576) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
20276
|
+
if (bytes < 1073741824) return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
20277
|
+
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
20278
|
+
}
|
|
20279
|
+
function formatDuration(seconds) {
|
|
20280
|
+
const total = Math.round(seconds);
|
|
20281
|
+
const h = Math.floor(total / 3600);
|
|
20282
|
+
const m = Math.floor(total % 3600 / 60);
|
|
20283
|
+
const s = total % 60;
|
|
20284
|
+
if (h > 0) return `${h}小时${m}分${s}秒`;
|
|
20285
|
+
if (m > 0) return `${m}分${s}秒`;
|
|
20286
|
+
return `${s}秒`;
|
|
20287
|
+
}
|
|
20288
|
+
function validateShipinhaoVideo(filePath, meta) {
|
|
20289
|
+
const fileName = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(filePath);
|
|
20290
|
+
const ext = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(fileName).toLowerCase();
|
|
20291
|
+
if (!ALLOWED_EXTENSIONS.includes(ext)) return `视频格式不支持:${fileName}。视频号仅支持 MP4/H.264 格式,请转换后重试。`;
|
|
20292
|
+
if (meta.duration > MAX_DURATION_SECONDS) return `视频时长超过限制:${fileName}(${formatDuration(meta.duration)})。视频号视频时长不能超过 8 小时,请剪辑后重试。`;
|
|
20293
|
+
if (meta.fileSize > MAX_FILE_SIZE) return `视频大小超过限制:${fileName}(${formatFileSize(meta.fileSize)})。视频号视频不能超过 20GB,请压缩后重试。`;
|
|
20294
|
+
if (meta.codec && !ALLOWED_CODECS.includes(meta.codec)) return `视频编码不支持:${fileName}(${meta.codec})。视频号仅支持 H.264 编码,请转码后重试。`;
|
|
20295
|
+
return null;
|
|
20296
|
+
}
|
|
20297
|
+
function validateShipinhaoTitle(title) {
|
|
20298
|
+
if (void 0 === title) return null;
|
|
20299
|
+
const trimmed = title.trim();
|
|
20300
|
+
const length = [
|
|
20301
|
+
...trimmed
|
|
20302
|
+
].length;
|
|
20303
|
+
if (length < MIN_TITLE_LENGTH) return `视频号标题至少需要 ${MIN_TITLE_LENGTH} 个字符,请补充后重试。`;
|
|
20304
|
+
return null;
|
|
20305
|
+
}
|
|
20306
|
+
const POST_CREATE_PAGE_URL = "https://channels.weixin.qq.com/micro/content/post/create";
|
|
20307
|
+
const MICRO_CONTENT_BASE = "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin";
|
|
20308
|
+
function resolveClientContext(params, fallbackUin) {
|
|
20309
|
+
const extra = params.extraParam || {};
|
|
20310
|
+
const deviceIdCookie = params.cookies.find((c)=>"device_id" === c.name || "finger_print_device_id" === c.name)?.value;
|
|
20311
|
+
return {
|
|
20312
|
+
aId: "string" == typeof extra.aId ? extra.aId : "",
|
|
20313
|
+
fingerPrintDeviceId: "string" == typeof extra.fingerPrintDeviceId ? extra.fingerPrintDeviceId : deviceIdCookie || "",
|
|
20314
|
+
uin: "string" == typeof extra.uin ? extra.uin : String(fallbackUin)
|
|
20315
|
+
};
|
|
20316
|
+
}
|
|
20317
|
+
function buildPublishHeaders(cookieString, client) {
|
|
20318
|
+
const headers = {
|
|
20319
|
+
cookie: cookieString,
|
|
20320
|
+
referer: POST_CREATE_PAGE_URL,
|
|
20321
|
+
origin: "https://channels.weixin.qq.com",
|
|
20322
|
+
"content-type": "application/json"
|
|
20323
|
+
};
|
|
20324
|
+
if (client.fingerPrintDeviceId) headers["finger-print-device-id"] = client.fingerPrintDeviceId;
|
|
20325
|
+
if (client.uin) headers["x-wechat-uin"] = client.uin;
|
|
20326
|
+
return headers;
|
|
20327
|
+
}
|
|
20328
|
+
function buildPublishQuery(client) {
|
|
20329
|
+
const query = {
|
|
20330
|
+
_rid: rid(),
|
|
20331
|
+
_pageUrl: POST_CREATE_PAGE_URL
|
|
20332
|
+
};
|
|
20333
|
+
if (client.aId) query._aid = client.aId;
|
|
20334
|
+
return query;
|
|
20335
|
+
}
|
|
20336
|
+
function buildCommonBody(finderUsername) {
|
|
20337
|
+
return {
|
|
20338
|
+
timestamp: String(Date.now()),
|
|
20339
|
+
_log_finder_uin: "",
|
|
20340
|
+
_log_finder_id: finderUsername,
|
|
20341
|
+
rawKeyBuff: "",
|
|
20342
|
+
pluginSessionId: null,
|
|
20343
|
+
scene: 7,
|
|
20344
|
+
reqScene: 7
|
|
20345
|
+
};
|
|
20346
|
+
}
|
|
20347
|
+
async function getTraceKey(auth, client, http, logger) {
|
|
20348
|
+
logger.info("[getTraceKey] 开始获取 traceKey...");
|
|
20349
|
+
const res = await http.api({
|
|
20350
|
+
method: "POST",
|
|
20351
|
+
url: `${MICRO_CONTENT_BASE}/post/get-finder-post-trace-key`,
|
|
20352
|
+
params: buildPublishQuery(client),
|
|
20353
|
+
data: {
|
|
20354
|
+
objectId: "",
|
|
20355
|
+
...buildCommonBody(auth.finderUsername)
|
|
20356
|
+
},
|
|
20357
|
+
defaultErrorMsg: "获取 traceKey 失败"
|
|
20358
|
+
});
|
|
20359
|
+
if (0 !== res.errCode || !res.data?.traceKey) {
|
|
20360
|
+
logger.error("[getTraceKey] 获取失败:", JSON.stringify(res));
|
|
20361
|
+
throw new Error(`获取 traceKey 失败: ${JSON.stringify(res)}`);
|
|
20362
|
+
}
|
|
20363
|
+
logger.info(`[getTraceKey] 获取成功: ${res.data.traceKey}`);
|
|
20364
|
+
return res.data.traceKey;
|
|
20365
|
+
}
|
|
20366
|
+
async function getObjectTagKey(auth, client, http, logger) {
|
|
20367
|
+
logger.info("[getObjectTagKey] 获取内容声明 tagKey...");
|
|
20368
|
+
try {
|
|
20369
|
+
const res = await http.api({
|
|
20370
|
+
method: "POST",
|
|
20371
|
+
url: `${MICRO_CONTENT_BASE}/post/finder_get_object_tag_list`,
|
|
20372
|
+
params: buildPublishQuery(client),
|
|
20373
|
+
data: {
|
|
20374
|
+
source: 1,
|
|
20375
|
+
...buildCommonBody(auth.finderUsername)
|
|
20376
|
+
},
|
|
20377
|
+
defaultErrorMsg: "获取内容声明标注失败"
|
|
20378
|
+
});
|
|
20379
|
+
if (0 !== res.errCode || !res.data?.tagKey) {
|
|
20380
|
+
logger.warn(`[getObjectTagKey] 未取到 tagKey: ${JSON.stringify(res)}`);
|
|
20381
|
+
return null;
|
|
20382
|
+
}
|
|
20383
|
+
logger.info(`[getObjectTagKey] tagKey: ${res.data.tagKey}`);
|
|
20384
|
+
return res.data.tagKey;
|
|
20385
|
+
} catch (error) {
|
|
20386
|
+
logger.warn(`[getObjectTagKey] 获取 tagKey 异常: ${stringifyError(error)}`);
|
|
20387
|
+
return null;
|
|
20388
|
+
}
|
|
20389
|
+
}
|
|
20390
|
+
async function submitAndPollTranscode(opts) {
|
|
20391
|
+
const { videoUrl, videoMeta, traceKey, uploadStartTime, uploadEndTime, finderUsername, client, http, logger } = opts;
|
|
20392
|
+
logger.info("[submitAndPollTranscode] 开始提交转码任务...");
|
|
20393
|
+
const finderUrl = videoUrl.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${videoUrl.split("qq.com")[1]}` : videoUrl;
|
|
20394
|
+
logger.info(`[submitAndPollTranscode] 视频尺寸: ${videoMeta.width}x${videoMeta.height}, 时长: ${videoMeta.duration}s`);
|
|
20395
|
+
const submitRes = await http.api({
|
|
20396
|
+
method: "POST",
|
|
20397
|
+
url: `${MICRO_CONTENT_BASE}/post/post_clip_video`,
|
|
20398
|
+
params: buildPublishQuery(client),
|
|
20399
|
+
data: {
|
|
20400
|
+
url: finderUrl,
|
|
20401
|
+
timeStart: 0,
|
|
20402
|
+
cropDuration: 0,
|
|
20403
|
+
height: videoMeta.height,
|
|
20404
|
+
width: videoMeta.width,
|
|
20405
|
+
x: 0,
|
|
20406
|
+
y: 0,
|
|
20407
|
+
clipOriginVideoInfo: {
|
|
20408
|
+
width: videoMeta.width,
|
|
20409
|
+
height: videoMeta.height,
|
|
20410
|
+
duration: videoMeta.duration,
|
|
20411
|
+
fileSize: videoMeta.fileSize
|
|
20412
|
+
},
|
|
20413
|
+
traceInfo: {
|
|
20414
|
+
traceKey,
|
|
20415
|
+
uploadCdnStart: uploadStartTime,
|
|
20416
|
+
uploadCdnEnd: uploadEndTime
|
|
20417
|
+
},
|
|
20418
|
+
targetWidth: videoMeta.width,
|
|
20419
|
+
targetHeight: videoMeta.height,
|
|
20420
|
+
type: 4,
|
|
20421
|
+
useAstraThumbCover: 1,
|
|
20422
|
+
...buildCommonBody(finderUsername)
|
|
20423
|
+
},
|
|
20424
|
+
defaultErrorMsg: "提交转码失败"
|
|
20425
|
+
});
|
|
20426
|
+
if (0 !== submitRes.errCode || !submitRes.data?.clipKey) {
|
|
20427
|
+
logger.error("[submitAndPollTranscode] 提交转码失败:", JSON.stringify(submitRes));
|
|
20428
|
+
throw new Error(`提交转码失败: ${JSON.stringify(submitRes)}`);
|
|
20429
|
+
}
|
|
20430
|
+
const { clipKey, draftId } = submitRes.data;
|
|
20431
|
+
logger.info(`[submitAndPollTranscode] 转码任务已提交,clipKey: ${clipKey}, draftId: ${draftId}`);
|
|
20432
|
+
const pollInterval = 5000;
|
|
20433
|
+
const pollBudget = Math.min(1800000, 300000 + 1000 * Math.ceil(1.5 * videoMeta.duration));
|
|
20434
|
+
const maxPolls = Math.ceil(pollBudget / pollInterval);
|
|
20435
|
+
let pollCount = 0;
|
|
20436
|
+
logger.info(`[submitAndPollTranscode] 开始轮询转码结果,最多 ${maxPolls} 次(${Math.round(pollBudget / 1000)}s),间隔 ${pollInterval / 1000}s`);
|
|
20437
|
+
while(pollCount < maxPolls){
|
|
20438
|
+
await sleep(pollInterval);
|
|
20439
|
+
pollCount++;
|
|
20440
|
+
const pollRes = await http.api({
|
|
20441
|
+
method: "POST",
|
|
20442
|
+
url: `${MICRO_CONTENT_BASE}/post/post_clip_video_result`,
|
|
20443
|
+
params: buildPublishQuery(client),
|
|
20444
|
+
data: {
|
|
20445
|
+
clipKey,
|
|
20446
|
+
draftId,
|
|
20447
|
+
...buildCommonBody(finderUsername)
|
|
20448
|
+
},
|
|
20449
|
+
defaultErrorMsg: "转码轮询失败"
|
|
20450
|
+
}, {
|
|
20451
|
+
timeout: 60000,
|
|
20452
|
+
retries: 2,
|
|
20453
|
+
retryDelay: 3000
|
|
20454
|
+
});
|
|
20455
|
+
if (0 !== pollRes.errCode) {
|
|
20456
|
+
logger.error(`[submitAndPollTranscode] 转码轮询失败 (poll ${pollCount}):`, JSON.stringify(pollRes));
|
|
20457
|
+
throw new Error(`转码轮询失败 (poll ${pollCount}): ${JSON.stringify(pollRes)}`);
|
|
20458
|
+
}
|
|
20459
|
+
const { flag, url, width, height, duration, md5, fileSize } = pollRes.data || {};
|
|
20460
|
+
logger.info(`[submitAndPollTranscode] 轮询第 ${pollCount} 次,flag=${flag}`);
|
|
20461
|
+
if (1 === flag) {
|
|
20462
|
+
if (!url || !width || !height || !duration || !md5 || !fileSize) {
|
|
20463
|
+
logger.error("[submitAndPollTranscode] 转码完成但返回数据不完整:", JSON.stringify(pollRes.data));
|
|
20464
|
+
throw new Error(`转码完成但返回数据不完整: ${JSON.stringify(pollRes.data)}`);
|
|
20465
|
+
}
|
|
20466
|
+
logger.info(`[submitAndPollTranscode] 转码完成! 用时: ${pollCount * pollInterval / 1000}s`);
|
|
20467
|
+
logger.info(`[submitAndPollTranscode] 视频信息: ${width}x${height}, 时长: ${duration}s, 大小: ${fileSize}`);
|
|
20468
|
+
return {
|
|
20469
|
+
clipKey,
|
|
20470
|
+
url,
|
|
20471
|
+
width,
|
|
20472
|
+
height,
|
|
20473
|
+
duration,
|
|
20474
|
+
md5,
|
|
20475
|
+
fileSize
|
|
20476
|
+
};
|
|
20477
|
+
}
|
|
20478
|
+
if (2 === flag) logger.info(`[submitAndPollTranscode] 转码中... (${pollCount}/${maxPolls})`);
|
|
20479
|
+
else {
|
|
20480
|
+
logger.error(`[submitAndPollTranscode] 转码失败,未知 flag=${flag}:`, JSON.stringify(pollRes.data));
|
|
20481
|
+
throw new Error(`转码失败,未知 flag=${flag}: ${JSON.stringify(pollRes.data)}`);
|
|
20482
|
+
}
|
|
20483
|
+
}
|
|
20484
|
+
logger.error(`[submitAndPollTranscode] 转码超时,已轮询 ${maxPolls} 次,用时: ${maxPolls * pollInterval / 1000}s`);
|
|
20485
|
+
throw new Error(`转码超时 (${maxPolls * pollInterval / 1000}s)`);
|
|
20486
|
+
}
|
|
20487
|
+
async function publishVideo(opts) {
|
|
20488
|
+
const { params, auth, client, clipResult, videoUpload, coverUpload, verticalCoverUpload, videoMeta, traceKey, tagKey, uploadStartTime, uploadEndTime, proxyHttp, logger } = opts;
|
|
20489
|
+
logger.info("[publishVideo] 开始构建发布请求...");
|
|
20490
|
+
const toFinderUrl = (url)=>url.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${url.split("qq.com")[1]}` : url;
|
|
20491
|
+
const thumbFinderUrl = toFinderUrl(coverUpload.downloadUrl);
|
|
20492
|
+
const coverFinderUrl = toFinderUrl(verticalCoverUpload.downloadUrl);
|
|
20493
|
+
const md5sumUuid = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].randomUUID();
|
|
20494
|
+
const description = params.description;
|
|
20495
|
+
logger.info("[publishVideo] 发布参数:");
|
|
20496
|
+
logger.info(` - 短标题: ${params.title || "(无)"}`);
|
|
20497
|
+
logger.info(` - 描述: ${description.substring(0, 50)}${description.length > 50 ? "..." : ""}`);
|
|
20498
|
+
logger.info(` - 定时发布: ${params.scheduledTime ? new Date(1000 * params.scheduledTime).toLocaleString() : "立即发布"}`);
|
|
20499
|
+
const objectDesc = {
|
|
20500
|
+
mpTitle: "",
|
|
20501
|
+
description,
|
|
20502
|
+
extReading: buildExtReading(params.link),
|
|
20503
|
+
mediaType: 4,
|
|
20504
|
+
location: payload_buildLocation(params.location),
|
|
20505
|
+
topic: buildTopic({
|
|
20506
|
+
description: params.description,
|
|
20507
|
+
topics: params.topics,
|
|
20508
|
+
mentionedUsers: params.mentionedUsers,
|
|
20509
|
+
collection: params.collection
|
|
20510
|
+
}),
|
|
20511
|
+
event: buildEvent(params.event),
|
|
20512
|
+
mentionedUser: buildMentionedUser(params.mentionedUsers),
|
|
20513
|
+
media: [
|
|
20514
|
+
{
|
|
20515
|
+
url: clipResult.url,
|
|
20516
|
+
fileSize: clipResult.fileSize,
|
|
20517
|
+
thumbUrl: thumbFinderUrl,
|
|
20518
|
+
fullThumbUrl: thumbFinderUrl,
|
|
20519
|
+
coverUrl: coverFinderUrl,
|
|
20520
|
+
fullCoverUrl: coverFinderUrl,
|
|
20521
|
+
shareCoverUrl: coverFinderUrl,
|
|
20522
|
+
mediaType: 4,
|
|
20523
|
+
videoPlayLen: Math.round(clipResult.duration),
|
|
20524
|
+
width: clipResult.width,
|
|
20525
|
+
height: clipResult.height,
|
|
20526
|
+
md5sum: md5sumUuid,
|
|
20527
|
+
cardShowStyle: 2,
|
|
20528
|
+
urlCdnTaskId: clipResult.clipKey
|
|
20529
|
+
}
|
|
20530
|
+
],
|
|
20531
|
+
shortTitle: params.title ? [
|
|
20532
|
+
{
|
|
20533
|
+
shortTitle: params.title
|
|
20534
|
+
}
|
|
20535
|
+
] : [],
|
|
20536
|
+
member: {}
|
|
20537
|
+
};
|
|
20538
|
+
const publishData = {
|
|
20539
|
+
objectType: 0,
|
|
20540
|
+
longitude: 0,
|
|
20541
|
+
latitude: 0,
|
|
20542
|
+
feedLongitude: 0,
|
|
20543
|
+
feedLatitude: 0,
|
|
20544
|
+
originalFlag: params.originalFlag ?? 0,
|
|
20545
|
+
topics: params.topics || [],
|
|
20546
|
+
isFullPost: 1,
|
|
20547
|
+
handleFlag: 2,
|
|
20548
|
+
videoClipTaskId: clipResult.clipKey,
|
|
20549
|
+
traceInfo: {
|
|
20550
|
+
traceKey,
|
|
20551
|
+
uploadCdnStart: uploadStartTime,
|
|
20552
|
+
uploadCdnEnd: uploadEndTime
|
|
20553
|
+
},
|
|
20554
|
+
objectDesc,
|
|
20555
|
+
report: {
|
|
20556
|
+
clipKey: clipResult.clipKey,
|
|
20557
|
+
draftId: clipResult.clipKey,
|
|
20558
|
+
...buildCommonBody(auth.finderUsername),
|
|
20559
|
+
height: videoMeta.height,
|
|
20560
|
+
width: videoMeta.width,
|
|
20561
|
+
duration: videoMeta.duration,
|
|
20562
|
+
fileSize: videoUpload.fileSize,
|
|
20563
|
+
uploadCost: (uploadEndTime - uploadStartTime) * 1000
|
|
20564
|
+
},
|
|
20565
|
+
postFlag: 0,
|
|
20566
|
+
mode: 1,
|
|
20567
|
+
clientid: __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].randomUUID(),
|
|
20568
|
+
...buildCommonBody(auth.finderUsername)
|
|
20569
|
+
};
|
|
20570
|
+
if (params.scheduledTime) publishData.effectiveTime = params.scheduledTime;
|
|
20571
|
+
if (params.tagInfo && tagKey) publishData.tagInfo = buildTagInfo(params.tagInfo, tagKey);
|
|
20572
|
+
logger.info("[publishVideo] 开始发布视频,全部参数:" + JSON.stringify(publishData));
|
|
20573
|
+
const publishRes = await proxyHttp.api({
|
|
20574
|
+
method: "POST",
|
|
20575
|
+
url: `${MICRO_CONTENT_BASE}/post/post_create`,
|
|
20576
|
+
params: buildPublishQuery(client),
|
|
20577
|
+
data: publishData,
|
|
20578
|
+
defaultErrorMsg: "发布视频失败"
|
|
20579
|
+
});
|
|
20580
|
+
logger.info(`[publishVideo] 发布响应: errCode=${publishRes.errCode}, baseResp.errcode=${publishRes.data?.baseResp?.errcode}`);
|
|
20581
|
+
return publishRes;
|
|
20582
|
+
}
|
|
20583
|
+
function sleep(ms) {
|
|
20584
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
20585
|
+
}
|
|
20586
|
+
async function resolveLocalCoverPath(coverPath, label, tmpCachePath, logger) {
|
|
20587
|
+
if (!/^https?:\/\//i.test(coverPath)) return coverPath;
|
|
20588
|
+
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(coverPath);
|
|
20589
|
+
const savePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, `${Date.now()}-${label}-${fileName}`);
|
|
20590
|
+
await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(coverPath, savePath);
|
|
20591
|
+
return savePath;
|
|
20592
|
+
}
|
|
20593
|
+
const shipinhaoPublishVideo_mock_mockAction = async (task, params)=>{
|
|
20594
|
+
task.logger.info("[shipinhaoPublishVideo] 开始执行视频号视频发布 - Mock API 方式");
|
|
20595
|
+
const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
|
|
20596
|
+
let currentStep = "初始化";
|
|
20597
|
+
try {
|
|
20598
|
+
task.logger.info(`[shipinhaoPublishVideo] 发布方式: ${params.scheduledTime ? `定时 ${new Date(1000 * params.scheduledTime).toLocaleString()}` : "立即发布"}`);
|
|
20599
|
+
currentStep = "解析认证信息";
|
|
20600
|
+
const cookieString = params.cookies.map((c)=>`${c.name}=${c.value}`).join("; ");
|
|
20601
|
+
const http = new Http({
|
|
20602
|
+
headers: {
|
|
20603
|
+
cookie: cookieString
|
|
20604
|
+
}
|
|
20605
|
+
});
|
|
20606
|
+
currentStep = "验证发布参数";
|
|
20607
|
+
if (!params.videoPath) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "视频文件路径不能为空", "");
|
|
20608
|
+
if (!params.coverPath) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "横屏封面图片路径不能为空", "");
|
|
20609
|
+
currentStep = "获取上传认证";
|
|
20610
|
+
task.logger.info("[shipinhaoPublishVideo] 获取上传认证...");
|
|
20611
|
+
const auth = await getShipinhaoUploadAuth(cookieString, http);
|
|
20612
|
+
const client = resolveClientContext(params, auth.uin);
|
|
20613
|
+
if (!client.aId) task.logger.warn("[shipinhaoPublishVideo] extraParam.aId 缺失,query 将不带 _aid");
|
|
20614
|
+
if (!client.fingerPrintDeviceId) task.logger.warn("[shipinhaoPublishVideo] extraParam.fingerPrintDeviceId 缺失,请求将不带 finger-print-device-id");
|
|
20615
|
+
const publishHeaders = buildPublishHeaders(cookieString, client);
|
|
20616
|
+
const microHttp = new Http({
|
|
20617
|
+
headers: publishHeaders
|
|
20618
|
+
});
|
|
20619
|
+
const args = [
|
|
20620
|
+
{
|
|
20621
|
+
headers: publishHeaders
|
|
20622
|
+
},
|
|
20623
|
+
task.logger,
|
|
20624
|
+
params.proxyLoc,
|
|
20625
|
+
params.accountId,
|
|
20626
|
+
"shipinhao"
|
|
20627
|
+
];
|
|
20628
|
+
const proxyHttp = new Http(...args);
|
|
20629
|
+
currentStep = "组装视频元数据";
|
|
20630
|
+
task.logger.info("[shipinhaoPublishVideo] 组装视频元数据...");
|
|
20631
|
+
const videoMeta = buildVideoMetaFromParams(params.videoPath, params.videoMetadata);
|
|
20632
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
20633
|
+
if (!videoMeta.codec) task.logger.warn("[shipinhaoPublishVideo] 未能读取视频编码格式,跳过 H.264 预检,交由服务端判断");
|
|
20634
|
+
currentStep = "校验视频限制";
|
|
20635
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
20636
|
+
if (validationError) {
|
|
20637
|
+
task.logger.error(`[shipinhaoPublishVideo] 视频校验未通过: ${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
|
+
task.logger.info("[shipinhaoPublishVideo] 视频校验通过");
|
|
20645
|
+
currentStep = "校验标题";
|
|
20646
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
20647
|
+
if (titleError) {
|
|
20648
|
+
task.logger.error(`[shipinhaoPublishVideo] 标题校验未通过: ${titleError}`);
|
|
20649
|
+
await updateTaskState?.({
|
|
20650
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20651
|
+
error: titleError
|
|
20652
|
+
});
|
|
20653
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, titleError, "");
|
|
20654
|
+
}
|
|
20655
|
+
currentStep = "获取 traceKey";
|
|
20656
|
+
task.logger.info("[shipinhaoPublishVideo] 获取 traceKey...");
|
|
20657
|
+
const traceKey = await getTraceKey(auth, client, microHttp, task.logger);
|
|
20658
|
+
let tagKey = null;
|
|
20659
|
+
if (params.tagInfo) {
|
|
20660
|
+
currentStep = "获取内容声明 tagKey";
|
|
20661
|
+
tagKey = await getObjectTagKey(auth, client, microHttp, task.logger);
|
|
20662
|
+
}
|
|
20663
|
+
const uploadStartTime = Math.floor(Date.now() / 1000);
|
|
20664
|
+
task.logger.info(`[shipinhaoPublishVideo] 上传开始时间: ${uploadStartTime}`);
|
|
20665
|
+
currentStep = "上传视频";
|
|
20666
|
+
task.logger.info("[shipinhaoPublishVideo] 上传视频...");
|
|
20667
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频路径: ${params.videoPath}`);
|
|
20668
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频文件类型: ${auth.videoFileType}`);
|
|
20669
|
+
const videoUpload = await uploader_uploadFile({
|
|
20670
|
+
filePath: params.videoPath,
|
|
20671
|
+
fileType: auth.videoFileType,
|
|
20672
|
+
uin: auth.uin,
|
|
20673
|
+
authKey: auth.authKey,
|
|
20674
|
+
http,
|
|
20675
|
+
logger: task.logger
|
|
20676
|
+
});
|
|
20677
|
+
task.logger.info("[shipinhaoPublishVideo] 视频上传完成");
|
|
20678
|
+
const uploadEndTime = Math.floor(Date.now() / 1000);
|
|
20679
|
+
task.logger.info(`[shipinhaoPublishVideo] 上传结束时间: ${uploadEndTime}, 耗时: ${uploadEndTime - uploadStartTime}s`);
|
|
20680
|
+
currentStep = "上传横屏封面";
|
|
20681
|
+
const localCoverPath = await resolveLocalCoverPath(params.coverPath, "横屏封面", task.getTmpPath(), task.logger);
|
|
20682
|
+
task.logger.info("[shipinhaoPublishVideo] 上传横屏封面...");
|
|
20683
|
+
const coverUpload = await uploader_uploadFile({
|
|
20684
|
+
filePath: localCoverPath,
|
|
20685
|
+
fileType: auth.pictureFileType,
|
|
20686
|
+
uin: auth.uin,
|
|
20687
|
+
authKey: auth.authKey,
|
|
20688
|
+
http,
|
|
20689
|
+
logger: task.logger
|
|
20690
|
+
});
|
|
20691
|
+
task.logger.info("[shipinhaoPublishVideo] 横屏封面上传完成");
|
|
20692
|
+
let verticalCoverUpload = coverUpload;
|
|
20693
|
+
if (params.verticalCoverPath) {
|
|
20694
|
+
currentStep = "上传竖屏封面";
|
|
20695
|
+
const localVerticalPath = await resolveLocalCoverPath(params.verticalCoverPath, "竖屏封面", task.getTmpPath(), task.logger);
|
|
20696
|
+
task.logger.info("[shipinhaoPublishVideo] 上传竖屏封面");
|
|
20697
|
+
verticalCoverUpload = await uploader_uploadFile({
|
|
20698
|
+
filePath: localVerticalPath,
|
|
20699
|
+
fileType: auth.pictureFileType,
|
|
20700
|
+
uin: auth.uin,
|
|
20701
|
+
authKey: auth.authKey,
|
|
20702
|
+
http,
|
|
20703
|
+
logger: task.logger
|
|
20704
|
+
});
|
|
20705
|
+
task.logger.info("[shipinhaoPublishVideo] 竖屏封面上传完成");
|
|
20706
|
+
} else task.logger.info("[shipinhaoPublishVideo] 未传竖屏封面,复用横屏封面");
|
|
20707
|
+
currentStep = "提交转码";
|
|
20708
|
+
task.logger.info("[shipinhaoPublishVideo] 提交转码...");
|
|
20709
|
+
const clipResult = await submitAndPollTranscode({
|
|
20710
|
+
videoUrl: videoUpload.downloadUrl,
|
|
20711
|
+
videoMeta,
|
|
20712
|
+
traceKey,
|
|
20713
|
+
uploadStartTime,
|
|
20714
|
+
uploadEndTime,
|
|
20715
|
+
finderUsername: auth.finderUsername,
|
|
20716
|
+
client,
|
|
20717
|
+
http: microHttp,
|
|
20718
|
+
logger: task.logger
|
|
20719
|
+
});
|
|
20720
|
+
currentStep = "发布视频";
|
|
20721
|
+
task.logger.info("[shipinhaoPublishVideo] 发布视频...");
|
|
20722
|
+
task.logger.info(`[shipinhaoPublishVideo] clipKey: ${clipResult.clipKey}`);
|
|
20723
|
+
let publishResult;
|
|
20724
|
+
try {
|
|
20725
|
+
publishResult = await publishVideo({
|
|
20726
|
+
params,
|
|
20727
|
+
auth,
|
|
20728
|
+
client,
|
|
20729
|
+
clipResult,
|
|
20730
|
+
videoUpload,
|
|
20731
|
+
coverUpload,
|
|
20732
|
+
verticalCoverUpload,
|
|
20733
|
+
videoMeta,
|
|
20734
|
+
traceKey,
|
|
20735
|
+
tagKey,
|
|
20736
|
+
uploadStartTime,
|
|
20737
|
+
uploadEndTime,
|
|
20738
|
+
proxyHttp,
|
|
20739
|
+
logger: task.logger
|
|
20740
|
+
});
|
|
20741
|
+
} catch (error) {
|
|
20742
|
+
const handledError = Http.handleApiError(error);
|
|
20743
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布请求失败: ${handledError.message}`, stringifyError(handledError));
|
|
20744
|
+
const classified = classifyPublishError(handledError);
|
|
20745
|
+
if (classified) {
|
|
20746
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
20747
|
+
task.logger.error(`[shipinhaoPublishVideo] ${classified.category},直接返回: ${handledError.message} (code=${handledError.code})`, stringifyError(handledError));
|
|
20748
|
+
await updateTaskState?.({
|
|
20749
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20750
|
+
error: message
|
|
20751
|
+
});
|
|
20752
|
+
return {
|
|
20753
|
+
code: 414,
|
|
20754
|
+
data: "",
|
|
20755
|
+
message
|
|
20756
|
+
};
|
|
20757
|
+
}
|
|
20758
|
+
throw error;
|
|
20759
|
+
}
|
|
20760
|
+
task.logger.info(`[shipinhaoPublishVideo] publishResult: ${JSON.stringify(publishResult)}`);
|
|
20761
|
+
const resultCode = publishResult.data?.baseResp?.errcode ?? publishResult.errCode;
|
|
20762
|
+
const resultMsg = publishResult.data?.baseResp?.errmsg ?? (0 === resultCode ? "发布成功" : `发布失败(errCode=${resultCode})`);
|
|
20763
|
+
if (0 === resultCode) {
|
|
20764
|
+
task.logger.info("[shipinhaoPublishVideo] 发布成功");
|
|
20765
|
+
task.logger.info(`[shipinhaoPublishVideo] 作品ID: ${clipResult.clipKey}`);
|
|
20766
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频URL: ${clipResult.url}`);
|
|
20767
|
+
task.logger.info(`[shipinhaoPublishVideo] 横屏封面URL: ${coverUpload.downloadUrl}`);
|
|
20768
|
+
task.logger.info(`[shipinhaoPublishVideo] 竖屏封面URL: ${verticalCoverUpload.downloadUrl}`);
|
|
20769
|
+
await updateTaskState?.({
|
|
20770
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.SUCCESS,
|
|
20771
|
+
result: {
|
|
20772
|
+
response: resultMsg
|
|
20773
|
+
}
|
|
20774
|
+
});
|
|
20775
|
+
reportLogger({
|
|
20776
|
+
token: params.huiwenToken || "",
|
|
20777
|
+
enverionment: task.enverionment || "development",
|
|
20778
|
+
postId: params.articleId,
|
|
20779
|
+
eip: proxyHttp.proxyInfo,
|
|
20780
|
+
accountId: params.accountId,
|
|
20781
|
+
uid: params.uid,
|
|
20782
|
+
publishParams: {
|
|
20783
|
+
videoPath: params.videoPath,
|
|
20784
|
+
coverPath: params.coverPath,
|
|
20785
|
+
verticalCoverPath: params.verticalCoverPath,
|
|
20786
|
+
title: params.title,
|
|
20787
|
+
topics: params.topics,
|
|
20788
|
+
mentionedUsers: params.mentionedUsers,
|
|
20789
|
+
collection: params.collection,
|
|
20790
|
+
event: params.event,
|
|
20791
|
+
link: params.link,
|
|
20792
|
+
tagInfo: params.tagInfo,
|
|
20793
|
+
originalFlag: params.originalFlag,
|
|
20794
|
+
scheduledTime: params.scheduledTime
|
|
20795
|
+
},
|
|
20796
|
+
platform: "shipinhao"
|
|
20797
|
+
});
|
|
20798
|
+
task.logger.info("[shipinhaoPublishVideo] 日志上报完成");
|
|
20799
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(0, "发布成功", clipResult.clipKey);
|
|
20800
|
+
}
|
|
20801
|
+
let errorMessage = resultMsg;
|
|
20802
|
+
if (-11224 === resultCode) errorMessage = "视频号管理员完成实名且绑定手机号后才可以发表";
|
|
20803
|
+
else if (300333 === resultCode || 300334 === resultCode) errorMessage = "登录失效";
|
|
20804
|
+
else if (300330 === resultCode) errorMessage = "未登录";
|
|
20805
|
+
else if (300002 === resultCode) errorMessage = "官方平台在校验音乐/位置/定时信息时失败了,请重新编辑后发布";
|
|
20806
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布失败: ${errorMessage} (errCode=${resultCode})`);
|
|
20807
|
+
await updateTaskState?.({
|
|
20808
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20809
|
+
error: errorMessage
|
|
20810
|
+
});
|
|
20811
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(resultCode || 414, errorMessage, "");
|
|
20812
|
+
} catch (error) {
|
|
20813
|
+
const handledError = Http.handleApiError(error);
|
|
20814
|
+
const errorMsg = handledError.message || "发布失败,请稍后重试";
|
|
20815
|
+
const errorCode = handledError.code || 414;
|
|
20816
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布流程异常 [${currentStep}]: ${errorMsg}`, stringifyError(error), handledError.extra);
|
|
20817
|
+
task.logger.error(`[shipinhaoPublishVideo] 错误码: ${errorCode}, 当前步骤: ${currentStep}`);
|
|
20818
|
+
await updateTaskState?.({
|
|
20819
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20820
|
+
error: errorMsg
|
|
20821
|
+
});
|
|
20822
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(errorCode, errorMsg, "");
|
|
20823
|
+
}
|
|
20824
|
+
};
|
|
20825
|
+
const shipinhaoPublishVideo_rpa_rpaAction = async (task, params)=>{
|
|
20826
|
+
task.logger.info("开始微信视频号视频发布(RPA 模式)");
|
|
20827
|
+
const videoMeta = buildVideoMetaFromParams(params.videoPath, params.videoMetadata);
|
|
20828
|
+
task.logger.info(`视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
20829
|
+
if (!videoMeta.codec) task.logger.warn("未能读取视频编码格式,跳过 H.264 预检,交由服务端判断");
|
|
20830
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
20831
|
+
if (validationError) {
|
|
20832
|
+
task.logger.error(`视频校验未通过: ${validationError}`);
|
|
20833
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, validationError, "");
|
|
20834
|
+
}
|
|
20835
|
+
task.logger.info("视频校验通过");
|
|
20836
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
20837
|
+
if (titleError) {
|
|
20838
|
+
task.logger.error(`标题校验未通过: ${titleError}`);
|
|
20839
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, titleError, "");
|
|
20840
|
+
}
|
|
20841
|
+
const unsupported = [
|
|
20842
|
+
params.verticalCoverPath && "verticalCoverPath",
|
|
20843
|
+
params.collection && "collection",
|
|
20844
|
+
params.originalFlag && "originalFlag",
|
|
20845
|
+
params.postWithMemberZoneLink && "postWithMemberZoneLink"
|
|
20846
|
+
].filter(Boolean);
|
|
20847
|
+
if (unsupported.length) task.logger.warn(`RPA 模式不支持以下参数,将被忽略: ${unsupported.join("、")};如需生效请使用 mockApi 模式`);
|
|
20848
|
+
if (params.tagInfo && 5 === params.tagInfo.tagType) {
|
|
20849
|
+
const shootInfo = params.tagInfo.shootInfo;
|
|
20850
|
+
if (shootInfo && (shootInfo.provinceCode || shootInfo.cityCode)) task.logger.warn("tagInfo.tagType=5 在 RPA 模式下仅支持拍摄时间和国家选择,省市选择需要使用 mockApi 模式");
|
|
20851
|
+
}
|
|
20852
|
+
const tmpCachePath = task.getTmpPath();
|
|
20853
|
+
const page = await task.createPage({
|
|
20854
|
+
url: "https://channels.weixin.qq.com/platform/post/create",
|
|
20855
|
+
show: task.debug,
|
|
20856
|
+
cookies: params.cookies
|
|
20857
|
+
});
|
|
20858
|
+
try {
|
|
20859
|
+
const waitForElement = async (selector, timeout = 10000)=>{
|
|
20860
|
+
try {
|
|
20861
|
+
const element = page.locator(selector);
|
|
20862
|
+
await element.waitFor({
|
|
20863
|
+
state: "visible",
|
|
20864
|
+
timeout
|
|
20865
|
+
});
|
|
20866
|
+
return element;
|
|
20867
|
+
} catch {
|
|
20868
|
+
task.logger.warn(`元素未找到: ${selector}`);
|
|
20869
|
+
return null;
|
|
20870
|
+
}
|
|
20871
|
+
};
|
|
20872
|
+
const retryAction = async (action, maxRetries = 3, delay = 1000)=>{
|
|
20873
|
+
let lastError;
|
|
20874
|
+
for(let i = 0; i < maxRetries; i++)try {
|
|
20875
|
+
return await action();
|
|
20876
|
+
} catch (error) {
|
|
20877
|
+
lastError = error;
|
|
20878
|
+
task.logger.warn(`重试 ${i + 1}/${maxRetries}: ${lastError.message}`);
|
|
20879
|
+
if (i < maxRetries - 1) await page.waitForTimeout(delay);
|
|
20880
|
+
}
|
|
20881
|
+
throw lastError;
|
|
20882
|
+
};
|
|
20883
|
+
task.logger.info("等待页面加载...");
|
|
20884
|
+
task.logger.info("检查登录状态...");
|
|
20885
|
+
if (task.debug) {
|
|
20886
|
+
task.logger.info(`当前页面 URL: ${page.url()}`);
|
|
20887
|
+
const title = await page.title();
|
|
20888
|
+
task.logger.info(`页面标题: ${title}`);
|
|
20889
|
+
}
|
|
20890
|
+
try {
|
|
20891
|
+
await page.waitForSelector(".post-edit-wrap", {
|
|
20892
|
+
state: "visible",
|
|
20893
|
+
timeout: 30000
|
|
20894
|
+
});
|
|
20895
|
+
task.logger.info("✓ 登录状态正常,找到编辑器容器");
|
|
20896
|
+
} catch {
|
|
20897
|
+
task.logger.error("✗ 未找到编辑器,可能登录失效");
|
|
20898
|
+
return {
|
|
20899
|
+
code: 414,
|
|
20900
|
+
message: "登录失效或页面加载异常",
|
|
20901
|
+
data: page.url()
|
|
20902
|
+
};
|
|
20903
|
+
}
|
|
20904
|
+
task.logger.info("页面加载完成,开始填充内容");
|
|
20905
|
+
task.logger.info("开始上传视频");
|
|
20906
|
+
await retryAction(async ()=>{
|
|
20907
|
+
const videoUploadSelectors = [
|
|
20908
|
+
'.ant-upload-btn input[type="file"][accept*="video"]',
|
|
20909
|
+
'.upload input[type="file"][accept*="video"]',
|
|
20910
|
+
'input[type="file"][accept*="video"]'
|
|
20911
|
+
];
|
|
20912
|
+
let uploadInput = null;
|
|
20913
|
+
if (task.debug) {
|
|
20914
|
+
const allFileInputs = await page.locator('input[type="file"]').count();
|
|
20915
|
+
task.logger.info(`页面中共找到 ${allFileInputs} 个文件上传输入框`);
|
|
20916
|
+
}
|
|
20917
|
+
for (const selector of videoUploadSelectors){
|
|
20918
|
+
const input = page.locator(selector);
|
|
20919
|
+
const count = await input.count();
|
|
20920
|
+
if (count > 0) {
|
|
20921
|
+
uploadInput = input.first();
|
|
20922
|
+
task.logger.info(`找到视频上传输入框: ${selector}`);
|
|
20923
|
+
break;
|
|
20924
|
+
}
|
|
20925
|
+
}
|
|
20926
|
+
if (!uploadInput) {
|
|
20927
|
+
task.logger.warn("未找到视频上传输入框,等待 3 秒后重试...");
|
|
20928
|
+
await page.waitForTimeout(3000);
|
|
20929
|
+
const anyFileInput = page.locator('input[type="file"]');
|
|
20930
|
+
const inputCount = await anyFileInput.count();
|
|
20931
|
+
if (inputCount > 0) {
|
|
20932
|
+
uploadInput = anyFileInput.first();
|
|
20933
|
+
task.logger.info(`找到文件输入框(共 ${inputCount} 个)`);
|
|
20934
|
+
} else {
|
|
20935
|
+
if (task.debug) {
|
|
20936
|
+
const screenshotPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, `upload-error-${Date.now()}.png`);
|
|
20937
|
+
await page.screenshot({
|
|
20938
|
+
path: screenshotPath,
|
|
20939
|
+
fullPage: true
|
|
20940
|
+
});
|
|
20941
|
+
task.logger.error(`未找到上传输入框,已截图保存至: ${screenshotPath}`);
|
|
20942
|
+
}
|
|
20943
|
+
throw new Error("未找到视频上传输入框");
|
|
20944
|
+
}
|
|
20945
|
+
}
|
|
20946
|
+
await uploadInput.setInputFiles(params.videoPath);
|
|
20947
|
+
task.logger.info("视频上传成功");
|
|
20948
|
+
await page.waitForTimeout(5000);
|
|
20949
|
+
});
|
|
20950
|
+
if (params.coverPath) {
|
|
20951
|
+
task.logger.info("开始上传封面");
|
|
20952
|
+
await retryAction(async ()=>{
|
|
20953
|
+
const coverUploadBtn = await waitForElement(".cover-upload-btn", 10000);
|
|
20954
|
+
if (coverUploadBtn) {
|
|
20955
|
+
const coverInput = page.locator('.cover-upload-btn input[type="file"]');
|
|
20956
|
+
await coverInput.setInputFiles(params.coverPath);
|
|
20957
|
+
task.logger.info("封面上传成功");
|
|
20958
|
+
await page.waitForTimeout(2000);
|
|
20959
|
+
}
|
|
20960
|
+
});
|
|
20961
|
+
}
|
|
20962
|
+
const descriptionText = payload_buildDescription({
|
|
20963
|
+
description: params.description,
|
|
20964
|
+
topics: params.topics,
|
|
20965
|
+
mentionedUsers: params.mentionedUsers
|
|
20966
|
+
});
|
|
20967
|
+
if (descriptionText) {
|
|
20968
|
+
task.logger.info("填写视频描述");
|
|
20969
|
+
await retryAction(async ()=>{
|
|
20970
|
+
const descEditor = await waitForElement(".input-editor", 10000);
|
|
20971
|
+
if (!descEditor) throw new Error("未找到描述编辑器");
|
|
20972
|
+
await descEditor.click();
|
|
20973
|
+
await page.waitForTimeout(500);
|
|
20974
|
+
await descEditor.evaluate((el)=>{
|
|
20975
|
+
el.textContent = "";
|
|
20976
|
+
});
|
|
20977
|
+
await page.waitForTimeout(300);
|
|
20978
|
+
task.logger.info("已清空编辑器内容");
|
|
20979
|
+
await descEditor.pressSequentially(descriptionText, {
|
|
20980
|
+
delay: 10
|
|
20981
|
+
});
|
|
20982
|
+
await page.waitForTimeout(500);
|
|
20983
|
+
task.logger.info("描述填写完成");
|
|
20984
|
+
});
|
|
20985
|
+
}
|
|
20986
|
+
if (params.title) {
|
|
20987
|
+
task.logger.info(`填写标题: ${params.title}`);
|
|
20988
|
+
const title = params.title;
|
|
20989
|
+
await retryAction(async ()=>{
|
|
20990
|
+
const titleInput = await waitForElement("#container-wrap div.form-item-body.short-title-wrap input", 10000);
|
|
20991
|
+
if (!titleInput) throw new Error("未找到标题输入框");
|
|
20992
|
+
await titleInput.click();
|
|
20993
|
+
await titleInput.clear({
|
|
20994
|
+
timeout: 3000
|
|
20995
|
+
});
|
|
20996
|
+
await titleInput.fill(title, {
|
|
20997
|
+
timeout: 5000
|
|
20998
|
+
});
|
|
20999
|
+
task.logger.info("标题填写完成");
|
|
21000
|
+
});
|
|
21001
|
+
}
|
|
21002
|
+
if (params.location) {
|
|
21003
|
+
task.logger.info(`选择地点: ${params.location.city}`);
|
|
21004
|
+
const instance = page.locator(".position-display-wrap");
|
|
21005
|
+
await instance.click();
|
|
21006
|
+
await page.waitForTimeout(1000);
|
|
21007
|
+
await page.locator(".location-filter-wrap input").fill(params.location.city);
|
|
21008
|
+
await page.waitForTimeout(2000);
|
|
21009
|
+
const poperInstance = page.locator(".location-filter-wrap .common-option-list-wrap .option-item");
|
|
21010
|
+
await poperInstance.nth(1).waitFor();
|
|
21011
|
+
await poperInstance.nth(1).click();
|
|
21012
|
+
task.logger.info("地点选择完成");
|
|
21013
|
+
}
|
|
21014
|
+
if (params.collection) {
|
|
21015
|
+
task.logger.info(`选择合集: ${params.collection.collectionName}`);
|
|
21016
|
+
const instanceCollection = page.locator(".post-album-display-wrap");
|
|
21017
|
+
await instanceCollection.click();
|
|
21018
|
+
await page.waitForTimeout(1000);
|
|
21019
|
+
page.locator(".post-album-wrap .option-item").filter({
|
|
21020
|
+
hasText: params.collection.collectionName
|
|
21021
|
+
}).first().click({
|
|
21022
|
+
force: true
|
|
21023
|
+
});
|
|
21024
|
+
}
|
|
21025
|
+
if (params.link) {
|
|
21026
|
+
task.logger.info(`设置扩展阅读链接: ${params.link.title}`);
|
|
21027
|
+
await page.locator(".post-link-wrap .link-display-wrap").click();
|
|
21028
|
+
await page.waitForTimeout(300);
|
|
21029
|
+
const linkTypeText = 2 === params.link.urlType ? "红包封面" : "公众号文章";
|
|
21030
|
+
await page.locator(".link-option-item .title-wrap span").filter({
|
|
21031
|
+
hasText: linkTypeText
|
|
21032
|
+
}).click();
|
|
21033
|
+
await page.waitForTimeout(300);
|
|
21034
|
+
const placeholder = 2 === params.link.urlType ? "粘贴红包封面链接" : "粘贴公众号文章链接";
|
|
21035
|
+
await page.locator(`.link-input-wrap input[placeholder="${placeholder}"]`).fill(params.link.link);
|
|
21036
|
+
await page.waitForTimeout(500);
|
|
21037
|
+
task.logger.info(`已设置${linkTypeText}: ${params.link.link}`);
|
|
21038
|
+
}
|
|
21039
|
+
if (params.event) {
|
|
21040
|
+
task.logger.info(`选择活动: ${params.event.eventName}`);
|
|
21041
|
+
await page.locator(".post-activity-wrap .activity-display").click();
|
|
21042
|
+
await page.waitForTimeout(500);
|
|
21043
|
+
await page.locator(".activity-filter-wrap .weui-desktop-form__input[placeholder='搜索活动']").fill(params.event.eventName);
|
|
21044
|
+
await page.waitForTimeout(500);
|
|
21045
|
+
const searchLoading = page.locator(".search-loading");
|
|
21046
|
+
await searchLoading.waitFor({
|
|
21047
|
+
state: "hidden",
|
|
21048
|
+
timeout: 5000
|
|
21049
|
+
}).catch(()=>{
|
|
21050
|
+
task.logger.warn("活动搜索加载超时,继续尝试选择");
|
|
21051
|
+
});
|
|
21052
|
+
const activityItem = page.locator(".option-item .activity-item .activity-item-info .name").filter({
|
|
21053
|
+
hasText: params.event.eventName
|
|
21054
|
+
});
|
|
21055
|
+
const count = await activityItem.count();
|
|
21056
|
+
if (count > 0) {
|
|
21057
|
+
await activityItem.first().click();
|
|
21058
|
+
await page.waitForTimeout(300);
|
|
21059
|
+
task.logger.info(`已选择活动: ${params.event.eventName}`);
|
|
21060
|
+
} else {
|
|
21061
|
+
task.logger.warn(`未找到活动: ${params.event.eventName},将不参与活动`);
|
|
21062
|
+
await page.locator(".post-activity-wrap .activity-display").click();
|
|
21063
|
+
await page.waitForTimeout(300);
|
|
21064
|
+
}
|
|
21065
|
+
}
|
|
21066
|
+
if (params.scheduledTime) {
|
|
21067
|
+
task.logger.info("设置定时发布");
|
|
21068
|
+
const timingRadio = page.locator(".weui-desktop-form__check-label").filter({
|
|
21069
|
+
hasNotText: "不定时"
|
|
21070
|
+
}).first();
|
|
21071
|
+
await timingRadio.click();
|
|
21072
|
+
await page.waitForTimeout(500);
|
|
21073
|
+
const instance = page.locator(".weui-desktop-picker__date");
|
|
21074
|
+
await instance.click();
|
|
21075
|
+
const dateD = utils_TimeFormatter.format(1000 * params.scheduledTime, "d");
|
|
21076
|
+
const nowMonth = utils_TimeFormatter.format(Date.now(), "MM月");
|
|
21077
|
+
const nowMonthText = utils_TimeFormatter.format(Date.now(), "M月");
|
|
21078
|
+
const month = utils_TimeFormatter.format(1000 * params.scheduledTime, "MM月");
|
|
21079
|
+
const monthLocator = await page.locator("weui-desktop-picker__panel__label").filter({
|
|
21080
|
+
hasText: month
|
|
21081
|
+
}).first();
|
|
21082
|
+
if (!monthLocator) {
|
|
21083
|
+
await page.locator(".weui-desktop-picker__panel__label").filter({
|
|
21084
|
+
hasText: nowMonth
|
|
21085
|
+
}).first().click();
|
|
21086
|
+
await page.waitForTimeout(500);
|
|
21087
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
21088
|
+
hasText: nowMonthText
|
|
21089
|
+
}).first().click();
|
|
21090
|
+
}
|
|
21091
|
+
await page.waitForTimeout(500);
|
|
21092
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
21093
|
+
hasText: dateD
|
|
21094
|
+
}).first().click();
|
|
21095
|
+
await page.locator(".weui-desktop-form__input-wrp input[placeholder*='请选择时间']").fill(utils_TimeFormatter.format(1000 * params.scheduledTime, "hh:mm"));
|
|
21096
|
+
await page.locator("i.weui-desktop-icon__time").click();
|
|
21097
|
+
await page.locator(".post-time-wrap .form-item .label").filter({
|
|
21098
|
+
hasText: "发表时间"
|
|
21099
|
+
}).click();
|
|
21100
|
+
}
|
|
21101
|
+
if (params.tagInfo) {
|
|
21102
|
+
task.logger.info(`设置视频标注: tagType=${params.tagInfo.tagType}`);
|
|
21103
|
+
await page.locator(".mark-tag-select").click();
|
|
21104
|
+
await page.waitForTimeout(300);
|
|
21105
|
+
const tagTypeTextMap = {
|
|
21106
|
+
0: "无需标注",
|
|
21107
|
+
1: "含AI生成内容",
|
|
21108
|
+
2: "内容包含营销广告",
|
|
21109
|
+
3: "内容为虚构剧情,仅供娱乐",
|
|
21110
|
+
5: "内容为自行拍摄",
|
|
21111
|
+
7: "内容为转载",
|
|
21112
|
+
8: "个人观点,仅供参考"
|
|
21113
|
+
};
|
|
21114
|
+
const tagText = tagTypeTextMap[params.tagInfo.tagType];
|
|
21115
|
+
if (tagText) {
|
|
21116
|
+
await page.locator(".mark-tag-option .option-main").filter({
|
|
21117
|
+
hasText: tagText
|
|
21118
|
+
}).click();
|
|
21119
|
+
await page.waitForTimeout(300);
|
|
21120
|
+
if (5 === params.tagInfo.tagType) {
|
|
21121
|
+
const shootInfo = params.tagInfo.shootInfo;
|
|
21122
|
+
if (shootInfo) {
|
|
21123
|
+
task.logger.info("填写拍摄时间和地点...");
|
|
21124
|
+
await page.waitForTimeout(500);
|
|
21125
|
+
if (shootInfo.postTimestamp) {
|
|
21126
|
+
task.logger.info(`设置拍摄时间: ${shootInfo.postTimestamp}`);
|
|
21127
|
+
const timestamp = 1000 * parseInt(shootInfo.postTimestamp, 10);
|
|
21128
|
+
const date = new Date(timestamp);
|
|
21129
|
+
await page.locator(".original-dialog-content .weui-desktop-picker__date input[placeholder*='请选择拍摄时间']").click();
|
|
21130
|
+
await page.waitForTimeout(300);
|
|
21131
|
+
const dayNum = date.getDate();
|
|
21132
|
+
await page.locator(".weui-desktop-picker__table a").filter({
|
|
21133
|
+
hasText: new RegExp(`^\\s*${dayNum}\\s*$`)
|
|
21134
|
+
}).first().click();
|
|
21135
|
+
await page.waitForTimeout(300);
|
|
21136
|
+
}
|
|
21137
|
+
if (shootInfo.countryCode || shootInfo.provinceCode || shootInfo.cityCode) {
|
|
21138
|
+
task.logger.info("设置拍摄地点...");
|
|
21139
|
+
await page.locator(".original-dialog-content .weui-desktop-form__dropdowncascade .weui-desktop-form__dropdowncascade__dt").click();
|
|
21140
|
+
await page.waitForTimeout(300);
|
|
21141
|
+
if (1156 === shootInfo.countryCode) {
|
|
21142
|
+
await page.locator(".weui-desktop-dropdown__list-ele .weui-desktop-dropdown__list-ele__text").filter({
|
|
21143
|
+
hasText: "中国"
|
|
21144
|
+
}).click();
|
|
21145
|
+
await page.waitForTimeout(300);
|
|
21146
|
+
task.logger.warn("RPA 模式下暂不支持选择具体省份和城市,仅选择了国家");
|
|
21147
|
+
} else task.logger.warn(`不支持的国家代码: ${shootInfo.countryCode},跳过地点设置`);
|
|
21148
|
+
}
|
|
21149
|
+
const confirmBtn = await waitForElement(".weui-desktop-dialog .weui-desktop-btn_primary");
|
|
21150
|
+
if (confirmBtn) {
|
|
21151
|
+
await confirmBtn.click();
|
|
21152
|
+
await page.waitForTimeout(300);
|
|
21153
|
+
}
|
|
21154
|
+
} else task.logger.warn("tagType=5 需要提供 shootInfo 字段(拍摄时间和地点)");
|
|
21155
|
+
}
|
|
21156
|
+
if (7 === params.tagInfo.tagType) {
|
|
21157
|
+
const repostSource = params.tagInfo.repostSource;
|
|
21158
|
+
if (repostSource) {
|
|
21159
|
+
task.logger.info(`填写转载来源: ${repostSource}`);
|
|
21160
|
+
await page.waitForTimeout(500);
|
|
21161
|
+
await page.locator(".repost-dialog-content .repost-textarea").fill(repostSource);
|
|
21162
|
+
await page.waitForTimeout(300);
|
|
21163
|
+
const confirmBtn = await waitForElement(".weui-desktop-dialog .weui-desktop-btn_primary");
|
|
21164
|
+
if (confirmBtn) {
|
|
21165
|
+
await confirmBtn.click();
|
|
21166
|
+
await page.waitForTimeout(300);
|
|
21167
|
+
}
|
|
21168
|
+
} else task.logger.warn("tagType=7 需要提供 repostSource 字段(转载来源)");
|
|
21169
|
+
}
|
|
21170
|
+
} else task.logger.warn(`未知的 tagType: ${params.tagInfo.tagType},跳过标注设置`);
|
|
21171
|
+
}
|
|
21172
|
+
task.logger.info("准备发布...");
|
|
21173
|
+
await page.waitForTimeout(500);
|
|
21174
|
+
let videoId = "";
|
|
21175
|
+
const handleResponse = async (response)=>{
|
|
21176
|
+
const url = response.url();
|
|
21177
|
+
if (url.includes("/post/post_create")) {
|
|
21178
|
+
const jsonResponse = await response.json();
|
|
21179
|
+
page.off("response", handleResponse);
|
|
21180
|
+
videoId = jsonResponse.object?.id || jsonResponse.data?.objectId || "";
|
|
21181
|
+
}
|
|
21182
|
+
};
|
|
21183
|
+
page.on("response", handleResponse);
|
|
21184
|
+
task._timerRecord.PrePublish = Date.now();
|
|
21185
|
+
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";
|
|
21186
|
+
task.logger.info("等待视频上传完成(预览区媒体操作栏出现)...");
|
|
21187
|
+
const uploadTimeout = 600000;
|
|
21188
|
+
const uploadWaitStart = Date.now();
|
|
21189
|
+
let lastProgressLog = 0;
|
|
21190
|
+
while(true){
|
|
21191
|
+
const ready = await page.evaluate((selector)=>{
|
|
21192
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
21193
|
+
const root = host?.shadowRoot;
|
|
21194
|
+
if (!root) return false;
|
|
21195
|
+
return !!root.querySelector(selector);
|
|
21196
|
+
}, MEDIA_OPR_SELECTOR);
|
|
21197
|
+
if (ready) break;
|
|
21198
|
+
const elapsed = Date.now() - uploadWaitStart;
|
|
21199
|
+
if (elapsed > uploadTimeout) throw new Error(`视频上传超时,预览区未就绪(已等待 ${Math.round(elapsed / 1000)}s)`);
|
|
21200
|
+
if (elapsed - lastProgressLog >= 15000) {
|
|
21201
|
+
lastProgressLog = elapsed;
|
|
21202
|
+
task.logger.info(`视频仍在上传中... 已等待 ${Math.round(elapsed / 1000)}s`);
|
|
21203
|
+
}
|
|
21204
|
+
await page.waitForTimeout(1000);
|
|
21205
|
+
}
|
|
21206
|
+
task.logger.info(`视频上传完成(等待 ${Math.round((Date.now() - uploadWaitStart) / 1000)}s)`);
|
|
21207
|
+
const clicked = await page.evaluate(()=>{
|
|
21208
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
21209
|
+
const root = host?.shadowRoot;
|
|
21210
|
+
if (!root) return "未找到 wujie-app shadowRoot";
|
|
21211
|
+
const btns = Array.from(root.querySelectorAll(".form-btns .weui-desktop-btn"));
|
|
21212
|
+
const target = btns.find((el)=>(el.textContent || "").includes("发表"));
|
|
21213
|
+
if (!target) return "未找到发表按钮";
|
|
21214
|
+
if (target.classList.contains("weui-desktop-btn_disabled")) return "发表按钮仍处于禁用状态";
|
|
21215
|
+
target.click();
|
|
21216
|
+
return null;
|
|
21217
|
+
});
|
|
21218
|
+
if (clicked) throw new Error(clicked);
|
|
21219
|
+
task.logger.info("已点击发布按钮,等待响应...");
|
|
21220
|
+
try {
|
|
21221
|
+
await page.waitForURL((url)=>url.href !== page.url(), {
|
|
21222
|
+
timeout: 30000
|
|
21223
|
+
});
|
|
21224
|
+
task.logger.info(`发布成功,页面已跳转: ${page.url()}`);
|
|
21225
|
+
} catch {
|
|
21226
|
+
task.logger.warn("等待页面跳转超时,可能发布失败或网络慢,继续关闭页面");
|
|
21227
|
+
}
|
|
21228
|
+
await page.close();
|
|
21229
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(videoId, "发布成功");
|
|
21230
|
+
} catch (error) {
|
|
21231
|
+
let errorMsg = error instanceof Error ? error.message : String(error);
|
|
21232
|
+
if (errorMsg.includes("context or browser has been closed")) errorMsg = "浏览器上下文已被关闭";
|
|
21233
|
+
task.logger.error(`微信视频号视频发布失败: ${errorMsg}`);
|
|
21234
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, `微信视频号视频发布失败: ${errorMsg}`, "");
|
|
21235
|
+
}
|
|
21236
|
+
};
|
|
21237
|
+
const ShipinhaoPublishVideoParamsSchema = ActionCommonParamsSchema.extend({
|
|
21238
|
+
videoPath: schemas_string().min(1),
|
|
21239
|
+
videoMetadata: schemas_object({
|
|
21240
|
+
duration: schemas_number().positive(),
|
|
21241
|
+
width: schemas_number().int().positive(),
|
|
21242
|
+
height: schemas_number().int().positive(),
|
|
21243
|
+
fileSize: schemas_number().int().positive(),
|
|
21244
|
+
path: schemas_string().min(1).optional(),
|
|
21245
|
+
fileName: schemas_string().min(1)
|
|
21246
|
+
}),
|
|
21247
|
+
coverPath: schemas_string().min(1),
|
|
21248
|
+
verticalCoverPath: schemas_string().min(1).optional(),
|
|
21249
|
+
description: schemas_string(),
|
|
21250
|
+
title: schemas_string().optional(),
|
|
21251
|
+
scheduledTime: schemas_number().int().positive().optional(),
|
|
21252
|
+
isImmediatelyPublish: schemas_boolean().optional(),
|
|
21253
|
+
topics: schemas_array(schemas_string()).optional(),
|
|
21254
|
+
mentionedUsers: schemas_array(schemas_object({
|
|
21255
|
+
nickname: schemas_string()
|
|
21256
|
+
})).optional(),
|
|
21257
|
+
collection: schemas_object({
|
|
21258
|
+
collectionId: schemas_string(),
|
|
21259
|
+
collectionName: schemas_string()
|
|
21260
|
+
}).optional(),
|
|
21261
|
+
event: schemas_object({
|
|
21262
|
+
eventTopicId: schemas_string(),
|
|
21263
|
+
eventName: schemas_string(),
|
|
21264
|
+
eventCreatorNickname: schemas_string().optional()
|
|
21265
|
+
}).optional(),
|
|
21266
|
+
link: schemas_object({
|
|
21267
|
+
link: schemas_string(),
|
|
21268
|
+
title: schemas_string(),
|
|
21269
|
+
urlType: schemas_number().int().default(1)
|
|
21270
|
+
}).optional(),
|
|
21271
|
+
tagInfo: looseObject({
|
|
21272
|
+
tagType: schemas_number().int()
|
|
21273
|
+
}).optional(),
|
|
21274
|
+
originalFlag: union([
|
|
21275
|
+
literal(0),
|
|
21276
|
+
literal(1)
|
|
21277
|
+
]).optional(),
|
|
21278
|
+
postWithMemberZoneLink: union([
|
|
21279
|
+
literal(0),
|
|
21280
|
+
literal(1)
|
|
21281
|
+
]).optional(),
|
|
21282
|
+
location: schemas_object({
|
|
21283
|
+
latitude: schemas_number(),
|
|
21284
|
+
longitude: schemas_number(),
|
|
21285
|
+
city: schemas_string(),
|
|
21286
|
+
poiName: schemas_string().optional(),
|
|
21287
|
+
address: schemas_string().optional(),
|
|
21288
|
+
poiClassifyId: schemas_string().optional()
|
|
21289
|
+
}).optional()
|
|
21290
|
+
});
|
|
21291
|
+
const shipinhaoPublishVideo = async (task, params)=>{
|
|
21292
|
+
task.logger.info(`[shipinhaoPublishVideo] actionType: ${params.actionType}`);
|
|
21293
|
+
if ("rpa" === params.actionType) return shipinhaoPublishVideo_rpa_rpaAction(task, params);
|
|
21294
|
+
if ("mockApi" === params.actionType) return shipinhaoPublishVideo_mock_mockAction(task, params);
|
|
21295
|
+
return executeAction(shipinhaoPublishVideo_mock_mockAction, shipinhaoPublishVideo_rpa_rpaAction)(task, params);
|
|
21296
|
+
};
|
|
21297
|
+
const ShipinhaoSendMsgParamsSchema = ActionCommonParamsSchema.extend({
|
|
21298
|
+
toUsername: schemas_string().min(1, "接收者用户名不能为空"),
|
|
21299
|
+
sessionId: schemas_string().min(1, "会话ID不能为空"),
|
|
21300
|
+
msgType: schemas_enum([
|
|
21301
|
+
"TEXT",
|
|
21302
|
+
"IMAGE"
|
|
21303
|
+
], {
|
|
21304
|
+
message: "消息类型必须是 TEXT 或 IMAGE"
|
|
21305
|
+
}),
|
|
21306
|
+
content: schemas_string().optional(),
|
|
21307
|
+
imageInfo: schemas_object({
|
|
21308
|
+
pathOrUrl: schemas_string().min(1, "图片路径或URL不能为空")
|
|
21309
|
+
}).optional()
|
|
21310
|
+
});
|
|
21311
|
+
const shipinhaoSendMsg_CHUNK_SIZE = 524288;
|
|
21312
|
+
async function shipinhaoSendMsg_getUserInfo(cookieStr, http) {
|
|
21313
|
+
const url = `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data?_rid=${rid()}`;
|
|
21314
|
+
const headers = {
|
|
21315
|
+
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
21316
|
+
cookie: cookieStr,
|
|
21317
|
+
Origin: "https://channels.weixin.qq.com"
|
|
21318
|
+
};
|
|
21319
|
+
return await http.api({
|
|
21320
|
+
method: "get",
|
|
21321
|
+
url,
|
|
21322
|
+
headers
|
|
21323
|
+
}, {
|
|
21324
|
+
retries: 3,
|
|
21325
|
+
retryDelay: 1000,
|
|
21326
|
+
timeout: 10000
|
|
21327
|
+
});
|
|
21328
|
+
}
|
|
21329
|
+
const shipinhaoSendMsg = async (_task, params)=>{
|
|
21330
|
+
if (!params.sessionId) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "sessionId 不能为空", void 0);
|
|
21331
|
+
if (!params.toUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "接收者用户名不能为空", void 0);
|
|
21332
|
+
if (!params.msgType) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型不能为空", void 0);
|
|
21333
|
+
if (![
|
|
21334
|
+
"TEXT",
|
|
21335
|
+
"IMAGE"
|
|
21336
|
+
].includes(params.msgType)) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息类型必须是 TEXT 或 IMAGE", void 0);
|
|
21337
|
+
if ("TEXT" === params.msgType) {
|
|
21338
|
+
if (!params.content || "" === params.content.trim()) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "消息内容不能为空", void 0);
|
|
21339
|
+
}
|
|
21340
|
+
if ("IMAGE" === params.msgType) {
|
|
21341
|
+
if (!params.imageInfo?.pathOrUrl) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "图片路径或URL不能为空", void 0);
|
|
21342
|
+
}
|
|
21343
|
+
if (!params.extraParam) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "缺少 extraParam 参数", void 0);
|
|
21344
|
+
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);
|
|
21345
|
+
const cookieStr = params.cookies.map((it)=>`${it.name}=${it.value}`).join(";");
|
|
21346
|
+
const headers = {
|
|
21347
|
+
cookie: cookieStr,
|
|
21348
|
+
referer: "https://channels.weixin.qq.com/micro/interaction/private_msg",
|
|
21349
|
+
origin: "https://channels.weixin.qq.com",
|
|
21350
|
+
"content-type": "application/json",
|
|
21351
|
+
"finger-print-device-id": params.extraParam.fingerPrintDeviceId,
|
|
21352
|
+
"x-wechat-uin": params.extraParam.uin
|
|
21353
|
+
};
|
|
21354
|
+
const http = new Http({
|
|
21355
|
+
headers
|
|
21356
|
+
});
|
|
21357
|
+
const urlParams = new URLSearchParams({
|
|
21358
|
+
_aid: params.extraParam.aId,
|
|
21359
|
+
_rid: rid(),
|
|
21360
|
+
_pageUrl: "https://channels.weixin.qq.com/micro/interaction/private_msg"
|
|
21361
|
+
}).toString();
|
|
21362
|
+
const generateCliMsgId = ()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (s)=>{
|
|
21363
|
+
const t = 16 * Math.random() | 0;
|
|
21364
|
+
return ("x" === s ? t : 3 & t | 8).toString(16);
|
|
21365
|
+
});
|
|
21366
|
+
let fromUsername = params.extraParam.finderUserName;
|
|
21367
|
+
if (!fromUsername) {
|
|
21368
|
+
_task.logger.info("未提供 finderUserName,尝试获取用户信息");
|
|
21369
|
+
const userInfoRes = await shipinhaoSendMsg_getUserInfo(cookieStr, http);
|
|
21370
|
+
if (!userInfoRes.data?.finderUser?.finderUsername) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(userInfoRes.errCode || -1, userInfoRes.errMsg || "获取用户信息失败", {});
|
|
21371
|
+
fromUsername = userInfoRes.data.finderUser.finderUsername;
|
|
21372
|
+
_task.logger.info(`获取到用户名: ${fromUsername}`);
|
|
21373
|
+
}
|
|
21374
|
+
let imgMsg;
|
|
21375
|
+
if ("IMAGE" === params.msgType) {
|
|
21376
|
+
let imageBuffer;
|
|
21377
|
+
const imagePath = params.imageInfo.pathOrUrl;
|
|
21378
|
+
try {
|
|
21379
|
+
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
|
|
21380
|
+
const resp = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(imagePath, {
|
|
21381
|
+
responseType: "arraybuffer"
|
|
21382
|
+
});
|
|
21383
|
+
imageBuffer = Buffer.from(resp.data);
|
|
21384
|
+
} else {
|
|
21385
|
+
const filePath = imagePath.startsWith("file://") ? imagePath.slice(7) : imagePath;
|
|
21386
|
+
imageBuffer = Buffer.from(await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.readFile(filePath));
|
|
21387
|
+
}
|
|
21388
|
+
} catch (err) {
|
|
21389
|
+
_task.logger.error(`读取图片失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
21390
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, USER_MESSAGE.IMAGE_UPLOAD_FAILED, void 0);
|
|
21391
|
+
}
|
|
21392
|
+
const md5 = (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)("md5").update(imageBuffer).digest("hex");
|
|
21393
|
+
const timestamp = Date.now().toString();
|
|
21394
|
+
const totalChunks = Math.ceil(imageBuffer.length / shipinhaoSendMsg_CHUNK_SIZE);
|
|
21395
|
+
console.log(`分片上传md5${md5}`);
|
|
21396
|
+
let lastRes;
|
|
21397
|
+
for(let i = 0; i < totalChunks; i++){
|
|
21398
|
+
const chunkBuffer = imageBuffer.slice(i * shipinhaoSendMsg_CHUNK_SIZE, (i + 1) * shipinhaoSendMsg_CHUNK_SIZE);
|
|
21399
|
+
const requestData = {
|
|
21400
|
+
content: `data:application/octet-stream;base64,${chunkBuffer.toString("base64")}`,
|
|
21401
|
+
chunk: i,
|
|
21402
|
+
chunks: totalChunks,
|
|
21403
|
+
fromUsername,
|
|
21404
|
+
toUsername: params.toUsername,
|
|
21405
|
+
aesKey: "U2FsdGVkX18cwrWR73LMGhBcmAX8xoNTgbmgkZBYkEs=",
|
|
21406
|
+
mediaSize: imageBuffer.length,
|
|
21407
|
+
mediaType: 3,
|
|
21408
|
+
md5,
|
|
21409
|
+
timestamp,
|
|
21410
|
+
_log_finder_uin: "",
|
|
21411
|
+
_log_finder_id: params.extraParam.finderUserName || "",
|
|
21412
|
+
rawKeyBuff: null,
|
|
21413
|
+
pluginSessionId: null,
|
|
21414
|
+
scene: 7,
|
|
21415
|
+
reqScene: 7
|
|
21416
|
+
};
|
|
21417
|
+
lastRes = await http.api({
|
|
21418
|
+
method: "post",
|
|
21419
|
+
url: `https://channels.weixin.qq.com/micro/interaction/cgi-bin/mmfinderassistant-bin/private-msg/upload-media-info?${urlParams}`,
|
|
21420
|
+
data: requestData
|
|
21421
|
+
});
|
|
21422
|
+
console.log(`分片上传 ${i + 1}/${totalChunks} 响应:`, lastRes);
|
|
21423
|
+
if (lastRes?.errCode !== 0 && i < totalChunks - 1) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || `第 ${i + 1}/${totalChunks} 分片上传失败`, void 0);
|
|
21424
|
+
}
|
|
21425
|
+
if (lastRes?.errCode !== 0) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, lastRes?.errMsg || "上传图片失败", void 0);
|
|
21426
|
+
const uploadedImgMsg = lastRes.data?.imgMsg;
|
|
21427
|
+
imgMsg = {
|
|
21428
|
+
aeskey: uploadedImgMsg.aesKey ?? uploadedImgMsg.aeskey,
|
|
21429
|
+
url: uploadedImgMsg.cdnUrl ?? uploadedImgMsg.url,
|
|
21430
|
+
hdSize: uploadedImgMsg.hdSize ?? uploadedImgMsg.size,
|
|
21431
|
+
midSize: uploadedImgMsg.midSize ?? uploadedImgMsg.size,
|
|
21432
|
+
thumbSize: uploadedImgMsg.thumbSize ?? uploadedImgMsg.size,
|
|
21433
|
+
thumbHeight: uploadedImgMsg.thumbHeight ?? uploadedImgMsg.height,
|
|
21434
|
+
thumbWidth: uploadedImgMsg.thumbWidth ?? uploadedImgMsg.width,
|
|
21435
|
+
md5: uploadedImgMsg.md5
|
|
21436
|
+
};
|
|
21437
|
+
}
|
|
21438
|
+
console.log("发送私信请求参数1111", {
|
|
21439
|
+
sessionId: params.sessionId,
|
|
21440
|
+
fromUsername
|
|
21441
|
+
});
|
|
21442
|
+
const sendRes = await http.api({
|
|
21443
|
+
method: "post",
|
|
21444
|
+
url: `https://channels.weixin.qq.com/micro/interaction/cgi-bin/mmfinderassistant-bin/private-msg/send-private-msg?${urlParams}`,
|
|
21445
|
+
data: {
|
|
21446
|
+
timestamp: Date.now().toString(),
|
|
21447
|
+
_log_finder_uin: "",
|
|
21448
|
+
_log_finder_id: params.extraParam.finderUserName || "",
|
|
21449
|
+
rawKeyBuff: null,
|
|
21450
|
+
pluginSessionId: null,
|
|
21451
|
+
scene: 7,
|
|
21452
|
+
reqScene: 7,
|
|
21453
|
+
msgPack: {
|
|
21454
|
+
sessionId: params.sessionId,
|
|
21455
|
+
fromUsername,
|
|
21456
|
+
toUsername: params.toUsername,
|
|
21457
|
+
cliMsgId: generateCliMsgId(),
|
|
21458
|
+
msgType: "TEXT" === params.msgType ? 1 : 3,
|
|
21459
|
+
imgMsg: "IMAGE" === params.msgType ? imgMsg : void 0,
|
|
21460
|
+
textMsg: "TEXT" === params.msgType ? {
|
|
21461
|
+
content: params.content
|
|
21462
|
+
} : void 0
|
|
21463
|
+
}
|
|
21464
|
+
}
|
|
21465
|
+
});
|
|
21466
|
+
console.log("发送私信响应:", sendRes);
|
|
21467
|
+
const isSuccess = sendRes?.errCode === 0;
|
|
21468
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(isSuccess ? 0 : 414, sendRes?.errMsg || "发送图片私信失败", sendRes.data);
|
|
21469
|
+
};
|
|
21470
|
+
const toutiaoLogin_rpa_rpaAction = async (task, _params)=>{
|
|
21471
|
+
const reporter = task.reportService?.reportLoginStatus ?? (()=>Promise.resolve());
|
|
21472
|
+
let page;
|
|
21473
|
+
let isSelfClosing = false;
|
|
21474
|
+
let handleBrowserDisconnected;
|
|
21475
|
+
const cleanup = async ()=>{
|
|
21476
|
+
if (handleBrowserDisconnected) task._steelBrowser?.off("disconnected", handleBrowserDisconnected);
|
|
21477
|
+
if (page && !page.isClosed()) await page.close().catch(()=>{});
|
|
21478
|
+
};
|
|
21479
|
+
try {
|
|
21480
|
+
page = await task.createPage({
|
|
21481
|
+
url: "https://mp.toutiao.com/auth/page/login"
|
|
21482
|
+
});
|
|
21483
|
+
if (!task._session?.id) throw new Error("Session ID 不存在");
|
|
21484
|
+
handleBrowserDisconnected = ()=>{
|
|
21485
|
+
if (task.debug && isSelfClosing) task.logger.info("执行结束,关闭浏览器!");
|
|
21486
|
+
else task.logger.info("浏览器被手动释放或意外关闭!");
|
|
21487
|
+
};
|
|
21488
|
+
task._steelBrowser?.on("disconnected", handleBrowserDisconnected);
|
|
21489
|
+
} catch (e) {
|
|
21490
|
+
return {
|
|
21491
|
+
code: 414,
|
|
21492
|
+
message: `浏览器启动失败: ${e}`,
|
|
21493
|
+
data: {}
|
|
21494
|
+
};
|
|
21495
|
+
}
|
|
21496
|
+
const pageInfo = await task._client?.sessions.liveDetails(task._session.id);
|
|
21497
|
+
const pageId = pageInfo?.pages[0].id ?? "";
|
|
21498
|
+
const baseHost = task._session.websocketUrl?.replace(/^wss?:\/\//, "") ?? "";
|
|
21499
|
+
const connectAddress = new URLSearchParams({
|
|
21500
|
+
baseHost,
|
|
21501
|
+
pageId
|
|
21502
|
+
}).toString();
|
|
21503
|
+
task.reportService?.settingSessionID?.(task._session?.id || "");
|
|
21504
|
+
await page.route(/\/welcome.*\.(png|mp4)$/i, (route)=>route.abort());
|
|
21505
|
+
await reporter(0, "浏览器启动成功,请使用头条号App扫码登录……", {
|
|
21506
|
+
connectAddress
|
|
21507
|
+
});
|
|
21508
|
+
let userInfo = {
|
|
21509
|
+
uniqueId: "",
|
|
21510
|
+
avatar: "",
|
|
21511
|
+
name: ""
|
|
21512
|
+
};
|
|
21513
|
+
try {
|
|
19847
21514
|
const handleUserInfo = async (resp)=>{
|
|
19848
21515
|
if (resp.url().includes("/mp/agw/creator_center/user_info")) try {
|
|
19849
21516
|
const jsonUserInfo = await resp.json();
|
|
@@ -20181,6 +21848,13 @@ const toutiaoPublish_mock_mockAction = async (task, params)=>{
|
|
|
20181
21848
|
const uploadImages = async (images)=>await Promise.all(images.map(async (url)=>{
|
|
20182
21849
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
20183
21850
|
const image = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
21851
|
+
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(image);
|
|
21852
|
+
const maxSize = 20971520;
|
|
21853
|
+
if (stats.size > maxSize) throw {
|
|
21854
|
+
code: 414,
|
|
21855
|
+
message: "头条号平台:单张图片不得超过 20MB",
|
|
21856
|
+
data: ""
|
|
21857
|
+
};
|
|
20184
21858
|
const formData = new __WEBPACK_EXTERNAL_MODULE_form_data_cf000082__["default"]();
|
|
20185
21859
|
formData.append("image", __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].createReadStream(image));
|
|
20186
21860
|
const response = await http.api({
|
|
@@ -23464,6 +25138,12 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23464
25138
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
23465
25139
|
const localUrl = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
23466
25140
|
const fileBuffer = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(localUrl);
|
|
25141
|
+
const maxSize = 33554432;
|
|
25142
|
+
if (fileBuffer.byteLength > maxSize) throw {
|
|
25143
|
+
code: 414,
|
|
25144
|
+
message: "小红书平台:单张图片不得超过 32MB",
|
|
25145
|
+
data: ""
|
|
25146
|
+
};
|
|
23467
25147
|
let width = 0;
|
|
23468
25148
|
let height = 0;
|
|
23469
25149
|
try {
|
|
@@ -25648,6 +27328,9 @@ class Action {
|
|
|
25648
27328
|
shipinhaoPublish(params) {
|
|
25649
27329
|
return this.bindTask(shipinhaoPublish, params);
|
|
25650
27330
|
}
|
|
27331
|
+
shipinhaoPublishVideo(params) {
|
|
27332
|
+
return this.bindTask(shipinhaoPublishVideo, params);
|
|
27333
|
+
}
|
|
25651
27334
|
douyinGetTopics(params) {
|
|
25652
27335
|
return this.bindTask(douyinGetTopics, params);
|
|
25653
27336
|
}
|
|
@@ -25701,7 +27384,7 @@ class Action {
|
|
|
25701
27384
|
}
|
|
25702
27385
|
}
|
|
25703
27386
|
var __webpack_exports__version = package_namespaceObject.i8;
|
|
25704
|
-
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 };
|
|
27387
|
+
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 };
|
|
25705
27388
|
|
|
25706
27389
|
//# sourceMappingURL=index.mjs.map
|
|
25707
|
-
//# debugId=
|
|
27390
|
+
//# debugId=4c43edf6-56aa-502f-8c51-85f87e629735
|