@iflyrpa/actions 1.1.18 → 1.1.20
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/toutiaoPublish/index.d.ts +1 -0
- package/dist/bundle.js +40 -31
- package/dist/bundle.js.map +1 -1
- package/dist/index.js +40 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -31
- package/dist/index.mjs.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -12887,7 +12887,7 @@ var __webpack_exports__ = {};
|
|
|
12887
12887
|
addResponseInterceptor(findError) {
|
|
12888
12888
|
this.apiClient.interceptors.response.use((response)=>{
|
|
12889
12889
|
const error = findError(response);
|
|
12890
|
-
return error ? Promise.reject(error) : response
|
|
12890
|
+
return error ? Promise.reject(error) : response;
|
|
12891
12891
|
}, (error)=>{
|
|
12892
12892
|
const errorResponse = {
|
|
12893
12893
|
code: error.response?.status || 500,
|
|
@@ -12974,31 +12974,44 @@ var __webpack_exports__ = {};
|
|
|
12974
12974
|
const handler = new esm_DomHandler((error, dom)=>{
|
|
12975
12975
|
if (error) console.log(error);
|
|
12976
12976
|
else dom.forEach(traverseDom);
|
|
12977
|
-
lastedHtml = esm(dom
|
|
12977
|
+
lastedHtml = esm(dom, {
|
|
12978
|
+
decodeEntities: false
|
|
12979
|
+
});
|
|
12980
|
+
});
|
|
12981
|
+
const parser = new Parser_Parser(handler, {
|
|
12982
|
+
decodeEntities: false
|
|
12978
12983
|
});
|
|
12979
|
-
const parser = new Parser_Parser(handler);
|
|
12980
12984
|
parser.write(html);
|
|
12981
12985
|
parser.end();
|
|
12982
12986
|
return lastedHtml;
|
|
12983
12987
|
};
|
|
12988
|
+
const stringifyError = (error)=>{
|
|
12989
|
+
if (error instanceof Error) return error;
|
|
12990
|
+
if ("object" == typeof error) return JSON.stringify(error);
|
|
12991
|
+
return error;
|
|
12992
|
+
};
|
|
12984
12993
|
const executeAction = (...actions)=>async (task, params)=>{
|
|
12985
12994
|
let result = {
|
|
12986
12995
|
code: 500,
|
|
12987
12996
|
message: "所有操作均失败",
|
|
12988
12997
|
data: null
|
|
12989
12998
|
};
|
|
12990
|
-
for
|
|
12991
|
-
const
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
|
|
12996
|
-
|
|
12999
|
+
for(let index = 0; index < actions.length; index++){
|
|
13000
|
+
const action = actions[index];
|
|
13001
|
+
try {
|
|
13002
|
+
const currentResult = await action(task, params);
|
|
13003
|
+
if (0 === currentResult.code) return currentResult;
|
|
13004
|
+
task.logger.error(currentResult.message, stringifyError(currentResult.data));
|
|
13005
|
+
result = currentResult;
|
|
13006
|
+
} catch (error) {
|
|
13007
|
+
result = Http.handleApiError(error);
|
|
13008
|
+
if (index !== actions.length - 1) task.logger.error(result.message, stringifyError(result.data));
|
|
13009
|
+
}
|
|
12997
13010
|
}
|
|
12998
13011
|
return result;
|
|
12999
13012
|
};
|
|
13000
13013
|
async function copyHtmlToClipboard(page, html, options = {
|
|
13001
|
-
format:
|
|
13014
|
+
format: "text/html",
|
|
13002
13015
|
fallback: true
|
|
13003
13016
|
}) {
|
|
13004
13017
|
try {
|
|
@@ -13019,8 +13032,8 @@ var __webpack_exports__ = {};
|
|
|
13019
13032
|
});
|
|
13020
13033
|
} catch (error) {
|
|
13021
13034
|
if (options.fallback) await page.evaluate((htmlContent)=>{
|
|
13022
|
-
const div = document.createElement(
|
|
13023
|
-
div.contentEditable =
|
|
13035
|
+
const div = document.createElement("div");
|
|
13036
|
+
div.contentEditable = "true";
|
|
13024
13037
|
div.style.cssText = `
|
|
13025
13038
|
position: fixed;
|
|
13026
13039
|
left: -9999px;
|
|
@@ -13034,7 +13047,7 @@ var __webpack_exports__ = {};
|
|
|
13034
13047
|
const selection = window.getSelection();
|
|
13035
13048
|
selection.removeAllRanges();
|
|
13036
13049
|
selection.addRange(range);
|
|
13037
|
-
document.execCommand(
|
|
13050
|
+
document.execCommand("copy");
|
|
13038
13051
|
document.body.removeChild(div);
|
|
13039
13052
|
selection.removeAllRanges();
|
|
13040
13053
|
}, html);
|
|
@@ -13147,31 +13160,29 @@ var __webpack_exports__ = {};
|
|
|
13147
13160
|
url: "https://baijiahao.baidu.com/builder/app/appinfo",
|
|
13148
13161
|
defaultErrorMsg: "创建草稿失败,请稍后重试。"
|
|
13149
13162
|
});
|
|
13150
|
-
const appId = appIdInfo.user.app_id;
|
|
13163
|
+
const appId = appIdInfo.data.user.app_id;
|
|
13151
13164
|
const uploadImages = async (_images)=>{
|
|
13152
13165
|
const images = _images.filter((url)=>!!url && "" !== url.trim());
|
|
13153
|
-
|
|
13166
|
+
return await Promise.all(images.map(async (url)=>{
|
|
13154
13167
|
const fileName = getFilenameFromUrl(url);
|
|
13155
|
-
|
|
13156
|
-
}));
|
|
13157
|
-
const orgList = await Promise.all(localImages.map(async (image)=>{
|
|
13168
|
+
const image = await downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
|
|
13158
13169
|
const formData = new (form_data_default())();
|
|
13170
|
+
formData.append("org_file_name", fileName);
|
|
13159
13171
|
formData.append("type", "image");
|
|
13172
|
+
formData.append("app_id", appId);
|
|
13160
13173
|
formData.append("is_waterlog", "1");
|
|
13161
13174
|
formData.append("save_material", "1");
|
|
13162
13175
|
formData.append("no_compress", "0");
|
|
13163
13176
|
formData.append("article_type", "news");
|
|
13164
|
-
formData.append("app_id", appId);
|
|
13165
13177
|
formData.append("media", external_node_fs_default().createReadStream(image));
|
|
13166
13178
|
const res = await http.api({
|
|
13167
13179
|
method: "post",
|
|
13168
|
-
url: "https://baijiahao.baidu.com/
|
|
13180
|
+
url: "https://baijiahao.baidu.com/materialui/picture/uploadProxy",
|
|
13169
13181
|
data: formData,
|
|
13170
13182
|
defaultErrorMsg: "draft" === params.saveType ? "图片上传异常,请稍后重试同步。" : "图片上传异常,请稍后重试发布。"
|
|
13171
13183
|
});
|
|
13172
13184
|
return res.ret;
|
|
13173
13185
|
}));
|
|
13174
|
-
return orgList;
|
|
13175
13186
|
};
|
|
13176
13187
|
const originContentImages = extractImgTag(params.content);
|
|
13177
13188
|
const targetContentImages = await uploadImages(originContentImages);
|
|
@@ -13535,6 +13546,7 @@ var __webpack_exports__ = {};
|
|
|
13535
13546
|
return error || ("draft" === saveType ? "文章同步异常,请稍后重试。" : "文章发布异常,请稍后重试。");
|
|
13536
13547
|
};
|
|
13537
13548
|
const mock_mockAction = async (task, params)=>{
|
|
13549
|
+
task.logger.info("开始头条 MockApi 发布");
|
|
13538
13550
|
const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType, toutiaoOriginal } = params.settingInfo;
|
|
13539
13551
|
const tmpCachePath = task.getTmpPath();
|
|
13540
13552
|
const http = new Http({
|
|
@@ -13560,23 +13572,19 @@ var __webpack_exports__ = {};
|
|
|
13560
13572
|
url: "https://mp.toutiao.com/mp/agw/creator_center/user_info",
|
|
13561
13573
|
defaultErrorMsg: `头条号登录状态失效,请重新绑定账号后${"draft" === params.saveType ? "同步" : "发布"}。`
|
|
13562
13574
|
});
|
|
13563
|
-
const uploadImages = async (images)=>{
|
|
13564
|
-
const localImages = await Promise.all(images.map((url)=>{
|
|
13575
|
+
const uploadImages = async (images)=>await Promise.all(images.map(async (url)=>{
|
|
13565
13576
|
const fileName = getFilenameFromUrl(url);
|
|
13566
|
-
|
|
13567
|
-
}));
|
|
13568
|
-
return await Promise.all(localImages.map(async (image)=>{
|
|
13577
|
+
const image = await downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
|
|
13569
13578
|
const formData = new (form_data_default())();
|
|
13570
13579
|
formData.append("image", external_node_fs_default().createReadStream(image));
|
|
13571
13580
|
const response = await http.api({
|
|
13572
13581
|
method: "post",
|
|
13573
|
-
url: "https://mp.toutiao.com/spice/image?upload_source=
|
|
13582
|
+
url: "https://mp.toutiao.com/spice/image?upload_source=20020002&aid=1231&device_platform=web",
|
|
13574
13583
|
data: formData,
|
|
13575
13584
|
defaultErrorMsg: "draft" === params.saveType ? "图片上传异常,请稍后重试同步。" : "图片上传异常,请稍后重试发布。"
|
|
13576
13585
|
});
|
|
13577
13586
|
return response.data;
|
|
13578
13587
|
}));
|
|
13579
|
-
};
|
|
13580
13588
|
const originContentImages = extractImgTag(params.content);
|
|
13581
13589
|
const targetContentImages = await uploadImages(originContentImages);
|
|
13582
13590
|
const content = replaceImgSrc(params.content, (dom)=>{
|
|
@@ -13687,6 +13695,7 @@ var __webpack_exports__ = {};
|
|
|
13687
13695
|
return success(publishResult.data.pgc_id);
|
|
13688
13696
|
};
|
|
13689
13697
|
const rpa_rpaAction = async (task, params)=>{
|
|
13698
|
+
task.logger.info("开始头条 RPA 发布");
|
|
13690
13699
|
const tmpCachePath = task.getTmpPath();
|
|
13691
13700
|
const commonCookies = {
|
|
13692
13701
|
path: "/",
|
|
@@ -14885,7 +14894,7 @@ var __webpack_exports__ = {};
|
|
|
14885
14894
|
return executeAction(xiaohongshuPublish_mock_mockAction, xiaohongshuPublish_rpa_rpaAction)(task, params);
|
|
14886
14895
|
};
|
|
14887
14896
|
var package_namespaceObject = {
|
|
14888
|
-
i8: "1.1.
|
|
14897
|
+
i8: "1.1.19"
|
|
14889
14898
|
};
|
|
14890
14899
|
class Action {
|
|
14891
14900
|
constructor(task){
|
|
@@ -14898,7 +14907,7 @@ var __webpack_exports__ = {};
|
|
|
14898
14907
|
} catch (error) {
|
|
14899
14908
|
responseData = Http.handleApiError(error);
|
|
14900
14909
|
}
|
|
14901
|
-
if (0 !== responseData.code) this.task.logger.error(responseData.message || `${func.name} 执行失败`, responseData.data);
|
|
14910
|
+
if (0 !== responseData.code) this.task.logger.error(responseData.message || `${func.name} 执行失败`, stringifyError(responseData.data));
|
|
14902
14911
|
return responseData;
|
|
14903
14912
|
}
|
|
14904
14913
|
searchToutiaoTopicList(params) {
|