@iflyrpa/actions 4.0.9-beta.4 → 4.1.0-beta.5
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 +51 -0
- package/dist/actions/shipinhaoPublishVideo/mock.d.ts +4 -0
- package/dist/actions/shipinhaoPublishVideo/rpa.d.ts +6 -0
- package/dist/actions/shipinhaoPublishVideo/uploader.d.ts +38 -0
- package/dist/actions/shipinhaoPublishVideo/videoMeta.d.ts +27 -0
- package/dist/actions/shipinhaoPublishVideo/videoValidator.d.ts +35 -0
- package/dist/bundle.js +1127 -8
- package/dist/bundle.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1127 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1127 -9
- 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/bundle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! For license information please see bundle.js.LICENSE.txt */
|
|
2
2
|
|
|
3
|
-
!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]="
|
|
3
|
+
!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]="1e50231c-4e0f-5db5-a554-c11a95d7391d")}catch(e){}}();
|
|
4
4
|
var __webpack_modules__ = {
|
|
5
5
|
"../../node_modules/.pnpm/agent-base@7.1.4/node_modules/agent-base/dist/helpers.js": function(__unused_webpack_module, exports1, __webpack_require__) {
|
|
6
6
|
"use strict";
|
|
@@ -12446,6 +12446,7 @@ var __webpack_exports__ = {};
|
|
|
12446
12446
|
SessionCheckResultSchema: ()=>SessionCheckResultSchema,
|
|
12447
12447
|
DouyinGetCommentReplyListParamsSchema: ()=>DouyinGetCommentReplyListParamsSchema,
|
|
12448
12448
|
DouyinCreateCommentReplyParamsSchema: ()=>DouyinCreateCommentReplyParamsSchema,
|
|
12449
|
+
ShipinhaoPublishVideoParamsSchema: ()=>ShipinhaoPublishVideoParamsSchema,
|
|
12449
12450
|
DouyinGetHotParamsSchema: ()=>DouyinGetHotParamsSchema,
|
|
12450
12451
|
DouyinGetMusicParamsSchema: ()=>DouyinGetMusicParamsSchema,
|
|
12451
12452
|
FetchArticlesDataSchema: ()=>FetchArticlesDataSchema,
|
|
@@ -12492,7 +12493,7 @@ var __webpack_exports__ = {};
|
|
|
12492
12493
|
var package_namespaceObject = {
|
|
12493
12494
|
i8: "0.1.2"
|
|
12494
12495
|
};
|
|
12495
|
-
var package_namespaceObject_0 = JSON.parse('{"i8":"4.0
|
|
12496
|
+
var package_namespaceObject_0 = JSON.parse('{"i8":"4.1.0-beta.5"}');
|
|
12496
12497
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
12497
12498
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
12498
12499
|
const external_node_http_namespaceObject = require("node:http");
|
|
@@ -13308,7 +13309,7 @@ var __webpack_exports__ = {};
|
|
|
13308
13309
|
const xid = /^[0-9a-vA-V]{20}$/;
|
|
13309
13310
|
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
13310
13311
|
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
13311
|
-
const
|
|
13312
|
+
const dist_duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
13312
13313
|
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})$/;
|
|
13313
13314
|
const dist_uuid = (version)=>{
|
|
13314
13315
|
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)$/;
|
|
@@ -13994,7 +13995,7 @@ var __webpack_exports__ = {};
|
|
|
13994
13995
|
$ZodStringFormat.init(inst, def);
|
|
13995
13996
|
});
|
|
13996
13997
|
const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def)=>{
|
|
13997
|
-
def.pattern ?? (def.pattern =
|
|
13998
|
+
def.pattern ?? (def.pattern = dist_duration);
|
|
13998
13999
|
$ZodStringFormat.init(inst, def);
|
|
13999
14000
|
});
|
|
14000
14001
|
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def)=>{
|
|
@@ -27492,22 +27493,32 @@ var __webpack_exports__ = {};
|
|
|
27492
27493
|
const retries = options?.retries ?? 0;
|
|
27493
27494
|
const retryDelay = options?.retryDelay ?? 500;
|
|
27494
27495
|
const reqTimeout = options?.timeout ?? 30000;
|
|
27496
|
+
const externalSignal = options?.signal;
|
|
27495
27497
|
let agent;
|
|
27496
27498
|
const sessionRt = async (Rtimes)=>{
|
|
27497
27499
|
try {
|
|
27498
27500
|
this.proxyInfo = agent ? `${agent.ip}:${agent.port}` : void 0;
|
|
27499
27501
|
const controller = new AbortController();
|
|
27500
27502
|
const timeoutId = setTimeout(()=>controller.abort(), reqTimeout + 500);
|
|
27503
|
+
const forwardAbort = ()=>controller.abort();
|
|
27504
|
+
if (externalSignal) {
|
|
27505
|
+
if (externalSignal.aborted) controller.abort();
|
|
27506
|
+
else externalSignal.addEventListener("abort", forwardAbort, {
|
|
27507
|
+
once: true
|
|
27508
|
+
});
|
|
27509
|
+
}
|
|
27501
27510
|
const response = await this.apiClient({
|
|
27502
27511
|
...config,
|
|
27503
27512
|
timeout: reqTimeout,
|
|
27504
27513
|
signal: controller.signal,
|
|
27514
|
+
onUploadProgress: options?.onUploadProgress,
|
|
27505
27515
|
...agent ? {
|
|
27506
27516
|
httpAgent: agent.agent,
|
|
27507
27517
|
httpsAgent: agent.agent
|
|
27508
27518
|
} : {}
|
|
27509
27519
|
}).finally(()=>{
|
|
27510
27520
|
clearTimeout(timeoutId);
|
|
27521
|
+
externalSignal?.removeEventListener("abort", forwardAbort);
|
|
27511
27522
|
});
|
|
27512
27523
|
return response.data;
|
|
27513
27524
|
} catch (error) {
|
|
@@ -32912,6 +32923,13 @@ var __webpack_exports__ = {};
|
|
|
32912
32923
|
data: ""
|
|
32913
32924
|
};
|
|
32914
32925
|
const image = await downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
|
|
32926
|
+
const stats = external_node_fs_default().statSync(image);
|
|
32927
|
+
const maxSize = 5242880;
|
|
32928
|
+
if (stats.size > maxSize) throw {
|
|
32929
|
+
code: 414,
|
|
32930
|
+
message: "百家号平台:单张图片不得超过 5MB",
|
|
32931
|
+
data: ""
|
|
32932
|
+
};
|
|
32915
32933
|
const formData = new (form_data_default())();
|
|
32916
32934
|
formData.append("org_file_name", fileName);
|
|
32917
32935
|
formData.append("type", "image");
|
|
@@ -38533,6 +38551,11 @@ var __webpack_exports__ = {};
|
|
|
38533
38551
|
}
|
|
38534
38552
|
async getImageInfo(localPath) {
|
|
38535
38553
|
const stats = external_node_fs_default().statSync(localPath);
|
|
38554
|
+
const maxSize = 52428800;
|
|
38555
|
+
if (stats.size > maxSize) {
|
|
38556
|
+
external_node_path_default().basename(localPath);
|
|
38557
|
+
throw new Error("抖音平台:单张图片不得超过 50MB");
|
|
38558
|
+
}
|
|
38536
38559
|
let width = 1080;
|
|
38537
38560
|
let height = 1920;
|
|
38538
38561
|
try {
|
|
@@ -44779,6 +44802,1086 @@ var __webpack_exports__ = {};
|
|
|
44779
44802
|
if ("server" === params.actionType) return rpa_server_rpaAction_Server(task, params);
|
|
44780
44803
|
return executeAction(shipinhaoPublish_mock_mockAction, rpa_server_rpaAction_Server)(task, params);
|
|
44781
44804
|
};
|
|
44805
|
+
function auth_getTimeStamp(length) {
|
|
44806
|
+
return Date.now().toString().substring(0, length);
|
|
44807
|
+
}
|
|
44808
|
+
async function auth_getUserInfo(cookies, http) {
|
|
44809
|
+
return http.api({
|
|
44810
|
+
method: "post",
|
|
44811
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data",
|
|
44812
|
+
data: {
|
|
44813
|
+
timestamp: auth_getTimeStamp(13),
|
|
44814
|
+
_log_finder_uin: "",
|
|
44815
|
+
_log_finder_id: "",
|
|
44816
|
+
rawKeyBuff: null,
|
|
44817
|
+
pluginSessionId: null,
|
|
44818
|
+
scene: 7,
|
|
44819
|
+
reqScene: 7
|
|
44820
|
+
},
|
|
44821
|
+
headers: {
|
|
44822
|
+
cookie: cookies,
|
|
44823
|
+
referer: "https://channels.weixin.qq.com",
|
|
44824
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
44825
|
+
},
|
|
44826
|
+
defaultErrorMsg: "获取用户信息失败"
|
|
44827
|
+
});
|
|
44828
|
+
}
|
|
44829
|
+
async function auth_getUploadAuthKey(cookies, finderUsername, http) {
|
|
44830
|
+
return http.api({
|
|
44831
|
+
method: "post",
|
|
44832
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/helper/helper_upload_params",
|
|
44833
|
+
data: {
|
|
44834
|
+
timestamp: auth_getTimeStamp(13),
|
|
44835
|
+
_log_finder_id: finderUsername,
|
|
44836
|
+
rawKeyBuff: null
|
|
44837
|
+
},
|
|
44838
|
+
headers: {
|
|
44839
|
+
cookie: cookies,
|
|
44840
|
+
referer: "https://channels.weixin.qq.com",
|
|
44841
|
+
Accept: "application/json, text/plain, */*",
|
|
44842
|
+
"Content-Type": "application/json",
|
|
44843
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
44844
|
+
},
|
|
44845
|
+
defaultErrorMsg: "获取上传认证密钥失败"
|
|
44846
|
+
});
|
|
44847
|
+
}
|
|
44848
|
+
class ShipinhaoAuthError extends Error {
|
|
44849
|
+
constructor(message, errCode){
|
|
44850
|
+
super(message), this.errCode = errCode;
|
|
44851
|
+
this.name = "ShipinhaoAuthError";
|
|
44852
|
+
}
|
|
44853
|
+
}
|
|
44854
|
+
async function getShipinhaoUploadAuth(cookies, http) {
|
|
44855
|
+
const userInfo = await auth_getUserInfo(cookies, http);
|
|
44856
|
+
if (0 !== userInfo.errCode || !userInfo.data?.finderUser) {
|
|
44857
|
+
const isLoginExpired = 300333 === userInfo.errCode || 300334 === userInfo.errCode;
|
|
44858
|
+
throw new ShipinhaoAuthError(isLoginExpired ? "登录失效" : userInfo.errMsg || "获取用户信息失败", userInfo.errCode || 500);
|
|
44859
|
+
}
|
|
44860
|
+
const finderUsername = userInfo.data.finderUser.finderUsername;
|
|
44861
|
+
const authKeyResponse = await auth_getUploadAuthKey(cookies, finderUsername, http);
|
|
44862
|
+
if (0 !== authKeyResponse.errCode || !authKeyResponse.data?.authKey) throw new ShipinhaoAuthError(`获取上传认证参数失败: ${authKeyResponse.errMsg}`, authKeyResponse.errCode || 500);
|
|
44863
|
+
const uin = authKeyResponse.data.uin;
|
|
44864
|
+
if (!uin) throw new ShipinhaoAuthError("获取用户 uin 失败", 500);
|
|
44865
|
+
const videoFileType = authKeyResponse.data.videoFileType || 20302;
|
|
44866
|
+
const pictureFileType = authKeyResponse.data.pictureFileType || 20304;
|
|
44867
|
+
return {
|
|
44868
|
+
uin,
|
|
44869
|
+
authKey: authKeyResponse.data.authKey,
|
|
44870
|
+
finderUsername,
|
|
44871
|
+
videoFileType,
|
|
44872
|
+
pictureFileType
|
|
44873
|
+
};
|
|
44874
|
+
}
|
|
44875
|
+
const CHUNK_SIZE = 8388608;
|
|
44876
|
+
async function uploader_uploadFile(opts) {
|
|
44877
|
+
const { filePath, fileType, uin, authKey, http, logger } = opts;
|
|
44878
|
+
const stat = external_node_fs_default().statSync(filePath);
|
|
44879
|
+
const fileSize = stat.size;
|
|
44880
|
+
const fileName = filePath.split(/[\\/]/).pop() || "file";
|
|
44881
|
+
logger?.info(`开始上传: ${fileName} (${fileSize} B, filetype=${fileType})`);
|
|
44882
|
+
const fileMd5 = await computeFileMd5(filePath);
|
|
44883
|
+
const taskId = generateTaskId(fileName, fileSize, fileMd5);
|
|
44884
|
+
const baseUrl = "https://finderassistancea.video.qq.com";
|
|
44885
|
+
const headers = {
|
|
44886
|
+
Authorization: authKey
|
|
44887
|
+
};
|
|
44888
|
+
const xArgs = `apptype=251&filetype=${fileType}&weixinnum=${uin}&filekey=${encodeURIComponent(fileName)}&filesize=${fileSize}&taskid=${taskId}&scene=2`;
|
|
44889
|
+
const chunkCount = Math.ceil(fileSize / CHUNK_SIZE);
|
|
44890
|
+
const blockPartLength = [];
|
|
44891
|
+
for(let i = 0; i < chunkCount; i++)blockPartLength.push(Math.min((i + 1) * CHUNK_SIZE, fileSize));
|
|
44892
|
+
logger?.info(`申请 UploadID: ${chunkCount} 片`);
|
|
44893
|
+
const applyRes = await http.api({
|
|
44894
|
+
method: "PUT",
|
|
44895
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
44896
|
+
headers: {
|
|
44897
|
+
...headers,
|
|
44898
|
+
"X-Arguments": xArgs
|
|
44899
|
+
},
|
|
44900
|
+
data: {
|
|
44901
|
+
BlockSum: chunkCount,
|
|
44902
|
+
BlockPartLength: blockPartLength
|
|
44903
|
+
}
|
|
44904
|
+
});
|
|
44905
|
+
if (!applyRes.UploadID && !applyRes.ListPartsResult) throw new Error("申请 UploadID 失败: " + JSON.stringify(applyRes));
|
|
44906
|
+
let uploadId = applyRes.UploadID;
|
|
44907
|
+
const uploadedParts = new Set();
|
|
44908
|
+
if (applyRes.ListPartsResult) {
|
|
44909
|
+
logger?.info("检测到已上传分片,执行续传");
|
|
44910
|
+
const parts = Array.isArray(applyRes.ListPartsResult.Part) ? applyRes.ListPartsResult.Part : applyRes.ListPartsResult.Part ? [
|
|
44911
|
+
applyRes.ListPartsResult.Part
|
|
44912
|
+
] : [];
|
|
44913
|
+
for (const p of parts)uploadedParts.add(p.PartNumber);
|
|
44914
|
+
const retryRes = await http.api({
|
|
44915
|
+
method: "PUT",
|
|
44916
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
44917
|
+
headers: {
|
|
44918
|
+
...headers,
|
|
44919
|
+
"X-Arguments": xArgs
|
|
44920
|
+
},
|
|
44921
|
+
data: {
|
|
44922
|
+
BlockSum: chunkCount,
|
|
44923
|
+
BlockPartLength: blockPartLength
|
|
44924
|
+
}
|
|
44925
|
+
});
|
|
44926
|
+
uploadId = retryRes.UploadID;
|
|
44927
|
+
if (!uploadId) throw new Error("续传获取 UploadID 失败");
|
|
44928
|
+
}
|
|
44929
|
+
const partInfo = [];
|
|
44930
|
+
const fd = external_node_fs_default().openSync(filePath, "r");
|
|
44931
|
+
try {
|
|
44932
|
+
for(let i = 0; i < chunkCount; i++){
|
|
44933
|
+
const partNumber = i + 1;
|
|
44934
|
+
if (uploadedParts.has(partNumber)) {
|
|
44935
|
+
const existing = applyRes.ListPartsResult.Part.find((p)=>p.PartNumber === partNumber);
|
|
44936
|
+
if (existing) {
|
|
44937
|
+
partInfo.push({
|
|
44938
|
+
PartNumber: partNumber,
|
|
44939
|
+
ETag: existing.ETag
|
|
44940
|
+
});
|
|
44941
|
+
logger?.info(`分片 ${partNumber}/${chunkCount} 已存在,跳过`);
|
|
44942
|
+
continue;
|
|
44943
|
+
}
|
|
44944
|
+
}
|
|
44945
|
+
const start = i * CHUNK_SIZE;
|
|
44946
|
+
const end = Math.min(start + CHUNK_SIZE, fileSize);
|
|
44947
|
+
const chunkSize = end - start;
|
|
44948
|
+
const chunk = Buffer.alloc(chunkSize);
|
|
44949
|
+
external_node_fs_default().readSync(fd, chunk, 0, chunkSize, start);
|
|
44950
|
+
const chunkMd5 = external_node_crypto_default().createHash("md5").update(chunk).digest("hex");
|
|
44951
|
+
await http.api({
|
|
44952
|
+
method: "PUT",
|
|
44953
|
+
url: `${baseUrl}/uploadpartdfs?PartNumber=${partNumber}&UploadID=${encodeURIComponent(uploadId)}`,
|
|
44954
|
+
headers: {
|
|
44955
|
+
...headers,
|
|
44956
|
+
"X-Arguments": xArgs.replace(/scene=2/, "scene=0"),
|
|
44957
|
+
"Content-MD5": chunkMd5
|
|
44958
|
+
},
|
|
44959
|
+
data: chunk
|
|
44960
|
+
});
|
|
44961
|
+
partInfo.push({
|
|
44962
|
+
PartNumber: partNumber,
|
|
44963
|
+
ETag: `"${chunkMd5}"`
|
|
44964
|
+
});
|
|
44965
|
+
logger?.info(`分片 ${partNumber}/${chunkCount} 完成 (${chunkSize} B)`);
|
|
44966
|
+
}
|
|
44967
|
+
} finally{
|
|
44968
|
+
external_node_fs_default().closeSync(fd);
|
|
44969
|
+
}
|
|
44970
|
+
logger?.info("合并分片...");
|
|
44971
|
+
const completeRes = await http.api({
|
|
44972
|
+
method: "POST",
|
|
44973
|
+
url: `${baseUrl}/completepartuploaddfs?UploadID=${encodeURIComponent(uploadId)}`,
|
|
44974
|
+
headers: {
|
|
44975
|
+
...headers,
|
|
44976
|
+
"X-Arguments": xArgs
|
|
44977
|
+
},
|
|
44978
|
+
data: {
|
|
44979
|
+
TransFlag: "0_0",
|
|
44980
|
+
PartInfo: partInfo
|
|
44981
|
+
}
|
|
44982
|
+
});
|
|
44983
|
+
if (!completeRes.DownloadURL) throw new Error("合并分片失败: " + JSON.stringify(completeRes));
|
|
44984
|
+
logger?.info(`上传成功: ${completeRes.DownloadURL.slice(0, 80)}...`);
|
|
44985
|
+
return {
|
|
44986
|
+
downloadUrl: completeRes.DownloadURL,
|
|
44987
|
+
md5: fileMd5,
|
|
44988
|
+
fileSize
|
|
44989
|
+
};
|
|
44990
|
+
}
|
|
44991
|
+
async function computeFileMd5(filePath) {
|
|
44992
|
+
return new Promise((resolve, reject)=>{
|
|
44993
|
+
const hash = external_node_crypto_default().createHash("md5");
|
|
44994
|
+
const stream = external_node_fs_default().createReadStream(filePath);
|
|
44995
|
+
stream.on("data", (chunk)=>hash.update(chunk));
|
|
44996
|
+
stream.on("end", ()=>resolve(hash.digest("hex")));
|
|
44997
|
+
stream.on("error", reject);
|
|
44998
|
+
});
|
|
44999
|
+
}
|
|
45000
|
+
function generateTaskId(fileName, fileSize, fileMd5) {
|
|
45001
|
+
const input = `${fileName}-${fileSize}-${fileMd5}`;
|
|
45002
|
+
return external_node_crypto_default().createHash("md5").update(input).digest("hex").slice(0, 32);
|
|
45003
|
+
}
|
|
45004
|
+
function parseVideoMeta(filePath) {
|
|
45005
|
+
let buf;
|
|
45006
|
+
try {
|
|
45007
|
+
buf = external_node_fs_default().readFileSync(filePath);
|
|
45008
|
+
} catch {
|
|
45009
|
+
return null;
|
|
45010
|
+
}
|
|
45011
|
+
let movie = null;
|
|
45012
|
+
const tracks = [];
|
|
45013
|
+
function walk(start, end) {
|
|
45014
|
+
let off = start;
|
|
45015
|
+
while(off + 8 <= end){
|
|
45016
|
+
let size = buf.readUInt32BE(off);
|
|
45017
|
+
const type = buf.toString("latin1", off + 4, off + 8);
|
|
45018
|
+
let headerSize = 8;
|
|
45019
|
+
if (1 === size) {
|
|
45020
|
+
if (off + 16 > end) break;
|
|
45021
|
+
const hi = buf.readUInt32BE(off + 8);
|
|
45022
|
+
const lo = buf.readUInt32BE(off + 12);
|
|
45023
|
+
size = hi * 2 ** 32 + lo;
|
|
45024
|
+
headerSize = 16;
|
|
45025
|
+
} else if (0 === size) size = end - off;
|
|
45026
|
+
if (size < headerSize || off + size > end) break;
|
|
45027
|
+
const bodyStart = off + headerSize;
|
|
45028
|
+
const bodyEnd = off + size;
|
|
45029
|
+
switch(type){
|
|
45030
|
+
case "moov":
|
|
45031
|
+
case "trak":
|
|
45032
|
+
case "mdia":
|
|
45033
|
+
case "minf":
|
|
45034
|
+
case "stbl":
|
|
45035
|
+
walk(bodyStart, bodyEnd);
|
|
45036
|
+
break;
|
|
45037
|
+
case "mvhd":
|
|
45038
|
+
movie = parseMvhd(buf, bodyStart, bodyEnd);
|
|
45039
|
+
break;
|
|
45040
|
+
case "tkhd":
|
|
45041
|
+
tracks.push({
|
|
45042
|
+
...parseTkhd(buf, bodyStart, bodyEnd),
|
|
45043
|
+
handler: null,
|
|
45044
|
+
codec: null
|
|
45045
|
+
});
|
|
45046
|
+
break;
|
|
45047
|
+
case "hdlr":
|
|
45048
|
+
if (bodyEnd - bodyStart >= 12) {
|
|
45049
|
+
const handler = buf.toString("latin1", bodyStart + 8, bodyStart + 12);
|
|
45050
|
+
if (tracks.length) tracks[tracks.length - 1].handler = handler;
|
|
45051
|
+
}
|
|
45052
|
+
break;
|
|
45053
|
+
case "stsd":
|
|
45054
|
+
{
|
|
45055
|
+
const codec = parseStsdCodec(buf, bodyStart, bodyEnd);
|
|
45056
|
+
if (codec && tracks.length) tracks[tracks.length - 1].codec = codec;
|
|
45057
|
+
break;
|
|
45058
|
+
}
|
|
45059
|
+
}
|
|
45060
|
+
off += size;
|
|
45061
|
+
}
|
|
45062
|
+
}
|
|
45063
|
+
walk(0, buf.length);
|
|
45064
|
+
const video = tracks.find((t)=>"vide" === t.handler) || tracks.find((t)=>t.width > 0 && t.height > 0);
|
|
45065
|
+
if (!movie || !video) return null;
|
|
45066
|
+
const movieData = movie;
|
|
45067
|
+
let { width, height } = video;
|
|
45068
|
+
if (90 === video.rotation || 270 === video.rotation) [width, height] = [
|
|
45069
|
+
height,
|
|
45070
|
+
width
|
|
45071
|
+
];
|
|
45072
|
+
return {
|
|
45073
|
+
width: Math.round(width),
|
|
45074
|
+
height: Math.round(height),
|
|
45075
|
+
duration: movieData.timescale ? movieData.duration / movieData.timescale : 0,
|
|
45076
|
+
rotation: video.rotation,
|
|
45077
|
+
fileSize: buf.length,
|
|
45078
|
+
codec: video.codec
|
|
45079
|
+
};
|
|
45080
|
+
}
|
|
45081
|
+
function parseStsdCodec(buf, start, end) {
|
|
45082
|
+
if (start + 16 > end) return null;
|
|
45083
|
+
return buf.toString("latin1", start + 12, start + 16).toLowerCase();
|
|
45084
|
+
}
|
|
45085
|
+
function parseMvhd(buf, start, end) {
|
|
45086
|
+
const version = buf.readUInt8(start);
|
|
45087
|
+
if (1 === version) {
|
|
45088
|
+
if (start + 28 > end) return null;
|
|
45089
|
+
const timescale = buf.readUInt32BE(start + 20);
|
|
45090
|
+
const hi = buf.readUInt32BE(start + 24);
|
|
45091
|
+
const lo = buf.readUInt32BE(start + 28);
|
|
45092
|
+
return {
|
|
45093
|
+
timescale,
|
|
45094
|
+
duration: hi * 2 ** 32 + lo
|
|
45095
|
+
};
|
|
45096
|
+
}
|
|
45097
|
+
if (start + 20 > end) return null;
|
|
45098
|
+
return {
|
|
45099
|
+
timescale: buf.readUInt32BE(start + 12),
|
|
45100
|
+
duration: buf.readUInt32BE(start + 16)
|
|
45101
|
+
};
|
|
45102
|
+
}
|
|
45103
|
+
function parseTkhd(buf, start, end) {
|
|
45104
|
+
const version = buf.readUInt8(start);
|
|
45105
|
+
const afterDuration = 1 === version ? 36 : 24;
|
|
45106
|
+
const matrixOff = start + afterDuration + 16;
|
|
45107
|
+
const whOff = matrixOff + 36;
|
|
45108
|
+
if (whOff + 8 > end) return {
|
|
45109
|
+
width: 0,
|
|
45110
|
+
height: 0,
|
|
45111
|
+
rotation: 0
|
|
45112
|
+
};
|
|
45113
|
+
const width = buf.readUInt32BE(whOff) / 65536;
|
|
45114
|
+
const height = buf.readUInt32BE(whOff + 4) / 65536;
|
|
45115
|
+
const a = buf.readInt32BE(matrixOff) / 65536;
|
|
45116
|
+
const b = buf.readInt32BE(matrixOff + 4) / 65536;
|
|
45117
|
+
let rotation = 0;
|
|
45118
|
+
if (Math.abs(a) < 0.01 && Math.abs(b - 1) < 0.01) rotation = 90;
|
|
45119
|
+
else if (Math.abs(a + 1) < 0.01 && Math.abs(b) < 0.01) rotation = 180;
|
|
45120
|
+
else if (Math.abs(a) < 0.01 && Math.abs(b + 1) < 0.01) rotation = 270;
|
|
45121
|
+
return {
|
|
45122
|
+
width,
|
|
45123
|
+
height,
|
|
45124
|
+
rotation
|
|
45125
|
+
};
|
|
45126
|
+
}
|
|
45127
|
+
const MAX_DURATION_SECONDS = 28800;
|
|
45128
|
+
const MAX_FILE_SIZE = 21474836480;
|
|
45129
|
+
const ALLOWED_EXTENSIONS = [
|
|
45130
|
+
".mp4"
|
|
45131
|
+
];
|
|
45132
|
+
const ALLOWED_CODECS = [
|
|
45133
|
+
"avc1",
|
|
45134
|
+
"avc3"
|
|
45135
|
+
];
|
|
45136
|
+
const MIN_TITLE_LENGTH = 6;
|
|
45137
|
+
function formatFileSize(bytes) {
|
|
45138
|
+
if (bytes < 1048576) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
45139
|
+
if (bytes < 1073741824) return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
45140
|
+
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
45141
|
+
}
|
|
45142
|
+
function formatDuration(seconds) {
|
|
45143
|
+
const total = Math.round(seconds);
|
|
45144
|
+
const h = Math.floor(total / 3600);
|
|
45145
|
+
const m = Math.floor(total % 3600 / 60);
|
|
45146
|
+
const s = total % 60;
|
|
45147
|
+
if (h > 0) return `${h}小时${m}分${s}秒`;
|
|
45148
|
+
if (m > 0) return `${m}分${s}秒`;
|
|
45149
|
+
return `${s}秒`;
|
|
45150
|
+
}
|
|
45151
|
+
function validateShipinhaoVideo(filePath, meta) {
|
|
45152
|
+
const fileName = external_node_path_default().basename(filePath);
|
|
45153
|
+
const ext = external_node_path_default().extname(fileName).toLowerCase();
|
|
45154
|
+
if (!ALLOWED_EXTENSIONS.includes(ext)) return `视频格式不支持:${fileName}。视频号仅支持 MP4/H.264 格式,请转换后重试。`;
|
|
45155
|
+
if (meta.duration > MAX_DURATION_SECONDS) return `视频时长超过限制:${fileName}(${formatDuration(meta.duration)})。视频号视频时长不能超过 8 小时,请剪辑后重试。`;
|
|
45156
|
+
if (meta.fileSize > MAX_FILE_SIZE) return `视频大小超过限制:${fileName}(${formatFileSize(meta.fileSize)})。视频号视频不能超过 20GB,请压缩后重试。`;
|
|
45157
|
+
if (meta.codec && !ALLOWED_CODECS.includes(meta.codec)) return `视频编码不支持:${fileName}(${meta.codec})。视频号仅支持 H.264 编码,请转码后重试。`;
|
|
45158
|
+
return null;
|
|
45159
|
+
}
|
|
45160
|
+
function validateShipinhaoTitle(title) {
|
|
45161
|
+
if (void 0 === title) return null;
|
|
45162
|
+
const trimmed = title.trim();
|
|
45163
|
+
const length = [
|
|
45164
|
+
...trimmed
|
|
45165
|
+
].length;
|
|
45166
|
+
if (length < MIN_TITLE_LENGTH) return `视频号标题至少需要 ${MIN_TITLE_LENGTH} 个字符,请补充后重试。`;
|
|
45167
|
+
return null;
|
|
45168
|
+
}
|
|
45169
|
+
async function getTraceKey(auth, http, logger) {
|
|
45170
|
+
logger.info("[getTraceKey] 开始获取 traceKey...");
|
|
45171
|
+
const res = await http.api({
|
|
45172
|
+
method: "POST",
|
|
45173
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/get-finder-post-trace-key",
|
|
45174
|
+
data: {
|
|
45175
|
+
objectId: "",
|
|
45176
|
+
timestamp: String(Date.now()),
|
|
45177
|
+
_log_finder_uin: "",
|
|
45178
|
+
_log_finder_id: auth.finderUsername,
|
|
45179
|
+
rawKeyBuff: "",
|
|
45180
|
+
pluginSessionId: null,
|
|
45181
|
+
scene: 7,
|
|
45182
|
+
reqScene: 7
|
|
45183
|
+
},
|
|
45184
|
+
defaultErrorMsg: "获取 traceKey 失败"
|
|
45185
|
+
});
|
|
45186
|
+
if (0 !== res.errCode || !res.data?.traceKey) {
|
|
45187
|
+
logger.error("[getTraceKey] 获取失败:", JSON.stringify(res));
|
|
45188
|
+
throw new Error(`获取 traceKey 失败: ${JSON.stringify(res)}`);
|
|
45189
|
+
}
|
|
45190
|
+
logger.info(`[getTraceKey] 获取成功: ${res.data.traceKey}`);
|
|
45191
|
+
return res.data.traceKey;
|
|
45192
|
+
}
|
|
45193
|
+
async function submitAndPollTranscode(opts) {
|
|
45194
|
+
const { videoUrl, videoMeta, traceKey, uploadStartTime, uploadEndTime, finderUsername, http, logger } = opts;
|
|
45195
|
+
logger.info("[submitAndPollTranscode] 开始提交转码任务...");
|
|
45196
|
+
const finderUrl = videoUrl.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${videoUrl.split("qq.com")[1]}` : videoUrl;
|
|
45197
|
+
logger.info(`[submitAndPollTranscode] 视频URL: ${finderUrl}`);
|
|
45198
|
+
logger.info(`[submitAndPollTranscode] 视频尺寸: ${videoMeta.width}x${videoMeta.height}, 时长: ${videoMeta.duration}s`);
|
|
45199
|
+
const submitRes = await http.api({
|
|
45200
|
+
method: "POST",
|
|
45201
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/post_clip_video",
|
|
45202
|
+
data: {
|
|
45203
|
+
url: finderUrl,
|
|
45204
|
+
timeStart: 0,
|
|
45205
|
+
cropDuration: 0,
|
|
45206
|
+
height: videoMeta.height,
|
|
45207
|
+
width: videoMeta.width,
|
|
45208
|
+
x: 0,
|
|
45209
|
+
y: 0,
|
|
45210
|
+
clipOriginVideoInfo: {
|
|
45211
|
+
width: videoMeta.width,
|
|
45212
|
+
height: videoMeta.height,
|
|
45213
|
+
duration: videoMeta.duration,
|
|
45214
|
+
fileSize: videoMeta.fileSize
|
|
45215
|
+
},
|
|
45216
|
+
traceInfo: {
|
|
45217
|
+
traceKey,
|
|
45218
|
+
uploadCdnStart: uploadStartTime,
|
|
45219
|
+
uploadCdnEnd: uploadEndTime
|
|
45220
|
+
},
|
|
45221
|
+
targetWidth: videoMeta.width,
|
|
45222
|
+
targetHeight: videoMeta.height,
|
|
45223
|
+
type: 4,
|
|
45224
|
+
useAstraThumbCover: 1,
|
|
45225
|
+
timestamp: String(Date.now()),
|
|
45226
|
+
_log_finder_uin: "",
|
|
45227
|
+
_log_finder_id: finderUsername,
|
|
45228
|
+
rawKeyBuff: "",
|
|
45229
|
+
pluginSessionId: null,
|
|
45230
|
+
scene: 7,
|
|
45231
|
+
reqScene: 7
|
|
45232
|
+
},
|
|
45233
|
+
defaultErrorMsg: "提交转码失败"
|
|
45234
|
+
});
|
|
45235
|
+
if (0 !== submitRes.errCode || !submitRes.data?.clipKey) {
|
|
45236
|
+
logger.error("[submitAndPollTranscode] 提交转码失败:", JSON.stringify(submitRes));
|
|
45237
|
+
throw new Error(`提交转码失败: ${JSON.stringify(submitRes)}`);
|
|
45238
|
+
}
|
|
45239
|
+
const { clipKey, draftId } = submitRes.data;
|
|
45240
|
+
logger.info(`[submitAndPollTranscode] 转码任务已提交,clipKey: ${clipKey}, draftId: ${draftId}`);
|
|
45241
|
+
const maxPolls = 60;
|
|
45242
|
+
const pollInterval = 5000;
|
|
45243
|
+
let pollCount = 0;
|
|
45244
|
+
logger.info(`[submitAndPollTranscode] 开始轮询转码结果,最多 ${maxPolls} 次,间隔 ${pollInterval / 1000}s`);
|
|
45245
|
+
while(pollCount < maxPolls){
|
|
45246
|
+
await mock_sleep(pollInterval);
|
|
45247
|
+
pollCount++;
|
|
45248
|
+
const pollRes = await http.api({
|
|
45249
|
+
method: "POST",
|
|
45250
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/post_clip_video_result",
|
|
45251
|
+
data: {
|
|
45252
|
+
clipKey,
|
|
45253
|
+
draftId,
|
|
45254
|
+
timestamp: String(Date.now()),
|
|
45255
|
+
_log_finder_uin: "",
|
|
45256
|
+
_log_finder_id: finderUsername,
|
|
45257
|
+
rawKeyBuff: "",
|
|
45258
|
+
pluginSessionId: null,
|
|
45259
|
+
scene: 7,
|
|
45260
|
+
reqScene: 7
|
|
45261
|
+
},
|
|
45262
|
+
defaultErrorMsg: "转码轮询失败"
|
|
45263
|
+
});
|
|
45264
|
+
if (0 !== pollRes.errCode) {
|
|
45265
|
+
logger.error(`[submitAndPollTranscode] 转码轮询失败 (poll ${pollCount}):`, JSON.stringify(pollRes));
|
|
45266
|
+
throw new Error(`转码轮询失败 (poll ${pollCount}): ${JSON.stringify(pollRes)}`);
|
|
45267
|
+
}
|
|
45268
|
+
const { flag, url, width, height, duration, md5, fileSize } = pollRes.data || {};
|
|
45269
|
+
logger.info(`[submitAndPollTranscode] 轮询第 ${pollCount} 次,flag=${flag}`);
|
|
45270
|
+
if (1 === flag) {
|
|
45271
|
+
if (!url || !width || !height || !duration || !md5 || !fileSize) {
|
|
45272
|
+
logger.error("[submitAndPollTranscode] 转码完成但返回数据不完整:", JSON.stringify(pollRes.data));
|
|
45273
|
+
throw new Error(`转码完成但返回数据不完整: ${JSON.stringify(pollRes.data)}`);
|
|
45274
|
+
}
|
|
45275
|
+
logger.info(`[submitAndPollTranscode] 转码完成! 用时: ${pollCount * pollInterval / 1000}s`);
|
|
45276
|
+
logger.info(`[submitAndPollTranscode] 视频信息: ${width}x${height}, 时长: ${duration}s, 大小: ${fileSize}`);
|
|
45277
|
+
return {
|
|
45278
|
+
clipKey,
|
|
45279
|
+
url,
|
|
45280
|
+
width,
|
|
45281
|
+
height,
|
|
45282
|
+
duration,
|
|
45283
|
+
md5,
|
|
45284
|
+
fileSize
|
|
45285
|
+
};
|
|
45286
|
+
}
|
|
45287
|
+
if (2 === flag) logger.info(`[submitAndPollTranscode] 转码中... (${pollCount}/${maxPolls})`);
|
|
45288
|
+
else {
|
|
45289
|
+
logger.error(`[submitAndPollTranscode] 转码失败,未知 flag=${flag}:`, JSON.stringify(pollRes.data));
|
|
45290
|
+
throw new Error(`转码失败,未知 flag=${flag}: ${JSON.stringify(pollRes.data)}`);
|
|
45291
|
+
}
|
|
45292
|
+
}
|
|
45293
|
+
logger.error(`[submitAndPollTranscode] 转码超时,已轮询 ${maxPolls} 次,用时: ${maxPolls * pollInterval / 1000}s`);
|
|
45294
|
+
throw new Error(`转码超时 (${maxPolls * pollInterval / 1000}s)`);
|
|
45295
|
+
}
|
|
45296
|
+
async function publishVideo(opts) {
|
|
45297
|
+
const { params, auth, clipResult, videoUpload, coverUpload, traceKey, uploadStartTime, uploadEndTime, proxyHttp, logger } = opts;
|
|
45298
|
+
logger.info("[publishVideo] 开始构建发布请求...");
|
|
45299
|
+
const coverFinderUrl = coverUpload.downloadUrl.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${coverUpload.downloadUrl.split("qq.com")[1]}` : coverUpload.downloadUrl;
|
|
45300
|
+
logger.info(`[publishVideo] 封面URL: ${coverFinderUrl}`);
|
|
45301
|
+
const md5sumUuid = external_node_crypto_default().randomUUID();
|
|
45302
|
+
logger.info("[publishVideo] 发布参数:");
|
|
45303
|
+
logger.info(` - 标题: ${params.title || "(无)"}`);
|
|
45304
|
+
logger.info(` - 描述: ${params.description?.substring(0, 50)}${params.description?.length > 50 ? "..." : ""}`);
|
|
45305
|
+
logger.info(` - 定时发布: ${params.scheduleTime ? new Date(1000 * params.scheduleTime).toLocaleString() : "立即发布"}`);
|
|
45306
|
+
logger.info(` - 地理位置: ${params.location ? `${params.location.city} (${params.location.latitude},${params.location.longitude})` : "(无)"}`);
|
|
45307
|
+
const publishRes = await proxyHttp.api({
|
|
45308
|
+
method: "POST",
|
|
45309
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/post_create",
|
|
45310
|
+
data: {
|
|
45311
|
+
objectType: 0,
|
|
45312
|
+
longitude: params.location?.longitude || 0,
|
|
45313
|
+
latitude: params.location?.latitude || 0,
|
|
45314
|
+
feedLongitude: 0,
|
|
45315
|
+
feedLatitude: 0,
|
|
45316
|
+
originalFlag: 0,
|
|
45317
|
+
topics: [],
|
|
45318
|
+
isFullPost: 1,
|
|
45319
|
+
handleFlag: 2,
|
|
45320
|
+
videoClipTaskId: clipResult.clipKey,
|
|
45321
|
+
traceInfo: {
|
|
45322
|
+
traceKey,
|
|
45323
|
+
uploadCdnStart: uploadStartTime,
|
|
45324
|
+
uploadCdnEnd: uploadEndTime
|
|
45325
|
+
},
|
|
45326
|
+
objectDesc: {
|
|
45327
|
+
mpTitle: "",
|
|
45328
|
+
description: params.description,
|
|
45329
|
+
shortTitle: params.title || "",
|
|
45330
|
+
extReading: {},
|
|
45331
|
+
mediaType: 4,
|
|
45332
|
+
location: params.location ? {
|
|
45333
|
+
latitude: params.location.latitude,
|
|
45334
|
+
longitude: params.location.longitude,
|
|
45335
|
+
city: params.location.city,
|
|
45336
|
+
poiClassifyId: params.location.poiClassifyId || ""
|
|
45337
|
+
} : {
|
|
45338
|
+
latitude: 0,
|
|
45339
|
+
longitude: 0,
|
|
45340
|
+
city: "",
|
|
45341
|
+
poiClassifyId: ""
|
|
45342
|
+
},
|
|
45343
|
+
topic: {
|
|
45344
|
+
finderTopicInfo: `<finder><version>1</version><valuecount>1</valuecount><style><at></at></style><value0><![CDATA[${params.description}]]></value0></finder>`
|
|
45345
|
+
},
|
|
45346
|
+
event: {},
|
|
45347
|
+
mentionedUser: [],
|
|
45348
|
+
media: [
|
|
45349
|
+
{
|
|
45350
|
+
url: clipResult.url,
|
|
45351
|
+
fileSize: clipResult.fileSize,
|
|
45352
|
+
thumbUrl: coverFinderUrl,
|
|
45353
|
+
fullThumbUrl: coverFinderUrl,
|
|
45354
|
+
coverUrl: coverFinderUrl,
|
|
45355
|
+
fullCoverUrl: coverFinderUrl,
|
|
45356
|
+
shareCoverUrl: coverFinderUrl,
|
|
45357
|
+
mediaType: 4,
|
|
45358
|
+
videoPlayLen: Math.round(clipResult.duration),
|
|
45359
|
+
width: clipResult.width,
|
|
45360
|
+
height: clipResult.height,
|
|
45361
|
+
md5sum: md5sumUuid,
|
|
45362
|
+
cardShowStyle: 2,
|
|
45363
|
+
urlCdnTaskId: clipResult.clipKey
|
|
45364
|
+
}
|
|
45365
|
+
],
|
|
45366
|
+
member: {}
|
|
45367
|
+
},
|
|
45368
|
+
effectiveTime: params.scheduleTime || 0,
|
|
45369
|
+
report: {
|
|
45370
|
+
clipKey: clipResult.clipKey,
|
|
45371
|
+
draftId: clipResult.clipKey,
|
|
45372
|
+
timestamp: String(Date.now()),
|
|
45373
|
+
_log_finder_uin: "",
|
|
45374
|
+
_log_finder_id: auth.finderUsername,
|
|
45375
|
+
rawKeyBuff: "",
|
|
45376
|
+
pluginSessionId: null,
|
|
45377
|
+
scene: 7,
|
|
45378
|
+
reqScene: 7,
|
|
45379
|
+
height: clipResult.height,
|
|
45380
|
+
width: clipResult.width,
|
|
45381
|
+
duration: clipResult.duration,
|
|
45382
|
+
fileSize: videoUpload.fileSize,
|
|
45383
|
+
uploadCost: (uploadEndTime - uploadStartTime) * 1000
|
|
45384
|
+
},
|
|
45385
|
+
postFlag: 0,
|
|
45386
|
+
mode: 1,
|
|
45387
|
+
clientid: external_node_crypto_default().randomUUID(),
|
|
45388
|
+
timestamp: String(Date.now()),
|
|
45389
|
+
_log_finder_uin: "",
|
|
45390
|
+
_log_finder_id: auth.finderUsername,
|
|
45391
|
+
rawKeyBuff: "",
|
|
45392
|
+
pluginSessionId: null,
|
|
45393
|
+
scene: 7,
|
|
45394
|
+
reqScene: 7
|
|
45395
|
+
},
|
|
45396
|
+
defaultErrorMsg: "发布视频失败"
|
|
45397
|
+
});
|
|
45398
|
+
logger.info(`[publishVideo] 发布响应: errCode=${publishRes.errCode}, baseResp.errcode=${publishRes.data?.baseResp?.errcode}`);
|
|
45399
|
+
return publishRes;
|
|
45400
|
+
}
|
|
45401
|
+
function mock_sleep(ms) {
|
|
45402
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
45403
|
+
}
|
|
45404
|
+
const shipinhaoPublishVideo_mock_mockAction = async (task, params)=>{
|
|
45405
|
+
task.logger.info("[shipinhaoPublishVideo] 开始执行视频号视频发布 - Mock API 方式");
|
|
45406
|
+
const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
|
|
45407
|
+
let currentStep = "初始化";
|
|
45408
|
+
try {
|
|
45409
|
+
currentStep = "解析认证信息";
|
|
45410
|
+
const cookieString = params.cookies.map((c)=>`${c.name}=${c.value}`).join("; ");
|
|
45411
|
+
const headers = {
|
|
45412
|
+
cookie: cookieString
|
|
45413
|
+
};
|
|
45414
|
+
const args = [
|
|
45415
|
+
{
|
|
45416
|
+
headers
|
|
45417
|
+
},
|
|
45418
|
+
task.logger,
|
|
45419
|
+
params.proxyLoc,
|
|
45420
|
+
params.accountId,
|
|
45421
|
+
"shipinhao"
|
|
45422
|
+
];
|
|
45423
|
+
const http = new Http({
|
|
45424
|
+
headers
|
|
45425
|
+
});
|
|
45426
|
+
const proxyHttp = new Http(...args);
|
|
45427
|
+
currentStep = "验证发布参数";
|
|
45428
|
+
if (!params.videoPath) return utils_response(414, "视频文件路径不能为空", "");
|
|
45429
|
+
if (!params.coverPath) return utils_response(414, "封面图片路径不能为空", "");
|
|
45430
|
+
currentStep = "获取上传认证";
|
|
45431
|
+
task.logger.info("[shipinhaoPublishVideo] 获取上传认证...");
|
|
45432
|
+
const auth = await getShipinhaoUploadAuth(cookieString, http);
|
|
45433
|
+
currentStep = "解析视频元数据";
|
|
45434
|
+
task.logger.info("[shipinhaoPublishVideo] 解析视频元数据...");
|
|
45435
|
+
const videoMeta = parseVideoMeta(params.videoPath);
|
|
45436
|
+
if (!videoMeta) return utils_response(414, "视频文件解析失败,请检查文件格式(仅支持 MP4)", "");
|
|
45437
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
45438
|
+
currentStep = "校验视频限制";
|
|
45439
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
45440
|
+
if (validationError) {
|
|
45441
|
+
task.logger.error(`[shipinhaoPublishVideo] 视频校验未通过: ${validationError}`);
|
|
45442
|
+
await updateTaskState?.({
|
|
45443
|
+
state: types_TaskState.FAILED,
|
|
45444
|
+
error: validationError
|
|
45445
|
+
});
|
|
45446
|
+
return utils_response(414, validationError, "");
|
|
45447
|
+
}
|
|
45448
|
+
task.logger.info("[shipinhaoPublishVideo] 视频校验通过");
|
|
45449
|
+
currentStep = "校验标题";
|
|
45450
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
45451
|
+
if (titleError) {
|
|
45452
|
+
task.logger.error(`[shipinhaoPublishVideo] 标题校验未通过: ${titleError}`);
|
|
45453
|
+
await updateTaskState?.({
|
|
45454
|
+
state: types_TaskState.FAILED,
|
|
45455
|
+
error: titleError
|
|
45456
|
+
});
|
|
45457
|
+
return utils_response(414, titleError, "");
|
|
45458
|
+
}
|
|
45459
|
+
currentStep = "获取 traceKey";
|
|
45460
|
+
task.logger.info("[shipinhaoPublishVideo] 获取 traceKey...");
|
|
45461
|
+
const traceKey = await getTraceKey(auth, http, task.logger);
|
|
45462
|
+
const uploadStartTime = Math.floor(Date.now() / 1000);
|
|
45463
|
+
task.logger.info(`[shipinhaoPublishVideo] 上传开始时间: ${uploadStartTime}`);
|
|
45464
|
+
currentStep = "上传视频";
|
|
45465
|
+
task.logger.info("[shipinhaoPublishVideo] 上传视频...");
|
|
45466
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频路径: ${params.videoPath}`);
|
|
45467
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频文件类型: ${auth.videoFileType}`);
|
|
45468
|
+
const videoUpload = await uploader_uploadFile({
|
|
45469
|
+
filePath: params.videoPath,
|
|
45470
|
+
fileType: auth.videoFileType,
|
|
45471
|
+
uin: auth.uin,
|
|
45472
|
+
authKey: auth.authKey,
|
|
45473
|
+
http,
|
|
45474
|
+
logger: task.logger
|
|
45475
|
+
});
|
|
45476
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频上传完成,URL: ${videoUpload.downloadUrl}`);
|
|
45477
|
+
const uploadEndTime = Math.floor(Date.now() / 1000);
|
|
45478
|
+
task.logger.info(`[shipinhaoPublishVideo] 上传结束时间: ${uploadEndTime}, 耗时: ${uploadEndTime - uploadStartTime}s`);
|
|
45479
|
+
currentStep = "上传封面";
|
|
45480
|
+
task.logger.info("[shipinhaoPublishVideo] 上传封面...");
|
|
45481
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面路径: ${params.coverPath}`);
|
|
45482
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面文件类型: ${auth.pictureFileType}`);
|
|
45483
|
+
const coverUpload = await uploader_uploadFile({
|
|
45484
|
+
filePath: params.coverPath,
|
|
45485
|
+
fileType: auth.pictureFileType,
|
|
45486
|
+
uin: auth.uin,
|
|
45487
|
+
authKey: auth.authKey,
|
|
45488
|
+
http,
|
|
45489
|
+
logger: task.logger
|
|
45490
|
+
});
|
|
45491
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面上传完成,URL: ${coverUpload.downloadUrl}`);
|
|
45492
|
+
currentStep = "提交转码";
|
|
45493
|
+
task.logger.info("[shipinhaoPublishVideo] 提交转码...");
|
|
45494
|
+
const clipResult = await submitAndPollTranscode({
|
|
45495
|
+
videoUrl: videoUpload.downloadUrl,
|
|
45496
|
+
videoMeta,
|
|
45497
|
+
traceKey,
|
|
45498
|
+
uploadStartTime,
|
|
45499
|
+
uploadEndTime,
|
|
45500
|
+
finderUsername: auth.finderUsername,
|
|
45501
|
+
http,
|
|
45502
|
+
logger: task.logger
|
|
45503
|
+
});
|
|
45504
|
+
currentStep = "发布视频";
|
|
45505
|
+
task.logger.info("[shipinhaoPublishVideo] 发布视频...");
|
|
45506
|
+
task.logger.info(`[shipinhaoPublishVideo] clipKey: ${clipResult.clipKey}`);
|
|
45507
|
+
let publishResult;
|
|
45508
|
+
try {
|
|
45509
|
+
publishResult = await publishVideo({
|
|
45510
|
+
params,
|
|
45511
|
+
auth,
|
|
45512
|
+
clipResult,
|
|
45513
|
+
videoUpload,
|
|
45514
|
+
coverUpload,
|
|
45515
|
+
traceKey,
|
|
45516
|
+
uploadStartTime,
|
|
45517
|
+
uploadEndTime,
|
|
45518
|
+
proxyHttp,
|
|
45519
|
+
logger: task.logger
|
|
45520
|
+
});
|
|
45521
|
+
} catch (error) {
|
|
45522
|
+
const handledError = Http.handleApiError(error);
|
|
45523
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布请求失败: ${handledError.message}`, stringifyError(handledError));
|
|
45524
|
+
const classified = classifyPublishError(handledError);
|
|
45525
|
+
if (classified) {
|
|
45526
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
45527
|
+
task.logger.error(`[shipinhaoPublishVideo] ${classified.category},直接返回: ${handledError.message} (code=${handledError.code})`, stringifyError(handledError));
|
|
45528
|
+
await updateTaskState?.({
|
|
45529
|
+
state: types_TaskState.FAILED,
|
|
45530
|
+
error: message
|
|
45531
|
+
});
|
|
45532
|
+
return {
|
|
45533
|
+
code: 414,
|
|
45534
|
+
data: "",
|
|
45535
|
+
message
|
|
45536
|
+
};
|
|
45537
|
+
}
|
|
45538
|
+
throw error;
|
|
45539
|
+
}
|
|
45540
|
+
task.logger.info(`[shipinhaoPublishVideo] publishResult: ${JSON.stringify(publishResult)}`);
|
|
45541
|
+
const resultCode = publishResult.data?.baseResp?.errcode ?? publishResult.errCode;
|
|
45542
|
+
const resultMsg = publishResult.data?.baseResp?.errmsg ?? "发布成功";
|
|
45543
|
+
if (0 === resultCode) {
|
|
45544
|
+
task.logger.info("[shipinhaoPublishVideo] 发布成功");
|
|
45545
|
+
task.logger.info(`[shipinhaoPublishVideo] 作品ID: ${clipResult.clipKey}`);
|
|
45546
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频URL: ${clipResult.url}`);
|
|
45547
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面URL: ${coverUpload.downloadUrl}`);
|
|
45548
|
+
await updateTaskState?.({
|
|
45549
|
+
state: types_TaskState.SUCCESS,
|
|
45550
|
+
result: {
|
|
45551
|
+
response: resultMsg
|
|
45552
|
+
}
|
|
45553
|
+
});
|
|
45554
|
+
reportLogger({
|
|
45555
|
+
token: params.huiwenToken || "",
|
|
45556
|
+
enverionment: task.enverionment || "development",
|
|
45557
|
+
postId: params.articleId,
|
|
45558
|
+
eip: proxyHttp.proxyInfo,
|
|
45559
|
+
accountId: params.accountId,
|
|
45560
|
+
uid: params.uid,
|
|
45561
|
+
publishParams: {
|
|
45562
|
+
videoPath: params.videoPath,
|
|
45563
|
+
coverPath: params.coverPath
|
|
45564
|
+
},
|
|
45565
|
+
platform: "shipinhao"
|
|
45566
|
+
});
|
|
45567
|
+
task.logger.info("[shipinhaoPublishVideo] 日志上报完成");
|
|
45568
|
+
return utils_response(0, "发布成功", clipResult.clipKey);
|
|
45569
|
+
}
|
|
45570
|
+
let errorMessage = resultMsg;
|
|
45571
|
+
if (-11224 === resultCode) errorMessage = "视频号管理员完成实名且绑定手机号后才可以发表";
|
|
45572
|
+
else if (300333 === resultCode || 300334 === resultCode) errorMessage = "登录失效";
|
|
45573
|
+
else if (300330 === resultCode) errorMessage = "未登录";
|
|
45574
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布失败: ${errorMessage} (errCode=${resultCode})`);
|
|
45575
|
+
await updateTaskState?.({
|
|
45576
|
+
state: types_TaskState.FAILED,
|
|
45577
|
+
error: errorMessage
|
|
45578
|
+
});
|
|
45579
|
+
return utils_response(resultCode || 414, errorMessage, "");
|
|
45580
|
+
} catch (error) {
|
|
45581
|
+
const handledError = Http.handleApiError(error);
|
|
45582
|
+
const errorMsg = handledError.message || "发布失败,请稍后重试";
|
|
45583
|
+
const errorCode = handledError.code || 414;
|
|
45584
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布流程异常 [${currentStep}]: ${errorMsg}`, stringifyError(error), handledError.extra);
|
|
45585
|
+
task.logger.error(`[shipinhaoPublishVideo] 错误码: ${errorCode}, 当前步骤: ${currentStep}`);
|
|
45586
|
+
await updateTaskState?.({
|
|
45587
|
+
state: types_TaskState.FAILED,
|
|
45588
|
+
error: errorMsg
|
|
45589
|
+
});
|
|
45590
|
+
return utils_response(errorCode, errorMsg, "");
|
|
45591
|
+
}
|
|
45592
|
+
};
|
|
45593
|
+
const shipinhaoPublishVideo_rpa_rpaAction = async (task, params)=>{
|
|
45594
|
+
task.logger.info("开始微信视频号视频发布(RPA 模式)");
|
|
45595
|
+
const videoMeta = parseVideoMeta(params.videoPath);
|
|
45596
|
+
if (!videoMeta) return utils_response(414, "视频文件解析失败,请检查文件格式(仅支持 MP4)", "");
|
|
45597
|
+
task.logger.info(`视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
45598
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
45599
|
+
if (validationError) {
|
|
45600
|
+
task.logger.error(`视频校验未通过: ${validationError}`);
|
|
45601
|
+
return utils_response(414, validationError, "");
|
|
45602
|
+
}
|
|
45603
|
+
task.logger.info("视频校验通过");
|
|
45604
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
45605
|
+
if (titleError) {
|
|
45606
|
+
task.logger.error(`标题校验未通过: ${titleError}`);
|
|
45607
|
+
return utils_response(414, titleError, "");
|
|
45608
|
+
}
|
|
45609
|
+
const tmpCachePath = task.getTmpPath();
|
|
45610
|
+
const page = await task.createPage({
|
|
45611
|
+
url: "https://channels.weixin.qq.com/platform/post/create",
|
|
45612
|
+
show: task.debug,
|
|
45613
|
+
cookies: params.cookies
|
|
45614
|
+
});
|
|
45615
|
+
try {
|
|
45616
|
+
const waitForElement = async (selector, timeout = 10000)=>{
|
|
45617
|
+
try {
|
|
45618
|
+
const element = page.locator(selector);
|
|
45619
|
+
await element.waitFor({
|
|
45620
|
+
state: "visible",
|
|
45621
|
+
timeout
|
|
45622
|
+
});
|
|
45623
|
+
return element;
|
|
45624
|
+
} catch {
|
|
45625
|
+
task.logger.warn(`元素未找到: ${selector}`);
|
|
45626
|
+
return null;
|
|
45627
|
+
}
|
|
45628
|
+
};
|
|
45629
|
+
const retryAction = async (action, maxRetries = 3, delay = 1000)=>{
|
|
45630
|
+
let lastError;
|
|
45631
|
+
for(let i = 0; i < maxRetries; i++)try {
|
|
45632
|
+
return await action();
|
|
45633
|
+
} catch (error) {
|
|
45634
|
+
lastError = error;
|
|
45635
|
+
task.logger.warn(`重试 ${i + 1}/${maxRetries}: ${lastError.message}`);
|
|
45636
|
+
if (i < maxRetries - 1) await page.waitForTimeout(delay);
|
|
45637
|
+
}
|
|
45638
|
+
throw lastError;
|
|
45639
|
+
};
|
|
45640
|
+
task.logger.info("等待页面加载...");
|
|
45641
|
+
task.logger.info("检查登录状态...");
|
|
45642
|
+
if (task.debug) {
|
|
45643
|
+
task.logger.info(`当前页面 URL: ${page.url()}`);
|
|
45644
|
+
const title = await page.title();
|
|
45645
|
+
task.logger.info(`页面标题: ${title}`);
|
|
45646
|
+
}
|
|
45647
|
+
try {
|
|
45648
|
+
await page.waitForSelector(".post-edit-wrap", {
|
|
45649
|
+
state: "visible",
|
|
45650
|
+
timeout: 30000
|
|
45651
|
+
});
|
|
45652
|
+
task.logger.info("✓ 登录状态正常,找到编辑器容器");
|
|
45653
|
+
} catch {
|
|
45654
|
+
task.logger.error("✗ 未找到编辑器,可能登录失效");
|
|
45655
|
+
return {
|
|
45656
|
+
code: 414,
|
|
45657
|
+
message: "登录失效或页面加载异常",
|
|
45658
|
+
data: page.url()
|
|
45659
|
+
};
|
|
45660
|
+
}
|
|
45661
|
+
task.logger.info("页面加载完成,开始填充内容");
|
|
45662
|
+
task.logger.info("开始上传视频");
|
|
45663
|
+
await retryAction(async ()=>{
|
|
45664
|
+
const videoUploadSelectors = [
|
|
45665
|
+
'.ant-upload-btn input[type="file"][accept*="video"]',
|
|
45666
|
+
'.upload input[type="file"][accept*="video"]',
|
|
45667
|
+
'input[type="file"][accept*="video"]'
|
|
45668
|
+
];
|
|
45669
|
+
let uploadInput = null;
|
|
45670
|
+
if (task.debug) {
|
|
45671
|
+
const allFileInputs = await page.locator('input[type="file"]').count();
|
|
45672
|
+
task.logger.info(`页面中共找到 ${allFileInputs} 个文件上传输入框`);
|
|
45673
|
+
}
|
|
45674
|
+
for (const selector of videoUploadSelectors){
|
|
45675
|
+
const input = page.locator(selector);
|
|
45676
|
+
const count = await input.count();
|
|
45677
|
+
if (count > 0) {
|
|
45678
|
+
uploadInput = input.first();
|
|
45679
|
+
task.logger.info(`找到视频上传输入框: ${selector}`);
|
|
45680
|
+
break;
|
|
45681
|
+
}
|
|
45682
|
+
}
|
|
45683
|
+
if (!uploadInput) {
|
|
45684
|
+
task.logger.warn("未找到视频上传输入框,等待 3 秒后重试...");
|
|
45685
|
+
await page.waitForTimeout(3000);
|
|
45686
|
+
const anyFileInput = page.locator('input[type="file"]');
|
|
45687
|
+
const inputCount = await anyFileInput.count();
|
|
45688
|
+
if (inputCount > 0) {
|
|
45689
|
+
uploadInput = anyFileInput.first();
|
|
45690
|
+
task.logger.info(`找到文件输入框(共 ${inputCount} 个)`);
|
|
45691
|
+
} else {
|
|
45692
|
+
if (task.debug) {
|
|
45693
|
+
const screenshotPath = external_node_path_default().join(tmpCachePath, `upload-error-${Date.now()}.png`);
|
|
45694
|
+
await page.screenshot({
|
|
45695
|
+
path: screenshotPath,
|
|
45696
|
+
fullPage: true
|
|
45697
|
+
});
|
|
45698
|
+
task.logger.error(`未找到上传输入框,已截图保存至: ${screenshotPath}`);
|
|
45699
|
+
}
|
|
45700
|
+
throw new Error("未找到视频上传输入框");
|
|
45701
|
+
}
|
|
45702
|
+
}
|
|
45703
|
+
await uploadInput.setInputFiles(params.videoPath);
|
|
45704
|
+
task.logger.info("视频上传成功");
|
|
45705
|
+
await page.waitForTimeout(5000);
|
|
45706
|
+
});
|
|
45707
|
+
if (params.coverPath) {
|
|
45708
|
+
task.logger.info("开始上传封面");
|
|
45709
|
+
await retryAction(async ()=>{
|
|
45710
|
+
const coverUploadBtn = await waitForElement(".cover-upload-btn", 10000);
|
|
45711
|
+
if (coverUploadBtn) {
|
|
45712
|
+
const coverInput = page.locator('.cover-upload-btn input[type="file"]');
|
|
45713
|
+
await coverInput.setInputFiles(params.coverPath);
|
|
45714
|
+
task.logger.info("封面上传成功");
|
|
45715
|
+
await page.waitForTimeout(2000);
|
|
45716
|
+
}
|
|
45717
|
+
});
|
|
45718
|
+
}
|
|
45719
|
+
if (params.description) {
|
|
45720
|
+
task.logger.info("填写视频描述");
|
|
45721
|
+
await retryAction(async ()=>{
|
|
45722
|
+
const descEditor = await waitForElement(".input-editor", 10000);
|
|
45723
|
+
if (!descEditor) throw new Error("未找到描述编辑器");
|
|
45724
|
+
await descEditor.click();
|
|
45725
|
+
await page.waitForTimeout(500);
|
|
45726
|
+
await descEditor.evaluate((el)=>{
|
|
45727
|
+
el.textContent = "";
|
|
45728
|
+
});
|
|
45729
|
+
await page.waitForTimeout(300);
|
|
45730
|
+
task.logger.info("已清空编辑器内容");
|
|
45731
|
+
await descEditor.pressSequentially(params.description, {
|
|
45732
|
+
delay: 10
|
|
45733
|
+
});
|
|
45734
|
+
await page.waitForTimeout(500);
|
|
45735
|
+
task.logger.info("描述填写完成");
|
|
45736
|
+
});
|
|
45737
|
+
}
|
|
45738
|
+
if (params.title) {
|
|
45739
|
+
task.logger.info(`填写标题: ${params.title}`);
|
|
45740
|
+
const title = params.title;
|
|
45741
|
+
await retryAction(async ()=>{
|
|
45742
|
+
const titleInput = await waitForElement("#container-wrap div.form-item-body.short-title-wrap input", 10000);
|
|
45743
|
+
if (!titleInput) throw new Error("未找到标题输入框");
|
|
45744
|
+
await titleInput.click();
|
|
45745
|
+
await titleInput.clear({
|
|
45746
|
+
timeout: 3000
|
|
45747
|
+
});
|
|
45748
|
+
await titleInput.fill(title, {
|
|
45749
|
+
timeout: 5000
|
|
45750
|
+
});
|
|
45751
|
+
task.logger.info("标题填写完成");
|
|
45752
|
+
});
|
|
45753
|
+
}
|
|
45754
|
+
if (params.location) {
|
|
45755
|
+
task.logger.info(`选择地点: ${params.location.city}`);
|
|
45756
|
+
const instance = page.locator(".position-display-wrap");
|
|
45757
|
+
await instance.click();
|
|
45758
|
+
await page.waitForTimeout(1000);
|
|
45759
|
+
await page.locator(".location-filter-wrap input").fill(params.location.city);
|
|
45760
|
+
await page.waitForTimeout(2000);
|
|
45761
|
+
const poperInstance = page.locator(".location-filter-wrap .common-option-list-wrap .option-item");
|
|
45762
|
+
await poperInstance.nth(1).waitFor();
|
|
45763
|
+
await poperInstance.nth(1).click();
|
|
45764
|
+
task.logger.info("地点选择完成");
|
|
45765
|
+
}
|
|
45766
|
+
if (params.scheduleTime) {
|
|
45767
|
+
task.logger.info("设置定时发布");
|
|
45768
|
+
const timingRadio = page.locator(".weui-desktop-form__check-label").filter({
|
|
45769
|
+
hasNotText: "不定时"
|
|
45770
|
+
}).first();
|
|
45771
|
+
await timingRadio.click();
|
|
45772
|
+
await page.waitForTimeout(500);
|
|
45773
|
+
const instance = page.locator(".weui-desktop-picker__date");
|
|
45774
|
+
await instance.click();
|
|
45775
|
+
const dateD = utils_TimeFormatter.format(1000 * params.scheduleTime, "d");
|
|
45776
|
+
const nowMonth = utils_TimeFormatter.format(Date.now(), "MM月");
|
|
45777
|
+
const nowMonthText = utils_TimeFormatter.format(Date.now(), "M月");
|
|
45778
|
+
const month = utils_TimeFormatter.format(1000 * params.scheduleTime, "MM月");
|
|
45779
|
+
const monthLocator = await page.locator("weui-desktop-picker__panel__label").filter({
|
|
45780
|
+
hasText: month
|
|
45781
|
+
}).first();
|
|
45782
|
+
if (!monthLocator) {
|
|
45783
|
+
await page.locator(".weui-desktop-picker__panel__label").filter({
|
|
45784
|
+
hasText: nowMonth
|
|
45785
|
+
}).first().click();
|
|
45786
|
+
await page.waitForTimeout(500);
|
|
45787
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
45788
|
+
hasText: nowMonthText
|
|
45789
|
+
}).first().click();
|
|
45790
|
+
}
|
|
45791
|
+
await page.waitForTimeout(500);
|
|
45792
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
45793
|
+
hasText: dateD
|
|
45794
|
+
}).first().click();
|
|
45795
|
+
await page.locator(".weui-desktop-form__input-wrp input[placeholder*='请选择时间']").fill(utils_TimeFormatter.format(1000 * params.scheduleTime, "hh:mm"));
|
|
45796
|
+
await page.locator("i.weui-desktop-icon__time").click();
|
|
45797
|
+
await page.locator(".post-time-wrap .form-item .label").filter({
|
|
45798
|
+
hasText: "发表时间"
|
|
45799
|
+
}).click();
|
|
45800
|
+
}
|
|
45801
|
+
task.logger.info("准备发布...");
|
|
45802
|
+
await page.waitForTimeout(300);
|
|
45803
|
+
let videoId = "";
|
|
45804
|
+
const handleResponse = async (response)=>{
|
|
45805
|
+
const url = response.url();
|
|
45806
|
+
if (url.includes("/post/post_create")) {
|
|
45807
|
+
const jsonResponse = await response.json();
|
|
45808
|
+
page.off("response", handleResponse);
|
|
45809
|
+
videoId = jsonResponse.object?.id || jsonResponse.data?.objectId || "";
|
|
45810
|
+
}
|
|
45811
|
+
};
|
|
45812
|
+
page.on("response", handleResponse);
|
|
45813
|
+
task._timerRecord.PrePublish = Date.now();
|
|
45814
|
+
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";
|
|
45815
|
+
task.logger.info("等待视频上传完成(预览区媒体操作栏出现)...");
|
|
45816
|
+
const uploadTimeout = 600000;
|
|
45817
|
+
const uploadWaitStart = Date.now();
|
|
45818
|
+
let lastProgressLog = 0;
|
|
45819
|
+
while(true){
|
|
45820
|
+
const ready = await page.evaluate((selector)=>{
|
|
45821
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
45822
|
+
const root = host?.shadowRoot;
|
|
45823
|
+
if (!root) return false;
|
|
45824
|
+
return !!root.querySelector(selector);
|
|
45825
|
+
}, MEDIA_OPR_SELECTOR);
|
|
45826
|
+
if (ready) break;
|
|
45827
|
+
const elapsed = Date.now() - uploadWaitStart;
|
|
45828
|
+
if (elapsed > uploadTimeout) throw new Error(`视频上传超时,预览区未就绪(已等待 ${Math.round(elapsed / 1000)}s)`);
|
|
45829
|
+
if (elapsed - lastProgressLog >= 15000) {
|
|
45830
|
+
lastProgressLog = elapsed;
|
|
45831
|
+
task.logger.info(`视频仍在上传中... 已等待 ${Math.round(elapsed / 1000)}s`);
|
|
45832
|
+
}
|
|
45833
|
+
await page.waitForTimeout(1000);
|
|
45834
|
+
}
|
|
45835
|
+
task.logger.info(`视频上传完成(等待 ${Math.round((Date.now() - uploadWaitStart) / 1000)}s)`);
|
|
45836
|
+
const clicked = await page.evaluate(()=>{
|
|
45837
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
45838
|
+
const root = host?.shadowRoot;
|
|
45839
|
+
if (!root) return "未找到 wujie-app shadowRoot";
|
|
45840
|
+
const btns = Array.from(root.querySelectorAll(".form-btns .weui-desktop-btn"));
|
|
45841
|
+
const target = btns.find((el)=>(el.textContent || "").includes("发表"));
|
|
45842
|
+
if (!target) return "未找到发表按钮";
|
|
45843
|
+
if (target.classList.contains("weui-desktop-btn_disabled")) return "发表按钮仍处于禁用状态";
|
|
45844
|
+
target.click();
|
|
45845
|
+
return null;
|
|
45846
|
+
});
|
|
45847
|
+
if (clicked) throw new Error(clicked);
|
|
45848
|
+
task.logger.info("已点击发布按钮,等待响应...");
|
|
45849
|
+
try {
|
|
45850
|
+
await page.waitForURL((url)=>url.href !== page.url(), {
|
|
45851
|
+
timeout: 30000
|
|
45852
|
+
});
|
|
45853
|
+
task.logger.info(`发布成功,页面已跳转: ${page.url()}`);
|
|
45854
|
+
} catch {
|
|
45855
|
+
task.logger.warn("等待页面跳转超时,可能发布失败或网络慢,继续关闭页面");
|
|
45856
|
+
}
|
|
45857
|
+
await page.close();
|
|
45858
|
+
return success(videoId, "发布成功");
|
|
45859
|
+
} catch (error) {
|
|
45860
|
+
let errorMsg = error instanceof Error ? error.message : String(error);
|
|
45861
|
+
if (errorMsg.includes("context or browser has been closed")) errorMsg = "浏览器上下文已被关闭";
|
|
45862
|
+
task.logger.error(`微信视频号视频发布失败: ${errorMsg}`);
|
|
45863
|
+
return utils_response(414, `微信视频号视频发布失败: ${errorMsg}`, "");
|
|
45864
|
+
}
|
|
45865
|
+
};
|
|
45866
|
+
const ShipinhaoPublishVideoParamsSchema = ActionCommonParamsSchema.extend({
|
|
45867
|
+
videoPath: classic_schemas_string().min(1),
|
|
45868
|
+
coverPath: classic_schemas_string().min(1),
|
|
45869
|
+
description: classic_schemas_string(),
|
|
45870
|
+
title: classic_schemas_string().optional(),
|
|
45871
|
+
scheduleTime: classic_schemas_number().int().positive().optional(),
|
|
45872
|
+
location: classic_schemas_object({
|
|
45873
|
+
latitude: classic_schemas_number(),
|
|
45874
|
+
longitude: classic_schemas_number(),
|
|
45875
|
+
city: classic_schemas_string(),
|
|
45876
|
+
poiClassifyId: classic_schemas_string().optional()
|
|
45877
|
+
}).optional()
|
|
45878
|
+
});
|
|
45879
|
+
const shipinhaoPublishVideo = async (task, params)=>{
|
|
45880
|
+
task.logger.info(`shipinhaoPublishVideo actionType: ${params.actionType}`);
|
|
45881
|
+
if ("rpa" === params.actionType) return shipinhaoPublishVideo_rpa_rpaAction(task, params);
|
|
45882
|
+
if ("mockApi" === params.actionType) return shipinhaoPublishVideo_mock_mockAction(task, params);
|
|
45883
|
+
return executeAction(shipinhaoPublishVideo_mock_mockAction, shipinhaoPublishVideo_rpa_rpaAction)(task, params);
|
|
45884
|
+
};
|
|
44782
45885
|
const ShipinhaoSendMsgParamsSchema = ActionCommonParamsSchema.extend({
|
|
44783
45886
|
toUsername: classic_schemas_string().min(1, "接收者用户名不能为空"),
|
|
44784
45887
|
sessionId: classic_schemas_string().min(1, "会话ID不能为空"),
|
|
@@ -44793,7 +45896,7 @@ var __webpack_exports__ = {};
|
|
|
44793
45896
|
pathOrUrl: classic_schemas_string().min(1, "图片路径或URL不能为空")
|
|
44794
45897
|
}).optional()
|
|
44795
45898
|
});
|
|
44796
|
-
const
|
|
45899
|
+
const shipinhaoSendMsg_CHUNK_SIZE = 524288;
|
|
44797
45900
|
async function shipinhaoSendMsg_getUserInfo(cookieStr, http) {
|
|
44798
45901
|
const url = `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data?_rid=${rid()}`;
|
|
44799
45902
|
const headers = {
|
|
@@ -44876,11 +45979,11 @@ var __webpack_exports__ = {};
|
|
|
44876
45979
|
}
|
|
44877
45980
|
const md5 = (0, external_node_crypto_namespaceObject.createHash)("md5").update(imageBuffer).digest("hex");
|
|
44878
45981
|
const timestamp = Date.now().toString();
|
|
44879
|
-
const totalChunks = Math.ceil(imageBuffer.length /
|
|
45982
|
+
const totalChunks = Math.ceil(imageBuffer.length / shipinhaoSendMsg_CHUNK_SIZE);
|
|
44880
45983
|
console.log(`分片上传md5${md5}`);
|
|
44881
45984
|
let lastRes;
|
|
44882
45985
|
for(let i = 0; i < totalChunks; i++){
|
|
44883
|
-
const chunkBuffer = imageBuffer.slice(i *
|
|
45986
|
+
const chunkBuffer = imageBuffer.slice(i * shipinhaoSendMsg_CHUNK_SIZE, (i + 1) * shipinhaoSendMsg_CHUNK_SIZE);
|
|
44884
45987
|
const requestData = {
|
|
44885
45988
|
content: `data:application/octet-stream;base64,${chunkBuffer.toString("base64")}`,
|
|
44886
45989
|
chunk: i,
|
|
@@ -45333,6 +46436,13 @@ var __webpack_exports__ = {};
|
|
|
45333
46436
|
const uploadImages = async (images)=>await Promise.all(images.map(async (url)=>{
|
|
45334
46437
|
const fileName = getFilenameFromUrl(url);
|
|
45335
46438
|
const image = await downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
|
|
46439
|
+
const stats = external_node_fs_default().statSync(image);
|
|
46440
|
+
const maxSize = 20971520;
|
|
46441
|
+
if (stats.size > maxSize) throw {
|
|
46442
|
+
code: 414,
|
|
46443
|
+
message: "头条号平台:单张图片不得超过 20MB",
|
|
46444
|
+
data: ""
|
|
46445
|
+
};
|
|
45336
46446
|
const formData = new (form_data_default())();
|
|
45337
46447
|
formData.append("image", external_node_fs_default().createReadStream(image));
|
|
45338
46448
|
const response = await http.api({
|
|
@@ -48616,6 +49726,12 @@ var __webpack_exports__ = {};
|
|
|
48616
49726
|
const fileName = getFilenameFromUrl(url);
|
|
48617
49727
|
const localUrl = await downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
|
|
48618
49728
|
const fileBuffer = external_node_fs_default().readFileSync(localUrl);
|
|
49729
|
+
const maxSize = 33554432;
|
|
49730
|
+
if (fileBuffer.byteLength > maxSize) throw {
|
|
49731
|
+
code: 414,
|
|
49732
|
+
message: "小红书平台:单张图片不得超过 32MB",
|
|
49733
|
+
data: ""
|
|
49734
|
+
};
|
|
48619
49735
|
let width = 0;
|
|
48620
49736
|
let height = 0;
|
|
48621
49737
|
try {
|
|
@@ -50800,6 +51916,9 @@ var __webpack_exports__ = {};
|
|
|
50800
51916
|
shipinhaoPublish(params) {
|
|
50801
51917
|
return this.bindTask(shipinhaoPublish, params);
|
|
50802
51918
|
}
|
|
51919
|
+
shipinhaoPublishVideo(params) {
|
|
51920
|
+
return this.bindTask(shipinhaoPublishVideo, params);
|
|
51921
|
+
}
|
|
50803
51922
|
douyinGetTopics(params) {
|
|
50804
51923
|
return this.bindTask(douyinGetTopics, params);
|
|
50805
51924
|
}
|
|
@@ -50860,4 +51979,4 @@ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_targe
|
|
|
50860
51979
|
});
|
|
50861
51980
|
|
|
50862
51981
|
//# sourceMappingURL=bundle.js.map
|
|
50863
|
-
//# debugId=
|
|
51982
|
+
//# debugId=1e50231c-4e0f-5db5-a554-c11a95d7391d
|