@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/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]="19f291bd-1860-5dc2-abcf-dd482b04a403")}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.5"}');
|
|
4356
4356
|
const USER_MESSAGE = {
|
|
4357
4357
|
PROXY_UNAVAILABLE: "代理暂时不可用,请稍后重试或使用本地IP",
|
|
4358
4358
|
NETWORK_ERROR: "网络异常,请稍后重试",
|
|
@@ -4805,22 +4805,32 @@ class Http {
|
|
|
4805
4805
|
const retries = options?.retries ?? 0;
|
|
4806
4806
|
const retryDelay = options?.retryDelay ?? 500;
|
|
4807
4807
|
const reqTimeout = options?.timeout ?? 30000;
|
|
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)=>{
|
|
@@ -9255,6 +9265,13 @@ const mockAction = async (task, params)=>{
|
|
|
9255
9265
|
data: ""
|
|
9256
9266
|
};
|
|
9257
9267
|
const image = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
9268
|
+
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(image);
|
|
9269
|
+
const maxSize = 5242880;
|
|
9270
|
+
if (stats.size > maxSize) throw {
|
|
9271
|
+
code: 414,
|
|
9272
|
+
message: "百家号平台:单张图片不得超过 5MB",
|
|
9273
|
+
data: ""
|
|
9274
|
+
};
|
|
9258
9275
|
const formData = new __WEBPACK_EXTERNAL_MODULE_form_data_cf000082__["default"]();
|
|
9259
9276
|
formData.append("org_file_name", fileName);
|
|
9260
9277
|
formData.append("type", "image");
|
|
@@ -13385,6 +13402,11 @@ class DouyinImageUploader {
|
|
|
13385
13402
|
}
|
|
13386
13403
|
async getImageInfo(localPath) {
|
|
13387
13404
|
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(localPath);
|
|
13405
|
+
const maxSize = 52428800;
|
|
13406
|
+
if (stats.size > maxSize) {
|
|
13407
|
+
__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(localPath);
|
|
13408
|
+
throw new Error("抖音平台:单张图片不得超过 50MB");
|
|
13409
|
+
}
|
|
13388
13410
|
let width = 1080;
|
|
13389
13411
|
let height = 1920;
|
|
13390
13412
|
try {
|
|
@@ -19627,6 +19649,1086 @@ const shipinhaoPublish = async (task, params)=>{
|
|
|
19627
19649
|
if ("server" === params.actionType) return rpa_server_rpaAction_Server(task, params);
|
|
19628
19650
|
return executeAction(shipinhaoPublish_mock_mockAction, rpa_server_rpaAction_Server)(task, params);
|
|
19629
19651
|
};
|
|
19652
|
+
function auth_getTimeStamp(length) {
|
|
19653
|
+
return Date.now().toString().substring(0, length);
|
|
19654
|
+
}
|
|
19655
|
+
async function auth_getUserInfo(cookies, http) {
|
|
19656
|
+
return http.api({
|
|
19657
|
+
method: "post",
|
|
19658
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data",
|
|
19659
|
+
data: {
|
|
19660
|
+
timestamp: auth_getTimeStamp(13),
|
|
19661
|
+
_log_finder_uin: "",
|
|
19662
|
+
_log_finder_id: "",
|
|
19663
|
+
rawKeyBuff: null,
|
|
19664
|
+
pluginSessionId: null,
|
|
19665
|
+
scene: 7,
|
|
19666
|
+
reqScene: 7
|
|
19667
|
+
},
|
|
19668
|
+
headers: {
|
|
19669
|
+
cookie: cookies,
|
|
19670
|
+
referer: "https://channels.weixin.qq.com",
|
|
19671
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
19672
|
+
},
|
|
19673
|
+
defaultErrorMsg: "获取用户信息失败"
|
|
19674
|
+
});
|
|
19675
|
+
}
|
|
19676
|
+
async function auth_getUploadAuthKey(cookies, finderUsername, http) {
|
|
19677
|
+
return http.api({
|
|
19678
|
+
method: "post",
|
|
19679
|
+
url: "https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/helper/helper_upload_params",
|
|
19680
|
+
data: {
|
|
19681
|
+
timestamp: auth_getTimeStamp(13),
|
|
19682
|
+
_log_finder_id: finderUsername,
|
|
19683
|
+
rawKeyBuff: null
|
|
19684
|
+
},
|
|
19685
|
+
headers: {
|
|
19686
|
+
cookie: cookies,
|
|
19687
|
+
referer: "https://channels.weixin.qq.com",
|
|
19688
|
+
Accept: "application/json, text/plain, */*",
|
|
19689
|
+
"Content-Type": "application/json",
|
|
19690
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
19691
|
+
},
|
|
19692
|
+
defaultErrorMsg: "获取上传认证密钥失败"
|
|
19693
|
+
});
|
|
19694
|
+
}
|
|
19695
|
+
class ShipinhaoAuthError extends Error {
|
|
19696
|
+
constructor(message, errCode){
|
|
19697
|
+
super(message), this.errCode = errCode;
|
|
19698
|
+
this.name = "ShipinhaoAuthError";
|
|
19699
|
+
}
|
|
19700
|
+
}
|
|
19701
|
+
async function getShipinhaoUploadAuth(cookies, http) {
|
|
19702
|
+
const userInfo = await auth_getUserInfo(cookies, http);
|
|
19703
|
+
if (0 !== userInfo.errCode || !userInfo.data?.finderUser) {
|
|
19704
|
+
const isLoginExpired = 300333 === userInfo.errCode || 300334 === userInfo.errCode;
|
|
19705
|
+
throw new ShipinhaoAuthError(isLoginExpired ? "登录失效" : userInfo.errMsg || "获取用户信息失败", userInfo.errCode || 500);
|
|
19706
|
+
}
|
|
19707
|
+
const finderUsername = userInfo.data.finderUser.finderUsername;
|
|
19708
|
+
const authKeyResponse = await auth_getUploadAuthKey(cookies, finderUsername, http);
|
|
19709
|
+
if (0 !== authKeyResponse.errCode || !authKeyResponse.data?.authKey) throw new ShipinhaoAuthError(`获取上传认证参数失败: ${authKeyResponse.errMsg}`, authKeyResponse.errCode || 500);
|
|
19710
|
+
const uin = authKeyResponse.data.uin;
|
|
19711
|
+
if (!uin) throw new ShipinhaoAuthError("获取用户 uin 失败", 500);
|
|
19712
|
+
const videoFileType = authKeyResponse.data.videoFileType || 20302;
|
|
19713
|
+
const pictureFileType = authKeyResponse.data.pictureFileType || 20304;
|
|
19714
|
+
return {
|
|
19715
|
+
uin,
|
|
19716
|
+
authKey: authKeyResponse.data.authKey,
|
|
19717
|
+
finderUsername,
|
|
19718
|
+
videoFileType,
|
|
19719
|
+
pictureFileType
|
|
19720
|
+
};
|
|
19721
|
+
}
|
|
19722
|
+
const CHUNK_SIZE = 8388608;
|
|
19723
|
+
async function uploader_uploadFile(opts) {
|
|
19724
|
+
const { filePath, fileType, uin, authKey, http, logger } = opts;
|
|
19725
|
+
const stat = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(filePath);
|
|
19726
|
+
const fileSize = stat.size;
|
|
19727
|
+
const fileName = filePath.split(/[\\/]/).pop() || "file";
|
|
19728
|
+
logger?.info(`开始上传: ${fileName} (${fileSize} B, filetype=${fileType})`);
|
|
19729
|
+
const fileMd5 = await computeFileMd5(filePath);
|
|
19730
|
+
const taskId = generateTaskId(fileName, fileSize, fileMd5);
|
|
19731
|
+
const baseUrl = "https://finderassistancea.video.qq.com";
|
|
19732
|
+
const headers = {
|
|
19733
|
+
Authorization: authKey
|
|
19734
|
+
};
|
|
19735
|
+
const xArgs = `apptype=251&filetype=${fileType}&weixinnum=${uin}&filekey=${encodeURIComponent(fileName)}&filesize=${fileSize}&taskid=${taskId}&scene=2`;
|
|
19736
|
+
const chunkCount = Math.ceil(fileSize / CHUNK_SIZE);
|
|
19737
|
+
const blockPartLength = [];
|
|
19738
|
+
for(let i = 0; i < chunkCount; i++)blockPartLength.push(Math.min((i + 1) * CHUNK_SIZE, fileSize));
|
|
19739
|
+
logger?.info(`申请 UploadID: ${chunkCount} 片`);
|
|
19740
|
+
const applyRes = await http.api({
|
|
19741
|
+
method: "PUT",
|
|
19742
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
19743
|
+
headers: {
|
|
19744
|
+
...headers,
|
|
19745
|
+
"X-Arguments": xArgs
|
|
19746
|
+
},
|
|
19747
|
+
data: {
|
|
19748
|
+
BlockSum: chunkCount,
|
|
19749
|
+
BlockPartLength: blockPartLength
|
|
19750
|
+
}
|
|
19751
|
+
});
|
|
19752
|
+
if (!applyRes.UploadID && !applyRes.ListPartsResult) throw new Error("申请 UploadID 失败: " + JSON.stringify(applyRes));
|
|
19753
|
+
let uploadId = applyRes.UploadID;
|
|
19754
|
+
const uploadedParts = new Set();
|
|
19755
|
+
if (applyRes.ListPartsResult) {
|
|
19756
|
+
logger?.info("检测到已上传分片,执行续传");
|
|
19757
|
+
const parts = Array.isArray(applyRes.ListPartsResult.Part) ? applyRes.ListPartsResult.Part : applyRes.ListPartsResult.Part ? [
|
|
19758
|
+
applyRes.ListPartsResult.Part
|
|
19759
|
+
] : [];
|
|
19760
|
+
for (const p of parts)uploadedParts.add(p.PartNumber);
|
|
19761
|
+
const retryRes = await http.api({
|
|
19762
|
+
method: "PUT",
|
|
19763
|
+
url: `${baseUrl}/applyuploaddfs`,
|
|
19764
|
+
headers: {
|
|
19765
|
+
...headers,
|
|
19766
|
+
"X-Arguments": xArgs
|
|
19767
|
+
},
|
|
19768
|
+
data: {
|
|
19769
|
+
BlockSum: chunkCount,
|
|
19770
|
+
BlockPartLength: blockPartLength
|
|
19771
|
+
}
|
|
19772
|
+
});
|
|
19773
|
+
uploadId = retryRes.UploadID;
|
|
19774
|
+
if (!uploadId) throw new Error("续传获取 UploadID 失败");
|
|
19775
|
+
}
|
|
19776
|
+
const partInfo = [];
|
|
19777
|
+
const fd = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].openSync(filePath, "r");
|
|
19778
|
+
try {
|
|
19779
|
+
for(let i = 0; i < chunkCount; i++){
|
|
19780
|
+
const partNumber = i + 1;
|
|
19781
|
+
if (uploadedParts.has(partNumber)) {
|
|
19782
|
+
const existing = applyRes.ListPartsResult.Part.find((p)=>p.PartNumber === partNumber);
|
|
19783
|
+
if (existing) {
|
|
19784
|
+
partInfo.push({
|
|
19785
|
+
PartNumber: partNumber,
|
|
19786
|
+
ETag: existing.ETag
|
|
19787
|
+
});
|
|
19788
|
+
logger?.info(`分片 ${partNumber}/${chunkCount} 已存在,跳过`);
|
|
19789
|
+
continue;
|
|
19790
|
+
}
|
|
19791
|
+
}
|
|
19792
|
+
const start = i * CHUNK_SIZE;
|
|
19793
|
+
const end = Math.min(start + CHUNK_SIZE, fileSize);
|
|
19794
|
+
const chunkSize = end - start;
|
|
19795
|
+
const chunk = Buffer.alloc(chunkSize);
|
|
19796
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readSync(fd, chunk, 0, chunkSize, start);
|
|
19797
|
+
const chunkMd5 = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5").update(chunk).digest("hex");
|
|
19798
|
+
await http.api({
|
|
19799
|
+
method: "PUT",
|
|
19800
|
+
url: `${baseUrl}/uploadpartdfs?PartNumber=${partNumber}&UploadID=${encodeURIComponent(uploadId)}`,
|
|
19801
|
+
headers: {
|
|
19802
|
+
...headers,
|
|
19803
|
+
"X-Arguments": xArgs.replace(/scene=2/, "scene=0"),
|
|
19804
|
+
"Content-MD5": chunkMd5
|
|
19805
|
+
},
|
|
19806
|
+
data: chunk
|
|
19807
|
+
});
|
|
19808
|
+
partInfo.push({
|
|
19809
|
+
PartNumber: partNumber,
|
|
19810
|
+
ETag: `"${chunkMd5}"`
|
|
19811
|
+
});
|
|
19812
|
+
logger?.info(`分片 ${partNumber}/${chunkCount} 完成 (${chunkSize} B)`);
|
|
19813
|
+
}
|
|
19814
|
+
} finally{
|
|
19815
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].closeSync(fd);
|
|
19816
|
+
}
|
|
19817
|
+
logger?.info("合并分片...");
|
|
19818
|
+
const completeRes = await http.api({
|
|
19819
|
+
method: "POST",
|
|
19820
|
+
url: `${baseUrl}/completepartuploaddfs?UploadID=${encodeURIComponent(uploadId)}`,
|
|
19821
|
+
headers: {
|
|
19822
|
+
...headers,
|
|
19823
|
+
"X-Arguments": xArgs
|
|
19824
|
+
},
|
|
19825
|
+
data: {
|
|
19826
|
+
TransFlag: "0_0",
|
|
19827
|
+
PartInfo: partInfo
|
|
19828
|
+
}
|
|
19829
|
+
});
|
|
19830
|
+
if (!completeRes.DownloadURL) throw new Error("合并分片失败: " + JSON.stringify(completeRes));
|
|
19831
|
+
logger?.info(`上传成功: ${completeRes.DownloadURL.slice(0, 80)}...`);
|
|
19832
|
+
return {
|
|
19833
|
+
downloadUrl: completeRes.DownloadURL,
|
|
19834
|
+
md5: fileMd5,
|
|
19835
|
+
fileSize
|
|
19836
|
+
};
|
|
19837
|
+
}
|
|
19838
|
+
async function computeFileMd5(filePath) {
|
|
19839
|
+
return new Promise((resolve, reject)=>{
|
|
19840
|
+
const hash = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5");
|
|
19841
|
+
const stream = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].createReadStream(filePath);
|
|
19842
|
+
stream.on("data", (chunk)=>hash.update(chunk));
|
|
19843
|
+
stream.on("end", ()=>resolve(hash.digest("hex")));
|
|
19844
|
+
stream.on("error", reject);
|
|
19845
|
+
});
|
|
19846
|
+
}
|
|
19847
|
+
function generateTaskId(fileName, fileSize, fileMd5) {
|
|
19848
|
+
const input = `${fileName}-${fileSize}-${fileMd5}`;
|
|
19849
|
+
return __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].createHash("md5").update(input).digest("hex").slice(0, 32);
|
|
19850
|
+
}
|
|
19851
|
+
function parseVideoMeta(filePath) {
|
|
19852
|
+
let buf;
|
|
19853
|
+
try {
|
|
19854
|
+
buf = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(filePath);
|
|
19855
|
+
} catch {
|
|
19856
|
+
return null;
|
|
19857
|
+
}
|
|
19858
|
+
let movie = null;
|
|
19859
|
+
const tracks = [];
|
|
19860
|
+
function walk(start, end) {
|
|
19861
|
+
let off = start;
|
|
19862
|
+
while(off + 8 <= end){
|
|
19863
|
+
let size = buf.readUInt32BE(off);
|
|
19864
|
+
const type = buf.toString("latin1", off + 4, off + 8);
|
|
19865
|
+
let headerSize = 8;
|
|
19866
|
+
if (1 === size) {
|
|
19867
|
+
if (off + 16 > end) break;
|
|
19868
|
+
const hi = buf.readUInt32BE(off + 8);
|
|
19869
|
+
const lo = buf.readUInt32BE(off + 12);
|
|
19870
|
+
size = hi * 2 ** 32 + lo;
|
|
19871
|
+
headerSize = 16;
|
|
19872
|
+
} else if (0 === size) size = end - off;
|
|
19873
|
+
if (size < headerSize || off + size > end) break;
|
|
19874
|
+
const bodyStart = off + headerSize;
|
|
19875
|
+
const bodyEnd = off + size;
|
|
19876
|
+
switch(type){
|
|
19877
|
+
case "moov":
|
|
19878
|
+
case "trak":
|
|
19879
|
+
case "mdia":
|
|
19880
|
+
case "minf":
|
|
19881
|
+
case "stbl":
|
|
19882
|
+
walk(bodyStart, bodyEnd);
|
|
19883
|
+
break;
|
|
19884
|
+
case "mvhd":
|
|
19885
|
+
movie = parseMvhd(buf, bodyStart, bodyEnd);
|
|
19886
|
+
break;
|
|
19887
|
+
case "tkhd":
|
|
19888
|
+
tracks.push({
|
|
19889
|
+
...parseTkhd(buf, bodyStart, bodyEnd),
|
|
19890
|
+
handler: null,
|
|
19891
|
+
codec: null
|
|
19892
|
+
});
|
|
19893
|
+
break;
|
|
19894
|
+
case "hdlr":
|
|
19895
|
+
if (bodyEnd - bodyStart >= 12) {
|
|
19896
|
+
const handler = buf.toString("latin1", bodyStart + 8, bodyStart + 12);
|
|
19897
|
+
if (tracks.length) tracks[tracks.length - 1].handler = handler;
|
|
19898
|
+
}
|
|
19899
|
+
break;
|
|
19900
|
+
case "stsd":
|
|
19901
|
+
{
|
|
19902
|
+
const codec = parseStsdCodec(buf, bodyStart, bodyEnd);
|
|
19903
|
+
if (codec && tracks.length) tracks[tracks.length - 1].codec = codec;
|
|
19904
|
+
break;
|
|
19905
|
+
}
|
|
19906
|
+
}
|
|
19907
|
+
off += size;
|
|
19908
|
+
}
|
|
19909
|
+
}
|
|
19910
|
+
walk(0, buf.length);
|
|
19911
|
+
const video = tracks.find((t)=>"vide" === t.handler) || tracks.find((t)=>t.width > 0 && t.height > 0);
|
|
19912
|
+
if (!movie || !video) return null;
|
|
19913
|
+
const movieData = movie;
|
|
19914
|
+
let { width, height } = video;
|
|
19915
|
+
if (90 === video.rotation || 270 === video.rotation) [width, height] = [
|
|
19916
|
+
height,
|
|
19917
|
+
width
|
|
19918
|
+
];
|
|
19919
|
+
return {
|
|
19920
|
+
width: Math.round(width),
|
|
19921
|
+
height: Math.round(height),
|
|
19922
|
+
duration: movieData.timescale ? movieData.duration / movieData.timescale : 0,
|
|
19923
|
+
rotation: video.rotation,
|
|
19924
|
+
fileSize: buf.length,
|
|
19925
|
+
codec: video.codec
|
|
19926
|
+
};
|
|
19927
|
+
}
|
|
19928
|
+
function parseStsdCodec(buf, start, end) {
|
|
19929
|
+
if (start + 16 > end) return null;
|
|
19930
|
+
return buf.toString("latin1", start + 12, start + 16).toLowerCase();
|
|
19931
|
+
}
|
|
19932
|
+
function parseMvhd(buf, start, end) {
|
|
19933
|
+
const version = buf.readUInt8(start);
|
|
19934
|
+
if (1 === version) {
|
|
19935
|
+
if (start + 28 > end) return null;
|
|
19936
|
+
const timescale = buf.readUInt32BE(start + 20);
|
|
19937
|
+
const hi = buf.readUInt32BE(start + 24);
|
|
19938
|
+
const lo = buf.readUInt32BE(start + 28);
|
|
19939
|
+
return {
|
|
19940
|
+
timescale,
|
|
19941
|
+
duration: hi * 2 ** 32 + lo
|
|
19942
|
+
};
|
|
19943
|
+
}
|
|
19944
|
+
if (start + 20 > end) return null;
|
|
19945
|
+
return {
|
|
19946
|
+
timescale: buf.readUInt32BE(start + 12),
|
|
19947
|
+
duration: buf.readUInt32BE(start + 16)
|
|
19948
|
+
};
|
|
19949
|
+
}
|
|
19950
|
+
function parseTkhd(buf, start, end) {
|
|
19951
|
+
const version = buf.readUInt8(start);
|
|
19952
|
+
const afterDuration = 1 === version ? 36 : 24;
|
|
19953
|
+
const matrixOff = start + afterDuration + 16;
|
|
19954
|
+
const whOff = matrixOff + 36;
|
|
19955
|
+
if (whOff + 8 > end) return {
|
|
19956
|
+
width: 0,
|
|
19957
|
+
height: 0,
|
|
19958
|
+
rotation: 0
|
|
19959
|
+
};
|
|
19960
|
+
const width = buf.readUInt32BE(whOff) / 65536;
|
|
19961
|
+
const height = buf.readUInt32BE(whOff + 4) / 65536;
|
|
19962
|
+
const a = buf.readInt32BE(matrixOff) / 65536;
|
|
19963
|
+
const b = buf.readInt32BE(matrixOff + 4) / 65536;
|
|
19964
|
+
let rotation = 0;
|
|
19965
|
+
if (Math.abs(a) < 0.01 && Math.abs(b - 1) < 0.01) rotation = 90;
|
|
19966
|
+
else if (Math.abs(a + 1) < 0.01 && Math.abs(b) < 0.01) rotation = 180;
|
|
19967
|
+
else if (Math.abs(a) < 0.01 && Math.abs(b + 1) < 0.01) rotation = 270;
|
|
19968
|
+
return {
|
|
19969
|
+
width,
|
|
19970
|
+
height,
|
|
19971
|
+
rotation
|
|
19972
|
+
};
|
|
19973
|
+
}
|
|
19974
|
+
const MAX_DURATION_SECONDS = 28800;
|
|
19975
|
+
const MAX_FILE_SIZE = 21474836480;
|
|
19976
|
+
const ALLOWED_EXTENSIONS = [
|
|
19977
|
+
".mp4"
|
|
19978
|
+
];
|
|
19979
|
+
const ALLOWED_CODECS = [
|
|
19980
|
+
"avc1",
|
|
19981
|
+
"avc3"
|
|
19982
|
+
];
|
|
19983
|
+
const MIN_TITLE_LENGTH = 6;
|
|
19984
|
+
function formatFileSize(bytes) {
|
|
19985
|
+
if (bytes < 1048576) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
19986
|
+
if (bytes < 1073741824) return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
19987
|
+
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
19988
|
+
}
|
|
19989
|
+
function formatDuration(seconds) {
|
|
19990
|
+
const total = Math.round(seconds);
|
|
19991
|
+
const h = Math.floor(total / 3600);
|
|
19992
|
+
const m = Math.floor(total % 3600 / 60);
|
|
19993
|
+
const s = total % 60;
|
|
19994
|
+
if (h > 0) return `${h}小时${m}分${s}秒`;
|
|
19995
|
+
if (m > 0) return `${m}分${s}秒`;
|
|
19996
|
+
return `${s}秒`;
|
|
19997
|
+
}
|
|
19998
|
+
function validateShipinhaoVideo(filePath, meta) {
|
|
19999
|
+
const fileName = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(filePath);
|
|
20000
|
+
const ext = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(fileName).toLowerCase();
|
|
20001
|
+
if (!ALLOWED_EXTENSIONS.includes(ext)) return `视频格式不支持:${fileName}。视频号仅支持 MP4/H.264 格式,请转换后重试。`;
|
|
20002
|
+
if (meta.duration > MAX_DURATION_SECONDS) return `视频时长超过限制:${fileName}(${formatDuration(meta.duration)})。视频号视频时长不能超过 8 小时,请剪辑后重试。`;
|
|
20003
|
+
if (meta.fileSize > MAX_FILE_SIZE) return `视频大小超过限制:${fileName}(${formatFileSize(meta.fileSize)})。视频号视频不能超过 20GB,请压缩后重试。`;
|
|
20004
|
+
if (meta.codec && !ALLOWED_CODECS.includes(meta.codec)) return `视频编码不支持:${fileName}(${meta.codec})。视频号仅支持 H.264 编码,请转码后重试。`;
|
|
20005
|
+
return null;
|
|
20006
|
+
}
|
|
20007
|
+
function validateShipinhaoTitle(title) {
|
|
20008
|
+
if (void 0 === title) return null;
|
|
20009
|
+
const trimmed = title.trim();
|
|
20010
|
+
const length = [
|
|
20011
|
+
...trimmed
|
|
20012
|
+
].length;
|
|
20013
|
+
if (length < MIN_TITLE_LENGTH) return `视频号标题至少需要 ${MIN_TITLE_LENGTH} 个字符,请补充后重试。`;
|
|
20014
|
+
return null;
|
|
20015
|
+
}
|
|
20016
|
+
async function getTraceKey(auth, http, logger) {
|
|
20017
|
+
logger.info("[getTraceKey] 开始获取 traceKey...");
|
|
20018
|
+
const res = await http.api({
|
|
20019
|
+
method: "POST",
|
|
20020
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/get-finder-post-trace-key",
|
|
20021
|
+
data: {
|
|
20022
|
+
objectId: "",
|
|
20023
|
+
timestamp: String(Date.now()),
|
|
20024
|
+
_log_finder_uin: "",
|
|
20025
|
+
_log_finder_id: auth.finderUsername,
|
|
20026
|
+
rawKeyBuff: "",
|
|
20027
|
+
pluginSessionId: null,
|
|
20028
|
+
scene: 7,
|
|
20029
|
+
reqScene: 7
|
|
20030
|
+
},
|
|
20031
|
+
defaultErrorMsg: "获取 traceKey 失败"
|
|
20032
|
+
});
|
|
20033
|
+
if (0 !== res.errCode || !res.data?.traceKey) {
|
|
20034
|
+
logger.error("[getTraceKey] 获取失败:", JSON.stringify(res));
|
|
20035
|
+
throw new Error(`获取 traceKey 失败: ${JSON.stringify(res)}`);
|
|
20036
|
+
}
|
|
20037
|
+
logger.info(`[getTraceKey] 获取成功: ${res.data.traceKey}`);
|
|
20038
|
+
return res.data.traceKey;
|
|
20039
|
+
}
|
|
20040
|
+
async function submitAndPollTranscode(opts) {
|
|
20041
|
+
const { videoUrl, videoMeta, traceKey, uploadStartTime, uploadEndTime, finderUsername, http, logger } = opts;
|
|
20042
|
+
logger.info("[submitAndPollTranscode] 开始提交转码任务...");
|
|
20043
|
+
const finderUrl = videoUrl.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${videoUrl.split("qq.com")[1]}` : videoUrl;
|
|
20044
|
+
logger.info(`[submitAndPollTranscode] 视频URL: ${finderUrl}`);
|
|
20045
|
+
logger.info(`[submitAndPollTranscode] 视频尺寸: ${videoMeta.width}x${videoMeta.height}, 时长: ${videoMeta.duration}s`);
|
|
20046
|
+
const submitRes = await http.api({
|
|
20047
|
+
method: "POST",
|
|
20048
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/post_clip_video",
|
|
20049
|
+
data: {
|
|
20050
|
+
url: finderUrl,
|
|
20051
|
+
timeStart: 0,
|
|
20052
|
+
cropDuration: 0,
|
|
20053
|
+
height: videoMeta.height,
|
|
20054
|
+
width: videoMeta.width,
|
|
20055
|
+
x: 0,
|
|
20056
|
+
y: 0,
|
|
20057
|
+
clipOriginVideoInfo: {
|
|
20058
|
+
width: videoMeta.width,
|
|
20059
|
+
height: videoMeta.height,
|
|
20060
|
+
duration: videoMeta.duration,
|
|
20061
|
+
fileSize: videoMeta.fileSize
|
|
20062
|
+
},
|
|
20063
|
+
traceInfo: {
|
|
20064
|
+
traceKey,
|
|
20065
|
+
uploadCdnStart: uploadStartTime,
|
|
20066
|
+
uploadCdnEnd: uploadEndTime
|
|
20067
|
+
},
|
|
20068
|
+
targetWidth: videoMeta.width,
|
|
20069
|
+
targetHeight: videoMeta.height,
|
|
20070
|
+
type: 4,
|
|
20071
|
+
useAstraThumbCover: 1,
|
|
20072
|
+
timestamp: String(Date.now()),
|
|
20073
|
+
_log_finder_uin: "",
|
|
20074
|
+
_log_finder_id: finderUsername,
|
|
20075
|
+
rawKeyBuff: "",
|
|
20076
|
+
pluginSessionId: null,
|
|
20077
|
+
scene: 7,
|
|
20078
|
+
reqScene: 7
|
|
20079
|
+
},
|
|
20080
|
+
defaultErrorMsg: "提交转码失败"
|
|
20081
|
+
});
|
|
20082
|
+
if (0 !== submitRes.errCode || !submitRes.data?.clipKey) {
|
|
20083
|
+
logger.error("[submitAndPollTranscode] 提交转码失败:", JSON.stringify(submitRes));
|
|
20084
|
+
throw new Error(`提交转码失败: ${JSON.stringify(submitRes)}`);
|
|
20085
|
+
}
|
|
20086
|
+
const { clipKey, draftId } = submitRes.data;
|
|
20087
|
+
logger.info(`[submitAndPollTranscode] 转码任务已提交,clipKey: ${clipKey}, draftId: ${draftId}`);
|
|
20088
|
+
const maxPolls = 60;
|
|
20089
|
+
const pollInterval = 5000;
|
|
20090
|
+
let pollCount = 0;
|
|
20091
|
+
logger.info(`[submitAndPollTranscode] 开始轮询转码结果,最多 ${maxPolls} 次,间隔 ${pollInterval / 1000}s`);
|
|
20092
|
+
while(pollCount < maxPolls){
|
|
20093
|
+
await sleep(pollInterval);
|
|
20094
|
+
pollCount++;
|
|
20095
|
+
const pollRes = await http.api({
|
|
20096
|
+
method: "POST",
|
|
20097
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/post_clip_video_result",
|
|
20098
|
+
data: {
|
|
20099
|
+
clipKey,
|
|
20100
|
+
draftId,
|
|
20101
|
+
timestamp: String(Date.now()),
|
|
20102
|
+
_log_finder_uin: "",
|
|
20103
|
+
_log_finder_id: finderUsername,
|
|
20104
|
+
rawKeyBuff: "",
|
|
20105
|
+
pluginSessionId: null,
|
|
20106
|
+
scene: 7,
|
|
20107
|
+
reqScene: 7
|
|
20108
|
+
},
|
|
20109
|
+
defaultErrorMsg: "转码轮询失败"
|
|
20110
|
+
});
|
|
20111
|
+
if (0 !== pollRes.errCode) {
|
|
20112
|
+
logger.error(`[submitAndPollTranscode] 转码轮询失败 (poll ${pollCount}):`, JSON.stringify(pollRes));
|
|
20113
|
+
throw new Error(`转码轮询失败 (poll ${pollCount}): ${JSON.stringify(pollRes)}`);
|
|
20114
|
+
}
|
|
20115
|
+
const { flag, url, width, height, duration, md5, fileSize } = pollRes.data || {};
|
|
20116
|
+
logger.info(`[submitAndPollTranscode] 轮询第 ${pollCount} 次,flag=${flag}`);
|
|
20117
|
+
if (1 === flag) {
|
|
20118
|
+
if (!url || !width || !height || !duration || !md5 || !fileSize) {
|
|
20119
|
+
logger.error("[submitAndPollTranscode] 转码完成但返回数据不完整:", JSON.stringify(pollRes.data));
|
|
20120
|
+
throw new Error(`转码完成但返回数据不完整: ${JSON.stringify(pollRes.data)}`);
|
|
20121
|
+
}
|
|
20122
|
+
logger.info(`[submitAndPollTranscode] 转码完成! 用时: ${pollCount * pollInterval / 1000}s`);
|
|
20123
|
+
logger.info(`[submitAndPollTranscode] 视频信息: ${width}x${height}, 时长: ${duration}s, 大小: ${fileSize}`);
|
|
20124
|
+
return {
|
|
20125
|
+
clipKey,
|
|
20126
|
+
url,
|
|
20127
|
+
width,
|
|
20128
|
+
height,
|
|
20129
|
+
duration,
|
|
20130
|
+
md5,
|
|
20131
|
+
fileSize
|
|
20132
|
+
};
|
|
20133
|
+
}
|
|
20134
|
+
if (2 === flag) logger.info(`[submitAndPollTranscode] 转码中... (${pollCount}/${maxPolls})`);
|
|
20135
|
+
else {
|
|
20136
|
+
logger.error(`[submitAndPollTranscode] 转码失败,未知 flag=${flag}:`, JSON.stringify(pollRes.data));
|
|
20137
|
+
throw new Error(`转码失败,未知 flag=${flag}: ${JSON.stringify(pollRes.data)}`);
|
|
20138
|
+
}
|
|
20139
|
+
}
|
|
20140
|
+
logger.error(`[submitAndPollTranscode] 转码超时,已轮询 ${maxPolls} 次,用时: ${maxPolls * pollInterval / 1000}s`);
|
|
20141
|
+
throw new Error(`转码超时 (${maxPolls * pollInterval / 1000}s)`);
|
|
20142
|
+
}
|
|
20143
|
+
async function publishVideo(opts) {
|
|
20144
|
+
const { params, auth, clipResult, videoUpload, coverUpload, traceKey, uploadStartTime, uploadEndTime, proxyHttp, logger } = opts;
|
|
20145
|
+
logger.info("[publishVideo] 开始构建发布请求...");
|
|
20146
|
+
const coverFinderUrl = coverUpload.downloadUrl.includes("wxapp.tc.qq.com") ? `https://finder.video.qq.com${coverUpload.downloadUrl.split("qq.com")[1]}` : coverUpload.downloadUrl;
|
|
20147
|
+
logger.info(`[publishVideo] 封面URL: ${coverFinderUrl}`);
|
|
20148
|
+
const md5sumUuid = __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].randomUUID();
|
|
20149
|
+
logger.info("[publishVideo] 发布参数:");
|
|
20150
|
+
logger.info(` - 标题: ${params.title || "(无)"}`);
|
|
20151
|
+
logger.info(` - 描述: ${params.description?.substring(0, 50)}${params.description?.length > 50 ? "..." : ""}`);
|
|
20152
|
+
logger.info(` - 定时发布: ${params.scheduleTime ? new Date(1000 * params.scheduleTime).toLocaleString() : "立即发布"}`);
|
|
20153
|
+
logger.info(` - 地理位置: ${params.location ? `${params.location.city} (${params.location.latitude},${params.location.longitude})` : "(无)"}`);
|
|
20154
|
+
const publishRes = await proxyHttp.api({
|
|
20155
|
+
method: "POST",
|
|
20156
|
+
url: "https://channels.weixin.qq.com/micro/content/cgi-bin/mmfinderassistant-bin/post/post_create",
|
|
20157
|
+
data: {
|
|
20158
|
+
objectType: 0,
|
|
20159
|
+
longitude: params.location?.longitude || 0,
|
|
20160
|
+
latitude: params.location?.latitude || 0,
|
|
20161
|
+
feedLongitude: 0,
|
|
20162
|
+
feedLatitude: 0,
|
|
20163
|
+
originalFlag: 0,
|
|
20164
|
+
topics: [],
|
|
20165
|
+
isFullPost: 1,
|
|
20166
|
+
handleFlag: 2,
|
|
20167
|
+
videoClipTaskId: clipResult.clipKey,
|
|
20168
|
+
traceInfo: {
|
|
20169
|
+
traceKey,
|
|
20170
|
+
uploadCdnStart: uploadStartTime,
|
|
20171
|
+
uploadCdnEnd: uploadEndTime
|
|
20172
|
+
},
|
|
20173
|
+
objectDesc: {
|
|
20174
|
+
mpTitle: "",
|
|
20175
|
+
description: params.description,
|
|
20176
|
+
shortTitle: params.title || "",
|
|
20177
|
+
extReading: {},
|
|
20178
|
+
mediaType: 4,
|
|
20179
|
+
location: params.location ? {
|
|
20180
|
+
latitude: params.location.latitude,
|
|
20181
|
+
longitude: params.location.longitude,
|
|
20182
|
+
city: params.location.city,
|
|
20183
|
+
poiClassifyId: params.location.poiClassifyId || ""
|
|
20184
|
+
} : {
|
|
20185
|
+
latitude: 0,
|
|
20186
|
+
longitude: 0,
|
|
20187
|
+
city: "",
|
|
20188
|
+
poiClassifyId: ""
|
|
20189
|
+
},
|
|
20190
|
+
topic: {
|
|
20191
|
+
finderTopicInfo: `<finder><version>1</version><valuecount>1</valuecount><style><at></at></style><value0><![CDATA[${params.description}]]></value0></finder>`
|
|
20192
|
+
},
|
|
20193
|
+
event: {},
|
|
20194
|
+
mentionedUser: [],
|
|
20195
|
+
media: [
|
|
20196
|
+
{
|
|
20197
|
+
url: clipResult.url,
|
|
20198
|
+
fileSize: clipResult.fileSize,
|
|
20199
|
+
thumbUrl: coverFinderUrl,
|
|
20200
|
+
fullThumbUrl: coverFinderUrl,
|
|
20201
|
+
coverUrl: coverFinderUrl,
|
|
20202
|
+
fullCoverUrl: coverFinderUrl,
|
|
20203
|
+
shareCoverUrl: coverFinderUrl,
|
|
20204
|
+
mediaType: 4,
|
|
20205
|
+
videoPlayLen: Math.round(clipResult.duration),
|
|
20206
|
+
width: clipResult.width,
|
|
20207
|
+
height: clipResult.height,
|
|
20208
|
+
md5sum: md5sumUuid,
|
|
20209
|
+
cardShowStyle: 2,
|
|
20210
|
+
urlCdnTaskId: clipResult.clipKey
|
|
20211
|
+
}
|
|
20212
|
+
],
|
|
20213
|
+
member: {}
|
|
20214
|
+
},
|
|
20215
|
+
effectiveTime: params.scheduleTime || 0,
|
|
20216
|
+
report: {
|
|
20217
|
+
clipKey: clipResult.clipKey,
|
|
20218
|
+
draftId: clipResult.clipKey,
|
|
20219
|
+
timestamp: String(Date.now()),
|
|
20220
|
+
_log_finder_uin: "",
|
|
20221
|
+
_log_finder_id: auth.finderUsername,
|
|
20222
|
+
rawKeyBuff: "",
|
|
20223
|
+
pluginSessionId: null,
|
|
20224
|
+
scene: 7,
|
|
20225
|
+
reqScene: 7,
|
|
20226
|
+
height: clipResult.height,
|
|
20227
|
+
width: clipResult.width,
|
|
20228
|
+
duration: clipResult.duration,
|
|
20229
|
+
fileSize: videoUpload.fileSize,
|
|
20230
|
+
uploadCost: (uploadEndTime - uploadStartTime) * 1000
|
|
20231
|
+
},
|
|
20232
|
+
postFlag: 0,
|
|
20233
|
+
mode: 1,
|
|
20234
|
+
clientid: __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__["default"].randomUUID(),
|
|
20235
|
+
timestamp: String(Date.now()),
|
|
20236
|
+
_log_finder_uin: "",
|
|
20237
|
+
_log_finder_id: auth.finderUsername,
|
|
20238
|
+
rawKeyBuff: "",
|
|
20239
|
+
pluginSessionId: null,
|
|
20240
|
+
scene: 7,
|
|
20241
|
+
reqScene: 7
|
|
20242
|
+
},
|
|
20243
|
+
defaultErrorMsg: "发布视频失败"
|
|
20244
|
+
});
|
|
20245
|
+
logger.info(`[publishVideo] 发布响应: errCode=${publishRes.errCode}, baseResp.errcode=${publishRes.data?.baseResp?.errcode}`);
|
|
20246
|
+
return publishRes;
|
|
20247
|
+
}
|
|
20248
|
+
function sleep(ms) {
|
|
20249
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
20250
|
+
}
|
|
20251
|
+
const shipinhaoPublishVideo_mock_mockAction = async (task, params)=>{
|
|
20252
|
+
task.logger.info("[shipinhaoPublishVideo] 开始执行视频号视频发布 - Mock API 方式");
|
|
20253
|
+
const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
|
|
20254
|
+
let currentStep = "初始化";
|
|
20255
|
+
try {
|
|
20256
|
+
currentStep = "解析认证信息";
|
|
20257
|
+
const cookieString = params.cookies.map((c)=>`${c.name}=${c.value}`).join("; ");
|
|
20258
|
+
const headers = {
|
|
20259
|
+
cookie: cookieString
|
|
20260
|
+
};
|
|
20261
|
+
const args = [
|
|
20262
|
+
{
|
|
20263
|
+
headers
|
|
20264
|
+
},
|
|
20265
|
+
task.logger,
|
|
20266
|
+
params.proxyLoc,
|
|
20267
|
+
params.accountId,
|
|
20268
|
+
"shipinhao"
|
|
20269
|
+
];
|
|
20270
|
+
const http = new Http({
|
|
20271
|
+
headers
|
|
20272
|
+
});
|
|
20273
|
+
const proxyHttp = new Http(...args);
|
|
20274
|
+
currentStep = "验证发布参数";
|
|
20275
|
+
if (!params.videoPath) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "视频文件路径不能为空", "");
|
|
20276
|
+
if (!params.coverPath) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "封面图片路径不能为空", "");
|
|
20277
|
+
currentStep = "获取上传认证";
|
|
20278
|
+
task.logger.info("[shipinhaoPublishVideo] 获取上传认证...");
|
|
20279
|
+
const auth = await getShipinhaoUploadAuth(cookieString, http);
|
|
20280
|
+
currentStep = "解析视频元数据";
|
|
20281
|
+
task.logger.info("[shipinhaoPublishVideo] 解析视频元数据...");
|
|
20282
|
+
const videoMeta = parseVideoMeta(params.videoPath);
|
|
20283
|
+
if (!videoMeta) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "视频文件解析失败,请检查文件格式(仅支持 MP4)", "");
|
|
20284
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
20285
|
+
currentStep = "校验视频限制";
|
|
20286
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
20287
|
+
if (validationError) {
|
|
20288
|
+
task.logger.error(`[shipinhaoPublishVideo] 视频校验未通过: ${validationError}`);
|
|
20289
|
+
await updateTaskState?.({
|
|
20290
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20291
|
+
error: validationError
|
|
20292
|
+
});
|
|
20293
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, validationError, "");
|
|
20294
|
+
}
|
|
20295
|
+
task.logger.info("[shipinhaoPublishVideo] 视频校验通过");
|
|
20296
|
+
currentStep = "校验标题";
|
|
20297
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
20298
|
+
if (titleError) {
|
|
20299
|
+
task.logger.error(`[shipinhaoPublishVideo] 标题校验未通过: ${titleError}`);
|
|
20300
|
+
await updateTaskState?.({
|
|
20301
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20302
|
+
error: titleError
|
|
20303
|
+
});
|
|
20304
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, titleError, "");
|
|
20305
|
+
}
|
|
20306
|
+
currentStep = "获取 traceKey";
|
|
20307
|
+
task.logger.info("[shipinhaoPublishVideo] 获取 traceKey...");
|
|
20308
|
+
const traceKey = await getTraceKey(auth, http, task.logger);
|
|
20309
|
+
const uploadStartTime = Math.floor(Date.now() / 1000);
|
|
20310
|
+
task.logger.info(`[shipinhaoPublishVideo] 上传开始时间: ${uploadStartTime}`);
|
|
20311
|
+
currentStep = "上传视频";
|
|
20312
|
+
task.logger.info("[shipinhaoPublishVideo] 上传视频...");
|
|
20313
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频路径: ${params.videoPath}`);
|
|
20314
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频文件类型: ${auth.videoFileType}`);
|
|
20315
|
+
const videoUpload = await uploader_uploadFile({
|
|
20316
|
+
filePath: params.videoPath,
|
|
20317
|
+
fileType: auth.videoFileType,
|
|
20318
|
+
uin: auth.uin,
|
|
20319
|
+
authKey: auth.authKey,
|
|
20320
|
+
http,
|
|
20321
|
+
logger: task.logger
|
|
20322
|
+
});
|
|
20323
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频上传完成,URL: ${videoUpload.downloadUrl}`);
|
|
20324
|
+
const uploadEndTime = Math.floor(Date.now() / 1000);
|
|
20325
|
+
task.logger.info(`[shipinhaoPublishVideo] 上传结束时间: ${uploadEndTime}, 耗时: ${uploadEndTime - uploadStartTime}s`);
|
|
20326
|
+
currentStep = "上传封面";
|
|
20327
|
+
task.logger.info("[shipinhaoPublishVideo] 上传封面...");
|
|
20328
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面路径: ${params.coverPath}`);
|
|
20329
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面文件类型: ${auth.pictureFileType}`);
|
|
20330
|
+
const coverUpload = await uploader_uploadFile({
|
|
20331
|
+
filePath: params.coverPath,
|
|
20332
|
+
fileType: auth.pictureFileType,
|
|
20333
|
+
uin: auth.uin,
|
|
20334
|
+
authKey: auth.authKey,
|
|
20335
|
+
http,
|
|
20336
|
+
logger: task.logger
|
|
20337
|
+
});
|
|
20338
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面上传完成,URL: ${coverUpload.downloadUrl}`);
|
|
20339
|
+
currentStep = "提交转码";
|
|
20340
|
+
task.logger.info("[shipinhaoPublishVideo] 提交转码...");
|
|
20341
|
+
const clipResult = await submitAndPollTranscode({
|
|
20342
|
+
videoUrl: videoUpload.downloadUrl,
|
|
20343
|
+
videoMeta,
|
|
20344
|
+
traceKey,
|
|
20345
|
+
uploadStartTime,
|
|
20346
|
+
uploadEndTime,
|
|
20347
|
+
finderUsername: auth.finderUsername,
|
|
20348
|
+
http,
|
|
20349
|
+
logger: task.logger
|
|
20350
|
+
});
|
|
20351
|
+
currentStep = "发布视频";
|
|
20352
|
+
task.logger.info("[shipinhaoPublishVideo] 发布视频...");
|
|
20353
|
+
task.logger.info(`[shipinhaoPublishVideo] clipKey: ${clipResult.clipKey}`);
|
|
20354
|
+
let publishResult;
|
|
20355
|
+
try {
|
|
20356
|
+
publishResult = await publishVideo({
|
|
20357
|
+
params,
|
|
20358
|
+
auth,
|
|
20359
|
+
clipResult,
|
|
20360
|
+
videoUpload,
|
|
20361
|
+
coverUpload,
|
|
20362
|
+
traceKey,
|
|
20363
|
+
uploadStartTime,
|
|
20364
|
+
uploadEndTime,
|
|
20365
|
+
proxyHttp,
|
|
20366
|
+
logger: task.logger
|
|
20367
|
+
});
|
|
20368
|
+
} catch (error) {
|
|
20369
|
+
const handledError = Http.handleApiError(error);
|
|
20370
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布请求失败: ${handledError.message}`, stringifyError(handledError));
|
|
20371
|
+
const classified = classifyPublishError(handledError);
|
|
20372
|
+
if (classified) {
|
|
20373
|
+
const message = `${classified.userMessage}${task.debug ? ` ${http.proxyInfo}` : ""}`;
|
|
20374
|
+
task.logger.error(`[shipinhaoPublishVideo] ${classified.category},直接返回: ${handledError.message} (code=${handledError.code})`, stringifyError(handledError));
|
|
20375
|
+
await updateTaskState?.({
|
|
20376
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20377
|
+
error: message
|
|
20378
|
+
});
|
|
20379
|
+
return {
|
|
20380
|
+
code: 414,
|
|
20381
|
+
data: "",
|
|
20382
|
+
message
|
|
20383
|
+
};
|
|
20384
|
+
}
|
|
20385
|
+
throw error;
|
|
20386
|
+
}
|
|
20387
|
+
task.logger.info(`[shipinhaoPublishVideo] publishResult: ${JSON.stringify(publishResult)}`);
|
|
20388
|
+
const resultCode = publishResult.data?.baseResp?.errcode ?? publishResult.errCode;
|
|
20389
|
+
const resultMsg = publishResult.data?.baseResp?.errmsg ?? "发布成功";
|
|
20390
|
+
if (0 === resultCode) {
|
|
20391
|
+
task.logger.info("[shipinhaoPublishVideo] 发布成功");
|
|
20392
|
+
task.logger.info(`[shipinhaoPublishVideo] 作品ID: ${clipResult.clipKey}`);
|
|
20393
|
+
task.logger.info(`[shipinhaoPublishVideo] 视频URL: ${clipResult.url}`);
|
|
20394
|
+
task.logger.info(`[shipinhaoPublishVideo] 封面URL: ${coverUpload.downloadUrl}`);
|
|
20395
|
+
await updateTaskState?.({
|
|
20396
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.SUCCESS,
|
|
20397
|
+
result: {
|
|
20398
|
+
response: resultMsg
|
|
20399
|
+
}
|
|
20400
|
+
});
|
|
20401
|
+
reportLogger({
|
|
20402
|
+
token: params.huiwenToken || "",
|
|
20403
|
+
enverionment: task.enverionment || "development",
|
|
20404
|
+
postId: params.articleId,
|
|
20405
|
+
eip: proxyHttp.proxyInfo,
|
|
20406
|
+
accountId: params.accountId,
|
|
20407
|
+
uid: params.uid,
|
|
20408
|
+
publishParams: {
|
|
20409
|
+
videoPath: params.videoPath,
|
|
20410
|
+
coverPath: params.coverPath
|
|
20411
|
+
},
|
|
20412
|
+
platform: "shipinhao"
|
|
20413
|
+
});
|
|
20414
|
+
task.logger.info("[shipinhaoPublishVideo] 日志上报完成");
|
|
20415
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(0, "发布成功", clipResult.clipKey);
|
|
20416
|
+
}
|
|
20417
|
+
let errorMessage = resultMsg;
|
|
20418
|
+
if (-11224 === resultCode) errorMessage = "视频号管理员完成实名且绑定手机号后才可以发表";
|
|
20419
|
+
else if (300333 === resultCode || 300334 === resultCode) errorMessage = "登录失效";
|
|
20420
|
+
else if (300330 === resultCode) errorMessage = "未登录";
|
|
20421
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布失败: ${errorMessage} (errCode=${resultCode})`);
|
|
20422
|
+
await updateTaskState?.({
|
|
20423
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20424
|
+
error: errorMessage
|
|
20425
|
+
});
|
|
20426
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(resultCode || 414, errorMessage, "");
|
|
20427
|
+
} catch (error) {
|
|
20428
|
+
const handledError = Http.handleApiError(error);
|
|
20429
|
+
const errorMsg = handledError.message || "发布失败,请稍后重试";
|
|
20430
|
+
const errorCode = handledError.code || 414;
|
|
20431
|
+
task.logger.error(`[shipinhaoPublishVideo] 发布流程异常 [${currentStep}]: ${errorMsg}`, stringifyError(error), handledError.extra);
|
|
20432
|
+
task.logger.error(`[shipinhaoPublishVideo] 错误码: ${errorCode}, 当前步骤: ${currentStep}`);
|
|
20433
|
+
await updateTaskState?.({
|
|
20434
|
+
state: __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.TaskState.FAILED,
|
|
20435
|
+
error: errorMsg
|
|
20436
|
+
});
|
|
20437
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(errorCode, errorMsg, "");
|
|
20438
|
+
}
|
|
20439
|
+
};
|
|
20440
|
+
const shipinhaoPublishVideo_rpa_rpaAction = async (task, params)=>{
|
|
20441
|
+
task.logger.info("开始微信视频号视频发布(RPA 模式)");
|
|
20442
|
+
const videoMeta = parseVideoMeta(params.videoPath);
|
|
20443
|
+
if (!videoMeta) return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, "视频文件解析失败,请检查文件格式(仅支持 MP4)", "");
|
|
20444
|
+
task.logger.info(`视频: ${videoMeta.width}×${videoMeta.height}, ${videoMeta.duration.toFixed(2)}s, ${(videoMeta.fileSize / 1024 / 1024).toFixed(2)}MB, codec=${videoMeta.codec || "unknown"}`);
|
|
20445
|
+
const validationError = validateShipinhaoVideo(params.videoPath, videoMeta);
|
|
20446
|
+
if (validationError) {
|
|
20447
|
+
task.logger.error(`视频校验未通过: ${validationError}`);
|
|
20448
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, validationError, "");
|
|
20449
|
+
}
|
|
20450
|
+
task.logger.info("视频校验通过");
|
|
20451
|
+
const titleError = validateShipinhaoTitle(params.title);
|
|
20452
|
+
if (titleError) {
|
|
20453
|
+
task.logger.error(`标题校验未通过: ${titleError}`);
|
|
20454
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, titleError, "");
|
|
20455
|
+
}
|
|
20456
|
+
const tmpCachePath = task.getTmpPath();
|
|
20457
|
+
const page = await task.createPage({
|
|
20458
|
+
url: "https://channels.weixin.qq.com/platform/post/create",
|
|
20459
|
+
show: task.debug,
|
|
20460
|
+
cookies: params.cookies
|
|
20461
|
+
});
|
|
20462
|
+
try {
|
|
20463
|
+
const waitForElement = async (selector, timeout = 10000)=>{
|
|
20464
|
+
try {
|
|
20465
|
+
const element = page.locator(selector);
|
|
20466
|
+
await element.waitFor({
|
|
20467
|
+
state: "visible",
|
|
20468
|
+
timeout
|
|
20469
|
+
});
|
|
20470
|
+
return element;
|
|
20471
|
+
} catch {
|
|
20472
|
+
task.logger.warn(`元素未找到: ${selector}`);
|
|
20473
|
+
return null;
|
|
20474
|
+
}
|
|
20475
|
+
};
|
|
20476
|
+
const retryAction = async (action, maxRetries = 3, delay = 1000)=>{
|
|
20477
|
+
let lastError;
|
|
20478
|
+
for(let i = 0; i < maxRetries; i++)try {
|
|
20479
|
+
return await action();
|
|
20480
|
+
} catch (error) {
|
|
20481
|
+
lastError = error;
|
|
20482
|
+
task.logger.warn(`重试 ${i + 1}/${maxRetries}: ${lastError.message}`);
|
|
20483
|
+
if (i < maxRetries - 1) await page.waitForTimeout(delay);
|
|
20484
|
+
}
|
|
20485
|
+
throw lastError;
|
|
20486
|
+
};
|
|
20487
|
+
task.logger.info("等待页面加载...");
|
|
20488
|
+
task.logger.info("检查登录状态...");
|
|
20489
|
+
if (task.debug) {
|
|
20490
|
+
task.logger.info(`当前页面 URL: ${page.url()}`);
|
|
20491
|
+
const title = await page.title();
|
|
20492
|
+
task.logger.info(`页面标题: ${title}`);
|
|
20493
|
+
}
|
|
20494
|
+
try {
|
|
20495
|
+
await page.waitForSelector(".post-edit-wrap", {
|
|
20496
|
+
state: "visible",
|
|
20497
|
+
timeout: 30000
|
|
20498
|
+
});
|
|
20499
|
+
task.logger.info("✓ 登录状态正常,找到编辑器容器");
|
|
20500
|
+
} catch {
|
|
20501
|
+
task.logger.error("✗ 未找到编辑器,可能登录失效");
|
|
20502
|
+
return {
|
|
20503
|
+
code: 414,
|
|
20504
|
+
message: "登录失效或页面加载异常",
|
|
20505
|
+
data: page.url()
|
|
20506
|
+
};
|
|
20507
|
+
}
|
|
20508
|
+
task.logger.info("页面加载完成,开始填充内容");
|
|
20509
|
+
task.logger.info("开始上传视频");
|
|
20510
|
+
await retryAction(async ()=>{
|
|
20511
|
+
const videoUploadSelectors = [
|
|
20512
|
+
'.ant-upload-btn input[type="file"][accept*="video"]',
|
|
20513
|
+
'.upload input[type="file"][accept*="video"]',
|
|
20514
|
+
'input[type="file"][accept*="video"]'
|
|
20515
|
+
];
|
|
20516
|
+
let uploadInput = null;
|
|
20517
|
+
if (task.debug) {
|
|
20518
|
+
const allFileInputs = await page.locator('input[type="file"]').count();
|
|
20519
|
+
task.logger.info(`页面中共找到 ${allFileInputs} 个文件上传输入框`);
|
|
20520
|
+
}
|
|
20521
|
+
for (const selector of videoUploadSelectors){
|
|
20522
|
+
const input = page.locator(selector);
|
|
20523
|
+
const count = await input.count();
|
|
20524
|
+
if (count > 0) {
|
|
20525
|
+
uploadInput = input.first();
|
|
20526
|
+
task.logger.info(`找到视频上传输入框: ${selector}`);
|
|
20527
|
+
break;
|
|
20528
|
+
}
|
|
20529
|
+
}
|
|
20530
|
+
if (!uploadInput) {
|
|
20531
|
+
task.logger.warn("未找到视频上传输入框,等待 3 秒后重试...");
|
|
20532
|
+
await page.waitForTimeout(3000);
|
|
20533
|
+
const anyFileInput = page.locator('input[type="file"]');
|
|
20534
|
+
const inputCount = await anyFileInput.count();
|
|
20535
|
+
if (inputCount > 0) {
|
|
20536
|
+
uploadInput = anyFileInput.first();
|
|
20537
|
+
task.logger.info(`找到文件输入框(共 ${inputCount} 个)`);
|
|
20538
|
+
} else {
|
|
20539
|
+
if (task.debug) {
|
|
20540
|
+
const screenshotPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, `upload-error-${Date.now()}.png`);
|
|
20541
|
+
await page.screenshot({
|
|
20542
|
+
path: screenshotPath,
|
|
20543
|
+
fullPage: true
|
|
20544
|
+
});
|
|
20545
|
+
task.logger.error(`未找到上传输入框,已截图保存至: ${screenshotPath}`);
|
|
20546
|
+
}
|
|
20547
|
+
throw new Error("未找到视频上传输入框");
|
|
20548
|
+
}
|
|
20549
|
+
}
|
|
20550
|
+
await uploadInput.setInputFiles(params.videoPath);
|
|
20551
|
+
task.logger.info("视频上传成功");
|
|
20552
|
+
await page.waitForTimeout(5000);
|
|
20553
|
+
});
|
|
20554
|
+
if (params.coverPath) {
|
|
20555
|
+
task.logger.info("开始上传封面");
|
|
20556
|
+
await retryAction(async ()=>{
|
|
20557
|
+
const coverUploadBtn = await waitForElement(".cover-upload-btn", 10000);
|
|
20558
|
+
if (coverUploadBtn) {
|
|
20559
|
+
const coverInput = page.locator('.cover-upload-btn input[type="file"]');
|
|
20560
|
+
await coverInput.setInputFiles(params.coverPath);
|
|
20561
|
+
task.logger.info("封面上传成功");
|
|
20562
|
+
await page.waitForTimeout(2000);
|
|
20563
|
+
}
|
|
20564
|
+
});
|
|
20565
|
+
}
|
|
20566
|
+
if (params.description) {
|
|
20567
|
+
task.logger.info("填写视频描述");
|
|
20568
|
+
await retryAction(async ()=>{
|
|
20569
|
+
const descEditor = await waitForElement(".input-editor", 10000);
|
|
20570
|
+
if (!descEditor) throw new Error("未找到描述编辑器");
|
|
20571
|
+
await descEditor.click();
|
|
20572
|
+
await page.waitForTimeout(500);
|
|
20573
|
+
await descEditor.evaluate((el)=>{
|
|
20574
|
+
el.textContent = "";
|
|
20575
|
+
});
|
|
20576
|
+
await page.waitForTimeout(300);
|
|
20577
|
+
task.logger.info("已清空编辑器内容");
|
|
20578
|
+
await descEditor.pressSequentially(params.description, {
|
|
20579
|
+
delay: 10
|
|
20580
|
+
});
|
|
20581
|
+
await page.waitForTimeout(500);
|
|
20582
|
+
task.logger.info("描述填写完成");
|
|
20583
|
+
});
|
|
20584
|
+
}
|
|
20585
|
+
if (params.title) {
|
|
20586
|
+
task.logger.info(`填写标题: ${params.title}`);
|
|
20587
|
+
const title = params.title;
|
|
20588
|
+
await retryAction(async ()=>{
|
|
20589
|
+
const titleInput = await waitForElement("#container-wrap div.form-item-body.short-title-wrap input", 10000);
|
|
20590
|
+
if (!titleInput) throw new Error("未找到标题输入框");
|
|
20591
|
+
await titleInput.click();
|
|
20592
|
+
await titleInput.clear({
|
|
20593
|
+
timeout: 3000
|
|
20594
|
+
});
|
|
20595
|
+
await titleInput.fill(title, {
|
|
20596
|
+
timeout: 5000
|
|
20597
|
+
});
|
|
20598
|
+
task.logger.info("标题填写完成");
|
|
20599
|
+
});
|
|
20600
|
+
}
|
|
20601
|
+
if (params.location) {
|
|
20602
|
+
task.logger.info(`选择地点: ${params.location.city}`);
|
|
20603
|
+
const instance = page.locator(".position-display-wrap");
|
|
20604
|
+
await instance.click();
|
|
20605
|
+
await page.waitForTimeout(1000);
|
|
20606
|
+
await page.locator(".location-filter-wrap input").fill(params.location.city);
|
|
20607
|
+
await page.waitForTimeout(2000);
|
|
20608
|
+
const poperInstance = page.locator(".location-filter-wrap .common-option-list-wrap .option-item");
|
|
20609
|
+
await poperInstance.nth(1).waitFor();
|
|
20610
|
+
await poperInstance.nth(1).click();
|
|
20611
|
+
task.logger.info("地点选择完成");
|
|
20612
|
+
}
|
|
20613
|
+
if (params.scheduleTime) {
|
|
20614
|
+
task.logger.info("设置定时发布");
|
|
20615
|
+
const timingRadio = page.locator(".weui-desktop-form__check-label").filter({
|
|
20616
|
+
hasNotText: "不定时"
|
|
20617
|
+
}).first();
|
|
20618
|
+
await timingRadio.click();
|
|
20619
|
+
await page.waitForTimeout(500);
|
|
20620
|
+
const instance = page.locator(".weui-desktop-picker__date");
|
|
20621
|
+
await instance.click();
|
|
20622
|
+
const dateD = utils_TimeFormatter.format(1000 * params.scheduleTime, "d");
|
|
20623
|
+
const nowMonth = utils_TimeFormatter.format(Date.now(), "MM月");
|
|
20624
|
+
const nowMonthText = utils_TimeFormatter.format(Date.now(), "M月");
|
|
20625
|
+
const month = utils_TimeFormatter.format(1000 * params.scheduleTime, "MM月");
|
|
20626
|
+
const monthLocator = await page.locator("weui-desktop-picker__panel__label").filter({
|
|
20627
|
+
hasText: month
|
|
20628
|
+
}).first();
|
|
20629
|
+
if (!monthLocator) {
|
|
20630
|
+
await page.locator(".weui-desktop-picker__panel__label").filter({
|
|
20631
|
+
hasText: nowMonth
|
|
20632
|
+
}).first().click();
|
|
20633
|
+
await page.waitForTimeout(500);
|
|
20634
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
20635
|
+
hasText: nowMonthText
|
|
20636
|
+
}).first().click();
|
|
20637
|
+
}
|
|
20638
|
+
await page.waitForTimeout(500);
|
|
20639
|
+
await page.locator(".weui-desktop-picker__table-row td a").filter({
|
|
20640
|
+
hasText: dateD
|
|
20641
|
+
}).first().click();
|
|
20642
|
+
await page.locator(".weui-desktop-form__input-wrp input[placeholder*='请选择时间']").fill(utils_TimeFormatter.format(1000 * params.scheduleTime, "hh:mm"));
|
|
20643
|
+
await page.locator("i.weui-desktop-icon__time").click();
|
|
20644
|
+
await page.locator(".post-time-wrap .form-item .label").filter({
|
|
20645
|
+
hasText: "发表时间"
|
|
20646
|
+
}).click();
|
|
20647
|
+
}
|
|
20648
|
+
task.logger.info("准备发布...");
|
|
20649
|
+
await page.waitForTimeout(300);
|
|
20650
|
+
let videoId = "";
|
|
20651
|
+
const handleResponse = async (response)=>{
|
|
20652
|
+
const url = response.url();
|
|
20653
|
+
if (url.includes("/post/post_create")) {
|
|
20654
|
+
const jsonResponse = await response.json();
|
|
20655
|
+
page.off("response", handleResponse);
|
|
20656
|
+
videoId = jsonResponse.object?.id || jsonResponse.data?.objectId || "";
|
|
20657
|
+
}
|
|
20658
|
+
};
|
|
20659
|
+
page.on("response", handleResponse);
|
|
20660
|
+
task._timerRecord.PrePublish = Date.now();
|
|
20661
|
+
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";
|
|
20662
|
+
task.logger.info("等待视频上传完成(预览区媒体操作栏出现)...");
|
|
20663
|
+
const uploadTimeout = 600000;
|
|
20664
|
+
const uploadWaitStart = Date.now();
|
|
20665
|
+
let lastProgressLog = 0;
|
|
20666
|
+
while(true){
|
|
20667
|
+
const ready = await page.evaluate((selector)=>{
|
|
20668
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
20669
|
+
const root = host?.shadowRoot;
|
|
20670
|
+
if (!root) return false;
|
|
20671
|
+
return !!root.querySelector(selector);
|
|
20672
|
+
}, MEDIA_OPR_SELECTOR);
|
|
20673
|
+
if (ready) break;
|
|
20674
|
+
const elapsed = Date.now() - uploadWaitStart;
|
|
20675
|
+
if (elapsed > uploadTimeout) throw new Error(`视频上传超时,预览区未就绪(已等待 ${Math.round(elapsed / 1000)}s)`);
|
|
20676
|
+
if (elapsed - lastProgressLog >= 15000) {
|
|
20677
|
+
lastProgressLog = elapsed;
|
|
20678
|
+
task.logger.info(`视频仍在上传中... 已等待 ${Math.round(elapsed / 1000)}s`);
|
|
20679
|
+
}
|
|
20680
|
+
await page.waitForTimeout(1000);
|
|
20681
|
+
}
|
|
20682
|
+
task.logger.info(`视频上传完成(等待 ${Math.round((Date.now() - uploadWaitStart) / 1000)}s)`);
|
|
20683
|
+
const clicked = await page.evaluate(()=>{
|
|
20684
|
+
const host = document.querySelector("#container-wrap > div.container-center > div > wujie-app");
|
|
20685
|
+
const root = host?.shadowRoot;
|
|
20686
|
+
if (!root) return "未找到 wujie-app shadowRoot";
|
|
20687
|
+
const btns = Array.from(root.querySelectorAll(".form-btns .weui-desktop-btn"));
|
|
20688
|
+
const target = btns.find((el)=>(el.textContent || "").includes("发表"));
|
|
20689
|
+
if (!target) return "未找到发表按钮";
|
|
20690
|
+
if (target.classList.contains("weui-desktop-btn_disabled")) return "发表按钮仍处于禁用状态";
|
|
20691
|
+
target.click();
|
|
20692
|
+
return null;
|
|
20693
|
+
});
|
|
20694
|
+
if (clicked) throw new Error(clicked);
|
|
20695
|
+
task.logger.info("已点击发布按钮,等待响应...");
|
|
20696
|
+
try {
|
|
20697
|
+
await page.waitForURL((url)=>url.href !== page.url(), {
|
|
20698
|
+
timeout: 30000
|
|
20699
|
+
});
|
|
20700
|
+
task.logger.info(`发布成功,页面已跳转: ${page.url()}`);
|
|
20701
|
+
} catch {
|
|
20702
|
+
task.logger.warn("等待页面跳转超时,可能发布失败或网络慢,继续关闭页面");
|
|
20703
|
+
}
|
|
20704
|
+
await page.close();
|
|
20705
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(videoId, "发布成功");
|
|
20706
|
+
} catch (error) {
|
|
20707
|
+
let errorMsg = error instanceof Error ? error.message : String(error);
|
|
20708
|
+
if (errorMsg.includes("context or browser has been closed")) errorMsg = "浏览器上下文已被关闭";
|
|
20709
|
+
task.logger.error(`微信视频号视频发布失败: ${errorMsg}`);
|
|
20710
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.response)(414, `微信视频号视频发布失败: ${errorMsg}`, "");
|
|
20711
|
+
}
|
|
20712
|
+
};
|
|
20713
|
+
const ShipinhaoPublishVideoParamsSchema = ActionCommonParamsSchema.extend({
|
|
20714
|
+
videoPath: schemas_string().min(1),
|
|
20715
|
+
coverPath: schemas_string().min(1),
|
|
20716
|
+
description: schemas_string(),
|
|
20717
|
+
title: schemas_string().optional(),
|
|
20718
|
+
scheduleTime: schemas_number().int().positive().optional(),
|
|
20719
|
+
location: schemas_object({
|
|
20720
|
+
latitude: schemas_number(),
|
|
20721
|
+
longitude: schemas_number(),
|
|
20722
|
+
city: schemas_string(),
|
|
20723
|
+
poiClassifyId: schemas_string().optional()
|
|
20724
|
+
}).optional()
|
|
20725
|
+
});
|
|
20726
|
+
const shipinhaoPublishVideo = async (task, params)=>{
|
|
20727
|
+
task.logger.info(`shipinhaoPublishVideo actionType: ${params.actionType}`);
|
|
20728
|
+
if ("rpa" === params.actionType) return shipinhaoPublishVideo_rpa_rpaAction(task, params);
|
|
20729
|
+
if ("mockApi" === params.actionType) return shipinhaoPublishVideo_mock_mockAction(task, params);
|
|
20730
|
+
return executeAction(shipinhaoPublishVideo_mock_mockAction, shipinhaoPublishVideo_rpa_rpaAction)(task, params);
|
|
20731
|
+
};
|
|
19630
20732
|
const ShipinhaoSendMsgParamsSchema = ActionCommonParamsSchema.extend({
|
|
19631
20733
|
toUsername: schemas_string().min(1, "接收者用户名不能为空"),
|
|
19632
20734
|
sessionId: schemas_string().min(1, "会话ID不能为空"),
|
|
@@ -19641,7 +20743,7 @@ const ShipinhaoSendMsgParamsSchema = ActionCommonParamsSchema.extend({
|
|
|
19641
20743
|
pathOrUrl: schemas_string().min(1, "图片路径或URL不能为空")
|
|
19642
20744
|
}).optional()
|
|
19643
20745
|
});
|
|
19644
|
-
const
|
|
20746
|
+
const shipinhaoSendMsg_CHUNK_SIZE = 524288;
|
|
19645
20747
|
async function shipinhaoSendMsg_getUserInfo(cookieStr, http) {
|
|
19646
20748
|
const url = `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/auth/auth_data?_rid=${rid()}`;
|
|
19647
20749
|
const headers = {
|
|
@@ -19724,11 +20826,11 @@ const shipinhaoSendMsg = async (_task, params)=>{
|
|
|
19724
20826
|
}
|
|
19725
20827
|
const md5 = (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)("md5").update(imageBuffer).digest("hex");
|
|
19726
20828
|
const timestamp = Date.now().toString();
|
|
19727
|
-
const totalChunks = Math.ceil(imageBuffer.length /
|
|
20829
|
+
const totalChunks = Math.ceil(imageBuffer.length / shipinhaoSendMsg_CHUNK_SIZE);
|
|
19728
20830
|
console.log(`分片上传md5${md5}`);
|
|
19729
20831
|
let lastRes;
|
|
19730
20832
|
for(let i = 0; i < totalChunks; i++){
|
|
19731
|
-
const chunkBuffer = imageBuffer.slice(i *
|
|
20833
|
+
const chunkBuffer = imageBuffer.slice(i * shipinhaoSendMsg_CHUNK_SIZE, (i + 1) * shipinhaoSendMsg_CHUNK_SIZE);
|
|
19732
20834
|
const requestData = {
|
|
19733
20835
|
content: `data:application/octet-stream;base64,${chunkBuffer.toString("base64")}`,
|
|
19734
20836
|
chunk: i,
|
|
@@ -20181,6 +21283,13 @@ const toutiaoPublish_mock_mockAction = async (task, params)=>{
|
|
|
20181
21283
|
const uploadImages = async (images)=>await Promise.all(images.map(async (url)=>{
|
|
20182
21284
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
20183
21285
|
const image = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
21286
|
+
const stats = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].statSync(image);
|
|
21287
|
+
const maxSize = 20971520;
|
|
21288
|
+
if (stats.size > maxSize) throw {
|
|
21289
|
+
code: 414,
|
|
21290
|
+
message: "头条号平台:单张图片不得超过 20MB",
|
|
21291
|
+
data: ""
|
|
21292
|
+
};
|
|
20184
21293
|
const formData = new __WEBPACK_EXTERNAL_MODULE_form_data_cf000082__["default"]();
|
|
20185
21294
|
formData.append("image", __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].createReadStream(image));
|
|
20186
21295
|
const response = await http.api({
|
|
@@ -23464,6 +24573,12 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
23464
24573
|
const fileName = (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.getFilenameFromUrl)(url);
|
|
23465
24574
|
const localUrl = await (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.downloadImage)(url, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(tmpCachePath, fileName));
|
|
23466
24575
|
const fileBuffer = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(localUrl);
|
|
24576
|
+
const maxSize = 33554432;
|
|
24577
|
+
if (fileBuffer.byteLength > maxSize) throw {
|
|
24578
|
+
code: 414,
|
|
24579
|
+
message: "小红书平台:单张图片不得超过 32MB",
|
|
24580
|
+
data: ""
|
|
24581
|
+
};
|
|
23467
24582
|
let width = 0;
|
|
23468
24583
|
let height = 0;
|
|
23469
24584
|
try {
|
|
@@ -25648,6 +26763,9 @@ class Action {
|
|
|
25648
26763
|
shipinhaoPublish(params) {
|
|
25649
26764
|
return this.bindTask(shipinhaoPublish, params);
|
|
25650
26765
|
}
|
|
26766
|
+
shipinhaoPublishVideo(params) {
|
|
26767
|
+
return this.bindTask(shipinhaoPublishVideo, params);
|
|
26768
|
+
}
|
|
25651
26769
|
douyinGetTopics(params) {
|
|
25652
26770
|
return this.bindTask(douyinGetTopics, params);
|
|
25653
26771
|
}
|
|
@@ -25701,7 +26819,7 @@ class Action {
|
|
|
25701
26819
|
}
|
|
25702
26820
|
}
|
|
25703
26821
|
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 };
|
|
26822
|
+
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
26823
|
|
|
25706
26824
|
//# sourceMappingURL=index.mjs.map
|
|
25707
|
-
//# debugId=
|
|
26825
|
+
//# debugId=19f291bd-1860-5dc2-abcf-dd482b04a403
|