@iflyrpa/actions 3.0.2 → 3.0.3

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/bundle.js CHANGED
@@ -8733,9 +8733,11 @@ var __webpack_exports__ = {};
8733
8733
  navigator: ()=>_navigator,
8734
8734
  origin: ()=>utils_origin
8735
8735
  });
8736
- var package_namespaceObject = JSON.parse('{"i8":"0.1.0-beta.1"}');
8736
+ var package_namespaceObject = {
8737
+ i8: "0.1.0"
8738
+ };
8737
8739
  var package_namespaceObject_0 = {
8738
- i8: "3.0.1"
8740
+ i8: "3.0.2"
8739
8741
  };
8740
8742
  const external_node_fs_namespaceObject = require("node:fs");
8741
8743
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
@@ -28421,7 +28423,7 @@ var __webpack_exports__ = {};
28421
28423
  data: null
28422
28424
  });
28423
28425
  const MockPublish = false;
28424
- const DisabledReq = true;
28426
+ const DisabledReq = false;
28425
28427
  const scanRetryMaxCount = 60;
28426
28428
  const waitQrcodeResultMaxTime = 2000 * scanRetryMaxCount;
28427
28429
  const rpaServer = async (task, params)=>{
@@ -43498,291 +43500,6 @@ var __webpack_exports__ = {};
43498
43500
  if ("server" === params.actionType) return xiaohongshuLogin_rpa_server_rpaServer(task, params);
43499
43501
  return executeAction(xiaohongshuLogin_rpa_rpaAction)(task, params);
43500
43502
  };
43501
- const FictionalRendition = classic_schemas_object({
43502
- type: literal("fictional-rendition")
43503
- });
43504
- const AIGenerated = classic_schemas_object({
43505
- type: literal("ai-generated")
43506
- });
43507
- const SourceStatement = classic_schemas_object({
43508
- type: literal("source-statement"),
43509
- childType: classic_schemas_enum([
43510
- "self-labeling",
43511
- "self-shooting",
43512
- "transshipment"
43513
- ]),
43514
- shootingLocation: custom().optional(),
43515
- shootingDate: classic_schemas_string().optional(),
43516
- sourceMedia: classic_schemas_string().optional()
43517
- });
43518
- schemas_union([
43519
- FictionalRendition,
43520
- AIGenerated,
43521
- SourceStatement
43522
- ]);
43523
- const XiaohongshuPublishParamsSchema = ActionCommonParamsSchema.extend({
43524
- banners: classic_schemas_array(classic_schemas_string()),
43525
- title: classic_schemas_string(),
43526
- content: classic_schemas_string(),
43527
- address: custom().optional(),
43528
- selfDeclaration: custom().optional(),
43529
- topic: classic_schemas_array(custom()).optional(),
43530
- proxyLoc: classic_schemas_string().optional(),
43531
- localIP: classic_schemas_string().optional(),
43532
- huiwenToken: classic_schemas_string().optional(),
43533
- visibleRange: classic_schemas_enum([
43534
- "public",
43535
- "private",
43536
- "friends"
43537
- ]),
43538
- isImmediatelyPublish: classic_schemas_boolean().optional(),
43539
- scheduledPublish: classic_schemas_string().optional(),
43540
- collectionId: classic_schemas_string().optional(),
43541
- collectionBind: custom().optional(),
43542
- groupBind: custom().optional(),
43543
- noteCopyBind: classic_schemas_boolean().optional(),
43544
- coProduceBind: classic_schemas_boolean().optional(),
43545
- originalBind: classic_schemas_boolean().optional()
43546
- });
43547
- const xiaohongshuPublish = async (_task, _params)=>({
43548
- code: 414,
43549
- data: "",
43550
- message: "临时维护:小红书发布政策调整,本平台小红书发布功能临时暂停服务并进行维护调整,暂时无法正常发布,敬请理解知悉。"
43551
- });
43552
- const xiaohongshuWebCommentAction_xsEncrypt = new Xhshow();
43553
- const xiaohongshuWebCommentAction = async (_task, params)=>{
43554
- if (DisabledReq) return utils_response(414, "点赞相关操作失败", {});
43555
- const headers = {
43556
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
43557
- referer: "https://www.xiaohongshu.com/",
43558
- origin: "https://www.xiaohongshu.com/"
43559
- };
43560
- const args = [
43561
- {
43562
- headers
43563
- },
43564
- _task.logger,
43565
- params.proxyLoc,
43566
- params.localIP,
43567
- params.accountId
43568
- ];
43569
- const http = new Http(...args);
43570
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
43571
- if (!a1Cookie) return {
43572
- code: 414,
43573
- message: "账号数据异常,请重新绑定账号后重试。",
43574
- data: []
43575
- };
43576
- if (!params.note_id && !params.comment_id && !params.action) return {
43577
- code: 414,
43578
- message: "参数缺失,请检查后重试!",
43579
- data: {}
43580
- };
43581
- const actionParams = {
43582
- note_id: params.note_id,
43583
- comment_id: params.comment_id
43584
- };
43585
- let likeActionRes = {
43586
- code: 500,
43587
- success: false,
43588
- msg: ""
43589
- };
43590
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
43591
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
43592
- return acc;
43593
- }, {});
43594
- switch(params.action){
43595
- case "like":
43596
- {
43597
- const likeAction = "/api/sns/web/v1/comment/like";
43598
- const likeActionXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(likeAction, recordCookie, "xhs-pc-web", actionParams);
43599
- likeActionRes = await http.api({
43600
- method: "post",
43601
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/like",
43602
- data: actionParams,
43603
- headers: likeActionXsHeader
43604
- }, {
43605
- retries: 3,
43606
- retryDelay: 20,
43607
- timeout: 3000
43608
- });
43609
- break;
43610
- }
43611
- case "dislike":
43612
- {
43613
- const dislikeMentions = "/api/sns/web/v1/comment/dislike";
43614
- const dislikeXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(dislikeMentions, recordCookie, "xhs-pc-web", actionParams);
43615
- likeActionRes = await http.api({
43616
- method: "post",
43617
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/dislike",
43618
- data: actionParams,
43619
- headers: dislikeXsHeader
43620
- }, {
43621
- retries: 3,
43622
- retryDelay: 20,
43623
- timeout: 3000
43624
- });
43625
- break;
43626
- }
43627
- default:
43628
- return {
43629
- code: 414,
43630
- message: "参数action错误,请重试!",
43631
- data: {}
43632
- };
43633
- }
43634
- const isSuccess = 0 === likeActionRes.code;
43635
- const message = `点赞相关操作${isSuccess ? "成功" : `失败,原因:${likeActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
43636
- const data = isSuccess ? likeActionRes.success : {};
43637
- return utils_response(isSuccess ? 0 : 414, message, data);
43638
- };
43639
- const xiaohongshuWebIntimacySearch = async (_task, params)=>{
43640
- if (DisabledReq) return utils_response(0, "搜索@列表数据成功", []);
43641
- const headers = {
43642
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
43643
- referer: "https://www.xiaohongshu.com/",
43644
- origin: "https://www.xiaohongshu.com"
43645
- };
43646
- const args = [
43647
- {
43648
- headers
43649
- },
43650
- _task.logger,
43651
- params.proxyLoc,
43652
- params.localIP,
43653
- params.accountId
43654
- ];
43655
- const http = new Http(...args);
43656
- let intimacyDetail = [];
43657
- const res = await http.api({
43658
- method: "get",
43659
- url: `https://edith.xiaohongshu.com/api/sns/web/v1/intimacy/intimacy_list${params.searchValue ? "/search" : ""}`,
43660
- ...params.searchValue ? {
43661
- params: {
43662
- keyword: params.searchValue,
43663
- page: 1,
43664
- rows: 30
43665
- }
43666
- } : {}
43667
- }, {
43668
- retries: 3,
43669
- retryDelay: 20,
43670
- timeout: 3000
43671
- });
43672
- const isSuccess = 0 === res.code;
43673
- if (isSuccess) intimacyDetail = res.data.items;
43674
- const message = `搜索@列表数据${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
43675
- return utils_response(isSuccess ? 0 : 414, message, intimacyDetail);
43676
- };
43677
- const xiaohongshuWebMsgRead_xsEncrypt = new Xhshow();
43678
- const xiaohongshuWebMsgRead = async (_task, params)=>{
43679
- if (DisabledReq) return utils_response(414, "Read指定Tab失败", {});
43680
- const headers = {
43681
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
43682
- referer: "https://www.xiaohongshu.com/",
43683
- origin: "https://www.xiaohongshu.com/"
43684
- };
43685
- const args = [
43686
- {
43687
- headers
43688
- },
43689
- _task.logger,
43690
- params.proxyLoc,
43691
- params.localIP,
43692
- params.accountId
43693
- ];
43694
- const http = new Http(...args);
43695
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
43696
- if (!a1Cookie) return {
43697
- code: 414,
43698
- message: "账号数据异常,请重新绑定账号后重试。",
43699
- data: []
43700
- };
43701
- if (!params.type) return {
43702
- code: 414,
43703
- message: "参数缺失,请检查后重试!",
43704
- data: {}
43705
- };
43706
- const replyParams = {
43707
- type: params.type
43708
- };
43709
- const fatchMentions = "/api/sns/web/v1/message/read";
43710
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
43711
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
43712
- return acc;
43713
- }, {});
43714
- const fatchMentionsXsHeader = xiaohongshuWebMsgRead_xsEncrypt.signHeadersPost(fatchMentions, recordCookie, "xhs-pc-web", replyParams);
43715
- const res = await http.api({
43716
- method: "post",
43717
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/message/read",
43718
- data: replyParams,
43719
- headers: fatchMentionsXsHeader
43720
- }, {
43721
- retries: 3,
43722
- retryDelay: 20,
43723
- timeout: 3000
43724
- });
43725
- const isSuccess = 0 === res.code;
43726
- const message = `Read指定Tab${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
43727
- const data = isSuccess ? res.success : {};
43728
- return utils_response(isSuccess ? 0 : 414, message, data);
43729
- };
43730
- const xiaohongshuWebMsgReply_xsEncrypt = new Xhshow();
43731
- const xiaohongshuWebMsgReply = async (_task, params)=>{
43732
- if (DisabledReq) return utils_response(414, "评论回复失败", {});
43733
- const headers = {
43734
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
43735
- referer: "https://www.xiaohongshu.com/",
43736
- origin: "https://www.xiaohongshu.com/"
43737
- };
43738
- const args = [
43739
- {
43740
- headers
43741
- },
43742
- _task.logger,
43743
- params.proxyLoc,
43744
- params.localIP,
43745
- params.accountId
43746
- ];
43747
- const http = new Http(...args);
43748
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
43749
- if (!a1Cookie) return {
43750
- code: 414,
43751
- message: "账号数据异常,请重新绑定账号后重试。",
43752
- data: []
43753
- };
43754
- if (!params.note_id || !params.target_comment_id || !params.content) return {
43755
- code: 414,
43756
- message: "参数缺失,请检查后重试!",
43757
- data: {}
43758
- };
43759
- const replyParams = {
43760
- at_users: params.at_users ?? [],
43761
- content: params.content,
43762
- note_id: params.note_id,
43763
- target_comment_id: params.target_comment_id
43764
- };
43765
- const replyPath = "/api/sns/web/v1/comment/post";
43766
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
43767
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
43768
- return acc;
43769
- }, {});
43770
- const replyXsHeader = xiaohongshuWebMsgReply_xsEncrypt.signHeadersPost(replyPath, recordCookie, "xhs-pc-web", replyParams);
43771
- const res = await http.api({
43772
- method: "post",
43773
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/post",
43774
- data: replyParams,
43775
- headers: replyXsHeader
43776
- }, {
43777
- retries: 3,
43778
- retryDelay: 20,
43779
- timeout: 3000
43780
- });
43781
- const isSuccess = 0 === res.code;
43782
- const message = `评论回复${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
43783
- const data = isSuccess ? res.data : {};
43784
- return utils_response(isSuccess ? 0 : 414, message, data);
43785
- };
43786
43503
  let _windowCache = null;
43787
43504
  const getWindow = ()=>{
43788
43505
  if (_windowCache) return _windowCache;
@@ -43838,336 +43555,7 @@ var __webpack_exports__ = {};
43838
43555
  };
43839
43556
  }
43840
43557
  }
43841
- const xiaohongshuWebNoteFeed_xsEncrypt = new xhs_ob_feed_Xhshow();
43842
- const GenXSCommon = __webpack_require__("./src/utils/XhsXsCommonEnc.js");
43843
- const xiaohongshuWebNoteFeed = async (_task, params)=>{
43844
- if (DisabledReq) return utils_response(414, "获取指定文章详情失败", {});
43845
- const headers = {
43846
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
43847
- referer: "https://www.xiaohongshu.com/",
43848
- origin: "https://www.xiaohongshu.com/"
43849
- };
43850
- const args = [
43851
- {
43852
- headers
43853
- },
43854
- _task.logger,
43855
- params.proxyLoc,
43856
- params.localIP,
43857
- params.accountId
43858
- ];
43859
- const http = new Http(...args);
43860
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
43861
- if (!a1Cookie) return {
43862
- code: 414,
43863
- message: "账号数据异常,请重新绑定账号后重试。",
43864
- data: {}
43865
- };
43866
- if (!params.source_note_id && !params.xsec_token) return {
43867
- code: 414,
43868
- message: "参数缺失,请检查后重试!",
43869
- data: {}
43870
- };
43871
- const feedParams = {
43872
- source_note_id: params.source_note_id,
43873
- image_formats: [
43874
- "jpg",
43875
- "webp",
43876
- "avif"
43877
- ],
43878
- extra: {
43879
- need_body_topic: "1"
43880
- },
43881
- xsec_source: "pc_feed",
43882
- xsec_token: params.xsec_token
43883
- };
43884
- const fatchFeed = "/api/sns/web/v1/feed";
43885
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
43886
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
43887
- return acc;
43888
- }, {});
43889
- const xsHeader = xiaohongshuWebNoteFeed_xsEncrypt.signHeadersPost(fatchFeed, recordCookie, "xhs-pc-web", feedParams);
43890
- const xT = Date.now().toString();
43891
- const xsCommon = GenXSCommon(a1Cookie, xT, xsHeader["X-S"]);
43892
- _task.logger.info(`请求参数: ${JSON.stringify(feedParams)}`);
43893
- _task.logger.info(`X-S: ${xsHeader["X-S"]}`);
43894
- _task.logger.info(`x-s-common: ${xsCommon}`);
43895
- const res = await http.api({
43896
- method: "post",
43897
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/feed",
43898
- data: feedParams,
43899
- headers: {
43900
- "X-S": xsHeader["X-S"],
43901
- "X-S-Common": xsCommon,
43902
- "X-T": xT
43903
- }
43904
- }, {
43905
- retries: 3,
43906
- retryDelay: 20,
43907
- timeout: 3000
43908
- });
43909
- _task.logger.info(`API 响应: ${JSON.stringify(res)}`);
43910
- const isSuccess = 0 === res.code && res.data && res.data.items && res.data.items.length > 0;
43911
- const message = `获取指定文章详情${isSuccess ? "成功" : `失败,原因:${res.msg || "返回数据为空,可能笔记不存在或参数错误"}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
43912
- const data = isSuccess ? res.data?.items[0].note_card || {} : {};
43913
- return utils_response(isSuccess ? 0 : 414, message, data);
43914
- };
43915
- const xiaohongshuWebRelationAction_xsEncrypt = new Xhshow();
43916
- const xiaohongshuWebRelationAction = async (_task, params)=>{
43917
- if (DisabledReq) return utils_response(414, "用户关系操作失败", {});
43918
- const headers = {
43919
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
43920
- referer: "https://www.xiaohongshu.com/",
43921
- origin: "https://www.xiaohongshu.com/"
43922
- };
43923
- const args = [
43924
- {
43925
- headers
43926
- },
43927
- _task.logger,
43928
- params.proxyLoc,
43929
- params.localIP,
43930
- params.accountId
43931
- ];
43932
- const http = new Http(...args);
43933
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
43934
- if (!a1Cookie) return {
43935
- code: 414,
43936
- message: "账号数据异常,请重新绑定账号后重试。",
43937
- data: {}
43938
- };
43939
- if (!params.action || !params.target_user_id) return {
43940
- code: 414,
43941
- message: "参数缺失,请检查后重试!",
43942
- data: {}
43943
- };
43944
- const relationParams = {
43945
- target_user_id: params.target_user_id
43946
- };
43947
- let relationActionRes;
43948
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
43949
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
43950
- return acc;
43951
- }, {});
43952
- switch(params.action){
43953
- case "follow":
43954
- {
43955
- const followMentions = "/api/sns/web/v1/user/follow";
43956
- const followXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(followMentions, recordCookie, "xhs-pc-web", relationParams);
43957
- relationActionRes = await http.api({
43958
- method: "post",
43959
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/follow",
43960
- data: relationParams,
43961
- headers: followXsHeader
43962
- }, {
43963
- retries: 3,
43964
- retryDelay: 500,
43965
- timeout: 3000
43966
- });
43967
- break;
43968
- }
43969
- case "unfollow":
43970
- {
43971
- const unfllowMentions = "/api/sns/web/v1/user/unfollow";
43972
- const unfllowXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(unfllowMentions, recordCookie, "xhs-pc-web", relationParams);
43973
- relationActionRes = await http.api({
43974
- method: "post",
43975
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/unfollow",
43976
- data: relationParams,
43977
- headers: unfllowXsHeader
43978
- }, {
43979
- retries: 3,
43980
- retryDelay: 20,
43981
- timeout: 3000
43982
- });
43983
- break;
43984
- }
43985
- default:
43986
- return {
43987
- code: 414,
43988
- message: "参数action错误,请重试!",
43989
- data: {}
43990
- };
43991
- }
43992
- const isSuccess = 0 === relationActionRes.code;
43993
- const message = `用户关系操作${isSuccess ? "成功" : `失败,原因:${relationActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
43994
- const data = isSuccess ? relationActionRes.data : {
43995
- fstatus: null
43996
- };
43997
- return utils_response(isSuccess ? 0 : 414, message, data);
43998
- };
43999
- const xiaohongshuWebSearch_xsEncrypt = new Xhshow();
44000
- const XhsWebSearchParamsSchema = ActionCommonParamsSchema.extend({
44001
- keyword: classic_schemas_string(),
44002
- page: classic_schemas_number(),
44003
- page_size: classic_schemas_number(),
44004
- sort_type: classic_schemas_enum([
44005
- "general",
44006
- "time_descending",
44007
- "popular_descending"
44008
- ]),
44009
- time_filter: classic_schemas_enum([
44010
- "不限",
44011
- "一周内"
44012
- ])
44013
- });
44014
- const createSearchId = ()=>{
44015
- let r = BigInt(Date.now());
44016
- const o = BigInt(Math.ceil(0x7ffffffe * Math.random()));
44017
- r <<= BigInt(64);
44018
- r += o;
44019
- return r.toString(36);
44020
- };
44021
- const xiaohongshuWebSearch = async (_task, params)=>{
44022
- const headers = {
44023
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
44024
- referer: "https://www.xiaohongshu.com/",
44025
- origin: "https://www.xiaohongshu.com/"
44026
- };
44027
- const args = [
44028
- {
44029
- headers
44030
- },
44031
- _task.logger,
44032
- params.proxyLoc,
44033
- params.localIP,
44034
- params.accountId
44035
- ];
44036
- const http = new Http(...args);
44037
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
44038
- if (!a1Cookie) return {
44039
- code: 414,
44040
- message: "账号数据异常,请重新绑定账号后重试。",
44041
- data: {}
44042
- };
44043
- if (!params.keyword || !params.page || !params.page_size || !params.sort_type || !params.time_filter) {
44044
- if ("general" !== params.sort_type && "time_descending" !== params.sort_type && "popular_descending" !== params.sort_type) return {
44045
- code: 414,
44046
- message: "排序类型参数错误,请检查后重试!",
44047
- data: {}
44048
- };
44049
- if ("不限" !== params.time_filter && "一周内" !== params.time_filter) return {
44050
- code: 414,
44051
- message: "时间过滤参数错误,请检查后重试!",
44052
- data: {}
44053
- };
44054
- return {
44055
- code: 414,
44056
- message: "参数缺失,请检查后重试!",
44057
- data: {}
44058
- };
44059
- }
44060
- const filterPath = "/api/sns/web/v1/search/notes";
44061
- const filterParams = {
44062
- ext_flags: [],
44063
- geo: "",
44064
- image_formats: [
44065
- "jpg",
44066
- "webp",
44067
- "avif"
44068
- ],
44069
- filters: [
44070
- {
44071
- tags: [
44072
- params.sort_type
44073
- ],
44074
- type: "sort_type"
44075
- },
44076
- {
44077
- tags: [
44078
- "不限"
44079
- ],
44080
- type: "filter_note_type"
44081
- },
44082
- {
44083
- tags: [
44084
- params.time_filter
44085
- ],
44086
- type: "filter_note_time"
44087
- },
44088
- {
44089
- tags: [
44090
- "不限"
44091
- ],
44092
- type: "filter_note_range"
44093
- },
44094
- {
44095
- tags: [
44096
- "不限"
44097
- ],
44098
- type: "filter_pos_distance"
44099
- }
44100
- ],
44101
- keyword: params.keyword,
44102
- note_type: 0,
44103
- page: params.page,
44104
- page_size: params.page_size,
44105
- search_id: createSearchId() + (params.sort_type || params.time_filter ? `@${createSearchId()}` : ""),
44106
- sort: "general"
44107
- };
44108
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
44109
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
44110
- return acc;
44111
- }, {});
44112
- const searchXsHeader = xiaohongshuWebSearch_xsEncrypt.signHeadersPost(filterPath, recordCookie, "xhs-pc-web", filterParams);
44113
- const res = await http.api({
44114
- method: "post",
44115
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/search/notes",
44116
- data: filterParams,
44117
- headers: searchXsHeader
44118
- }, {
44119
- retries: 3,
44120
- retryDelay: 20,
44121
- timeout: 3000
44122
- });
44123
- const isSuccess = 0 === res.code;
44124
- const message = `Web笔记搜索${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
44125
- const data = isSuccess ? res.data : {};
44126
- return utils_response(isSuccess ? 0 : 414, message, data);
44127
- };
44128
- const ttConfigDataSchema = classic_schemas_object({
44129
- fansNum: classic_schemas_number(),
44130
- fansNumYesterday: classic_schemas_number().nullable(),
44131
- readNum: classic_schemas_number(),
44132
- incomeNum: classic_schemas_number(),
44133
- incomeNumYesterday: classic_schemas_number().nullable(),
44134
- showNumYesterday: classic_schemas_number().nullable(),
44135
- readNumYesterday: classic_schemas_number().nullable(),
44136
- likeNumYesterday: classic_schemas_number().nullable(),
44137
- commentNumYesterday: classic_schemas_number().nullable()
44138
- });
44139
- const xhsConfigDataSchema = classic_schemas_object({
44140
- fansNum: classic_schemas_number(),
44141
- favedNum: classic_schemas_number(),
44142
- watchNumLastWeek: classic_schemas_number(),
44143
- likeNumLastWeek: classic_schemas_number(),
44144
- collectNumLastWeek: classic_schemas_number(),
44145
- commentNumLastWeek: classic_schemas_number(),
44146
- fansNumLastWeek: classic_schemas_number(),
44147
- fansNumYesterday: classic_schemas_number()
44148
- });
44149
- const wxConfigDataSchema = classic_schemas_object({
44150
- fansNum: classic_schemas_number(),
44151
- fansNumYesterday: classic_schemas_number(),
44152
- readNumYesterday: classic_schemas_number(),
44153
- shareNumYesterday: classic_schemas_number()
44154
- });
44155
- const bjhConfigDataSchema = classic_schemas_object({
44156
- fansNum: classic_schemas_number(),
44157
- fansNumYesterday: classic_schemas_number().nullable(),
44158
- readNum: classic_schemas_number(),
44159
- incomeNum: classic_schemas_number(),
44160
- incomeNumYesterday: classic_schemas_number().nullable(),
44161
- recommendNumYesterday: classic_schemas_number().nullable(),
44162
- readNumYesterday: classic_schemas_number().nullable(),
44163
- likeNumYesterday: classic_schemas_number().nullable(),
44164
- commentNumYesterday: classic_schemas_number().nullable()
44165
- });
44166
- const rpa_server_mock_encode_mnsv2 = __webpack_require__("./src/utils/xhs_ob/x_s.encoder.js");
44167
- function Md5(input) {
44168
- return external_node_crypto_default().createHash("md5").update(input).digest("hex");
44169
- }
44170
- const rpa_server_mock_errnoMap = {
43558
+ const xiaohongshuPublish_mock_errnoMap = {
44171
43559
  "-1": "未知拦截器错误,请稍后重试。",
44172
43560
  915: "所属C端账号手机号被修改,请重新登录",
44173
43561
  914: "所属C端账号密码被修改,请重新登录",
@@ -44176,9 +43564,8 @@ var __webpack_exports__ = {};
44176
43564
  906: "账号存在风险,请重新登录!",
44177
43565
  "-9136": "因违反社区规范禁止发笔记,请检查账号状态!"
44178
43566
  };
44179
- const rpa_server_mock_xsEncrypt = new Xhshow();
44180
- const rpaAction_Server_Mock = async (task, params)=>{
44181
- const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
43567
+ const mock_xsEncrypt = new xhs_ob_feed_Xhshow();
43568
+ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
44182
43569
  const tmpCachePath = task.getTmpPath();
44183
43570
  if (params?.selfDeclaration?.type === "source-statement" && "transshipment" === params.selfDeclaration.childType && params.originalBind) return {
44184
43571
  code: 414,
@@ -44191,49 +43578,6 @@ var __webpack_exports__ = {};
44191
43578
  message: "账号数据异常,请重新绑定账号后重试。",
44192
43579
  data: ""
44193
43580
  };
44194
- const defaultPage = task.steelBrowserContext?.pages()[0];
44195
- if (defaultPage) {
44196
- if (!defaultPage._routeRegistered) {
44197
- defaultPage._routeRegistered = true;
44198
- const blockedPatterns = [
44199
- "**/ffmpeg-core.wasm*",
44200
- "**/apm-fe.xiaohongshu.com*",
44201
- "**/t2.xiaohongshu.com*",
44202
- "**/fe-video-qc.xhscdn.com*"
44203
- ].map((pattern)=>new RegExp(pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*")));
44204
- await defaultPage.route("**/*", async (route)=>{
44205
- const req = route.request();
44206
- const url = req.url();
44207
- const blocked = blockedPatterns.some((regex)=>regex.test(url));
44208
- if (!blocked) return route.continue();
44209
- if ("OPTIONS" === req.method()) {
44210
- console.log("处理 OPTIONS 预检:", url);
44211
- await route.fulfill({
44212
- status: 204,
44213
- headers: {
44214
- "access-control-allow-origin": "*",
44215
- "access-control-allow-methods": "GET,POST,OPTIONS,PUT,DELETE",
44216
- "access-control-allow-headers": "*"
44217
- },
44218
- body: ""
44219
- });
44220
- return;
44221
- }
44222
- await route.fulfill({
44223
- status: 204,
44224
- body: ""
44225
- });
44226
- });
44227
- }
44228
- }
44229
- const pagePromise = task.createPage({
44230
- show: task.debug,
44231
- cookies: params.cookies,
44232
- url: params.url || "https://creator.xiaohongshu.com/statistics/account/v2?source=official"
44233
- });
44234
- await updateTaskState?.({
44235
- state: types_TaskState.ACTION
44236
- });
44237
43581
  const headers = {
44238
43582
  cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
44239
43583
  origin: "https://creator.xiaohongshu.com",
@@ -44260,9 +43604,9 @@ var __webpack_exports__ = {};
44260
43604
  proxyHttp.addResponseInterceptor((response)=>{
44261
43605
  const responseData = response.data;
44262
43606
  if (response && responseData?.code && 0 !== responseData.code || responseData?.code && !responseData.success) {
44263
- const errmsg = rpa_server_mock_errnoMap[responseData.code] || response.config.defaultErrorMsg || "文章发布异常,请稍后重试。";
43607
+ const errmsg = xiaohongshuPublish_mock_errnoMap[responseData.code] || response.config.defaultErrorMsg || "文章发布异常,请稍后重试。";
44264
43608
  return {
44265
- code: rpa_server_mock_errnoMap[responseData.code] ? 414 : 500,
43609
+ code: xiaohongshuPublish_mock_errnoMap[responseData.code] ? 414 : 500,
44266
43610
  message: errmsg,
44267
43611
  data: responseData
44268
43612
  };
@@ -44276,10 +43620,10 @@ var __webpack_exports__ = {};
44276
43620
  version: 1,
44277
43621
  source: "web"
44278
43622
  };
44279
- const fetchCoverXsHeader = rpa_server_mock_xsEncrypt.signHeadersGet(fetchCoverUrl, recordCookie, "ugc", fetchCoverParams);
43623
+ const fetchCoverXsHeader = mock_xsEncrypt.signHeadersGet(fetchCoverUrl, recordCookie, "ugc", fetchCoverParams);
44280
43624
  const uploadInfos = [];
44281
43625
  if (params.banners.length > 18) {
44282
- let num = Math.ceil(params.banners.length / 14);
43626
+ const num = Math.ceil(params.banners.length / 14);
44283
43627
  for(let i = 0; i < num; i++){
44284
43628
  const start = 14 * i;
44285
43629
  params.banners.length;
@@ -44343,7 +43687,6 @@ var __webpack_exports__ = {};
44343
43687
  const localUrl = await downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
44344
43688
  const fileBuffer = external_node_fs_default().readFileSync(localUrl);
44345
43689
  const MAX_RETRIES = uploadInfos.length;
44346
- task.logger.debug(`上传图片 ${index + 1}:尝试使用最多 ${MAX_RETRIES} 个 bucket`);
44347
43690
  let attempt = 0;
44348
43691
  while(attempt < MAX_RETRIES){
44349
43692
  const ossBucketIndex = availableBuckets.shift();
@@ -44367,7 +43710,6 @@ var __webpack_exports__ = {};
44367
43710
  ossToken
44368
43711
  };
44369
43712
  } catch (error) {
44370
- task.logger.warn(`上传图片 ${index + 1}:使用 bucket ${ossDomain} 失败,尝试下一个可用 bucket。错误信息:${error.message}`);
44371
43713
  attempt++;
44372
43714
  }
44373
43715
  }
@@ -44388,7 +43730,7 @@ var __webpack_exports__ = {};
44388
43730
  const topicData = {
44389
43731
  topic_names: topic.name
44390
43732
  };
44391
- const topicXsHeader = rpa_server_mock_xsEncrypt.signHeadersPost("/web_api/sns/capa/postgw/topic/batch_customized", recordCookie, "ugc", topicData);
43733
+ const topicXsHeader = mock_xsEncrypt.signHeadersPost("/web_api/sns/capa/postgw/topic/batch_customized", recordCookie, "ugc", topicData);
44392
43734
  const createTopic = await proxyHttp.api({
44393
43735
  method: "POST",
44394
43736
  url: "https://edith.xiaohongshu.com/web_api/sns/capa/postgw/topic/batch_customized",
@@ -44400,7 +43742,8 @@ var __webpack_exports__ = {};
44400
43742
  retryDelay: 20,
44401
43743
  timeout: 3000
44402
43744
  });
44403
- Object.assign(topic, createTopic.data.topic_infos[0]);
43745
+ if (!createTopic?.data) throw types_errorResponse("话题创建失败,请检查话题字段!", 414);
43746
+ Object.assign(topic, createTopic?.data?.topic_infos[0]);
44404
43747
  }
44405
43748
  }));
44406
43749
  const visibleRangeMap = {
@@ -44531,28 +43874,9 @@ var __webpack_exports__ = {};
44531
43874
  } : {}
44532
43875
  };
44533
43876
  publishData.common.business_binds = JSON.stringify(business_binds);
43877
+ const publishXsHeader = mock_xsEncrypt.signHeadersPost("/web_api/sns/v2/note", recordCookie, "ugc", publishData);
44534
43878
  task._timerRecord.PrePublish = Date.now();
44535
- const page = await pagePromise;
44536
- await updateTaskState?.({
44537
- sessionId: task.sessionId
44538
- });
44539
- const publishXsHeader = {
44540
- "x-s": "",
44541
- "x-t": Date.now().toString()
44542
- };
44543
- await page.waitForFunction(()=>"function" == typeof window.mnsv2, {
44544
- timeout: 10000
44545
- });
44546
- const encodeData = `/web_api/sns/v2/note${JSON.stringify(publishData)}`;
44547
- const ticket_mnsv2 = await page.evaluate(({ c, d })=>{
44548
- if ("function" == typeof window.mnsv2) return window.mnsv2(c, d);
44549
- return "mnsv2 未定义";
44550
- }, {
44551
- c: encodeData,
44552
- d: Md5(encodeData)
44553
- });
44554
- publishXsHeader["x-s"] = rpa_server_mock_encode_mnsv2(ticket_mnsv2, "Windows", "object");
44555
- publishXsHeader["x-t"] = Date.now().toString();
43879
+ const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
44556
43880
  if (MockPublish) {
44557
43881
  const message = `文章模拟发布成功 ${http.proxyInfo}`;
44558
43882
  const data = "123456789";
@@ -44575,6 +43899,17 @@ var __webpack_exports__ = {};
44575
43899
  retryDelay: 500,
44576
43900
  timeout: 12000
44577
43901
  });
43902
+ reportLogger({
43903
+ token: params.huiwenToken || "",
43904
+ enverionment: task.enverionment || "development",
43905
+ postId: params.articleId,
43906
+ eip: proxyHttp.proxyInfo,
43907
+ proxyIp: params.localIP,
43908
+ accountId: params.accountId,
43909
+ uid: params.uid,
43910
+ platform: "xiaohongshu",
43911
+ publishParams: publishData
43912
+ });
44578
43913
  const isSuccess = publishResult.success;
44579
43914
  const message = `文章发布${isSuccess ? "成功" : `失败,原因:${publishResult.msg}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
44580
43915
  const data = isSuccess ? publishResult.data?.id || "" : "";
@@ -44595,8 +43930,1642 @@ var __webpack_exports__ = {};
44595
43930
  response: data
44596
43931
  }
44597
43932
  });
44598
- return success(data, message);
43933
+ return utils_response(isSuccess ? 0 : 414, message, data);
43934
+ };
43935
+ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
43936
+ const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
43937
+ const commonCookies = {
43938
+ path: "/",
43939
+ sameSite: "lax",
43940
+ secure: false,
43941
+ domain: ".xiaohongshu.com",
43942
+ url: "https://creator.xiaohongshu.com",
43943
+ httpOnly: true
43944
+ };
43945
+ const page = await task.createPage({
43946
+ show: task.debug,
43947
+ url: params.url || "https://creator.xiaohongshu.com/publish/publish",
43948
+ cookies: params.cookies?.map((it)=>({
43949
+ ...it,
43950
+ ...commonCookies
43951
+ }))
43952
+ });
43953
+ await updateTaskState?.({
43954
+ state: types_TaskState.ACTION,
43955
+ connectAddress: task.steelConnector?.getProxyUrl(task.sessionId || "", "v1/sessions/debug"),
43956
+ sessionId: task.sessionId
43957
+ });
43958
+ const tmpCachePath = task.getTmpPath();
43959
+ const selectAddress = async (selector, address)=>{
43960
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
43961
+ await instance.click();
43962
+ await instance.locator("input").fill(address);
43963
+ const poperInstance = page.locator('.d-popover:not([style*="display: none"]) .d-options .d-grid-item');
43964
+ await poperInstance.first().waitFor();
43965
+ await poperInstance.first().click();
43966
+ };
43967
+ const selectDate = async (selector, date)=>{
43968
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
43969
+ await instance.click();
43970
+ await instance.fill(date);
43971
+ await instance.blur();
43972
+ };
43973
+ const getPoperInstance = async ()=>{
43974
+ await page.waitForTimeout(500);
43975
+ const elements = page.locator(".d-popover");
43976
+ const count = await elements.count();
43977
+ const visibleElements = [];
43978
+ for(let i = 0; i < count; i++){
43979
+ const element = elements.nth(i);
43980
+ const style = await element.getAttribute("style");
43981
+ if (style && !style.includes("display: none")) visibleElements.push(element);
43982
+ }
43983
+ if (visibleElements.length > 0) return visibleElements[visibleElements.length - 1];
43984
+ throw new Error("未找到 popover 弹窗");
43985
+ };
43986
+ const getDialogInstance = async ()=>{
43987
+ await page.waitForTimeout(1000);
43988
+ const elements = page.locator(".el-dialog");
43989
+ return elements.last();
43990
+ };
43991
+ try {
43992
+ await page.waitForSelector("#CreatorPlatform", {
43993
+ state: "visible"
43994
+ });
43995
+ } catch (error) {
43996
+ return {
43997
+ code: 414,
43998
+ message: "登录失效",
43999
+ data: page.url()
44000
+ };
44001
+ }
44002
+ await page.locator("#content-area .menu-container .publish-video .btn-wrapper .btn-inner").click();
44003
+ await page.locator('.header-tabs .creator-tab:not([style*="-9999px"])').filter({
44004
+ hasText: /^上传图文$/
44005
+ }).click();
44006
+ const images = await Promise.all(params.banners.map((url)=>{
44007
+ const fileName = getFilenameFromUrl(url);
44008
+ return downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
44009
+ }));
44010
+ const fileChooser = await page.$("input.upload-input");
44011
+ if (fileChooser) await fileChooser.setInputFiles(images);
44012
+ const titleInstance = page.locator(".input input");
44013
+ await titleInstance.waitFor({
44014
+ state: "visible",
44015
+ timeout: 50000
44016
+ });
44017
+ await titleInstance.click();
44018
+ await titleInstance.fill(params.title);
44019
+ const descInstance = page.locator(".editor-container .tiptap.ProseMirror");
44020
+ await descInstance.click();
44021
+ await descInstance.pressSequentially(params.content.replace(/#.*?\[.*?]#/g, ""));
44022
+ if (params.topic && params.topic.length > 0) for (const it of params.topic){
44023
+ await descInstance.pressSequentially(`#${it.name}`);
44024
+ await page.locator("#creator-editor-topic-container").waitFor({
44025
+ state: "visible"
44026
+ });
44027
+ await page.waitForTimeout(500);
44028
+ await page.locator("#creator-editor-topic-container .item").first().click();
44029
+ }
44030
+ if (params.address) await selectAddress(page.locator(".address-card-wrapper .d-select-wrapper"), params.address.name);
44031
+ if (params.selfDeclaration) {
44032
+ await page.locator(".declaration-wrapper .d-select-wrapper").click();
44033
+ const poperInstance = await getPoperInstance();
44034
+ const selfDeclarationInstance = poperInstance.locator(".d-options .d-option");
44035
+ if ("fictional-rendition" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
44036
+ hasText: "虚构演绎,仅供娱乐"
44037
+ }).click();
44038
+ else if ("ai-generated" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
44039
+ hasText: "笔记含AI合成内容"
44040
+ }).click();
44041
+ else if ("source-statement" === params.selfDeclaration.type) {
44042
+ await selfDeclarationInstance.filter({
44043
+ hasText: /内容来源声明/
44044
+ }).click();
44045
+ const selfDeclarationSecondaryMenuInstance = (await getPoperInstance()).locator(".d-options .d-option");
44046
+ await selfDeclarationSecondaryMenuInstance.first().waitFor();
44047
+ if ("self-labeling" === params.selfDeclaration.childType) await selfDeclarationSecondaryMenuInstance.filter({
44048
+ hasText: "已在正文中自主标注"
44049
+ }).click();
44050
+ else if ("self-shooting" === params.selfDeclaration.childType) {
44051
+ const { shootingDate, shootingLocation } = params.selfDeclaration;
44052
+ await selfDeclarationSecondaryMenuInstance.filter({
44053
+ hasText: "自主拍摄"
44054
+ }).click();
44055
+ const selfShootingPopup = await getDialogInstance();
44056
+ const hasCustomContent = shootingDate || shootingLocation;
44057
+ if (shootingLocation) await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation.name);
44058
+ if (shootingDate) await selectDate(selfShootingPopup.locator(".date-picker input"), shootingDate);
44059
+ await selfShootingPopup.locator("footer button").filter({
44060
+ hasText: hasCustomContent ? "确认" : "取消"
44061
+ }).click();
44062
+ } else if ("transshipment" === params.selfDeclaration.childType) {
44063
+ await selfDeclarationSecondaryMenuInstance.filter({
44064
+ hasText: "来源转载"
44065
+ }).click();
44066
+ const selfShootingPopup = await getDialogInstance();
44067
+ const sourceMedia = params.selfDeclaration.sourceMedia;
44068
+ if (sourceMedia) await selfShootingPopup.locator(".el-input input").fill(sourceMedia);
44069
+ await selfShootingPopup.locator("footer button").filter({
44070
+ hasText: sourceMedia ? "确认" : "取消"
44071
+ }).click();
44072
+ }
44073
+ }
44074
+ }
44075
+ if ("private" === params.visibleRange) {
44076
+ await page.locator(".publish-page-content-setting-content .d-select-wrapper").last().click();
44077
+ const poperInstance = await getPoperInstance();
44078
+ await poperInstance.locator(".d-options .d-option").filter({
44079
+ hasText: "仅自己可见"
44080
+ }).click();
44081
+ }
44082
+ task._timerRecord.PrePublish = Date.now();
44083
+ const releaseTimeInstance = page.locator("label").filter({
44084
+ hasText: params.isImmediatelyPublish ? "立即发布" : "定时发布"
44085
+ });
44086
+ await releaseTimeInstance.click();
44087
+ if (params.scheduledPublish) await selectDate(".date-picker input", params.scheduledPublish);
44088
+ await page.waitForFunction(()=>{
44089
+ const publishBtn = Array.from(document.querySelectorAll("button")).find((b)=>b.textContent?.trim() === "发布");
44090
+ const uploading = document.querySelector(".progress-container");
44091
+ return !!publishBtn && !uploading;
44092
+ }, {
44093
+ timeout: 180000,
44094
+ polling: 2000
44095
+ });
44096
+ const response = await new Promise((resolve, reject)=>{
44097
+ const handleResponse = async (response)=>{
44098
+ if (response.url().includes("/web_api/sns/v2/note")) {
44099
+ const jsonResponse = await response.json();
44100
+ page.off("response", handleResponse);
44101
+ if (jsonResponse?.success) resolve(jsonResponse?.data?.id);
44102
+ else reject(new Error(jsonResponse?.msg || "发布失败"));
44103
+ }
44104
+ };
44105
+ page.on("response", handleResponse);
44106
+ page.locator(".publish-page-publish-btn button").filter({
44107
+ hasText: "发布"
44108
+ }).click();
44109
+ });
44110
+ await updateTaskState?.({
44111
+ state: types_TaskState.SUCCESS,
44112
+ result: {
44113
+ response
44114
+ }
44115
+ });
44116
+ await page.close();
44117
+ return success(response);
44599
44118
  };
44119
+ const xiaohongshuPublish_rpa_server_rpaAction_Server = async (task, params)=>{
44120
+ if (params.originalBind && params?.selfDeclaration?.type === "source-statement") return {
44121
+ code: 414,
44122
+ message: "已声明原创不可选择“来源转载”",
44123
+ data: ""
44124
+ };
44125
+ const defaultPage = task.steelBrowserContext?.pages()[0];
44126
+ if (defaultPage) {
44127
+ if (!defaultPage._routeRegistered) {
44128
+ defaultPage._routeRegistered = true;
44129
+ const blockedPatterns = [
44130
+ "**/ffmpeg-core.wasm*",
44131
+ "**/apm-fe.xiaohongshu.com*",
44132
+ "**/t2.xiaohongshu.com*",
44133
+ "**/fe-video-qc.xhscdn.com*"
44134
+ ].map((pattern)=>new RegExp(pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*")));
44135
+ await defaultPage.route("**/*", async (route)=>{
44136
+ const req = route.request();
44137
+ const url = req.url();
44138
+ const blocked = blockedPatterns.some((regex)=>regex.test(url));
44139
+ if (!blocked) return route.continue();
44140
+ if ("OPTIONS" === req.method()) {
44141
+ console.log("处理 OPTIONS 预检:", url);
44142
+ await route.fulfill({
44143
+ status: 204,
44144
+ headers: {
44145
+ "access-control-allow-origin": "*",
44146
+ "access-control-allow-methods": "GET,POST,OPTIONS,PUT,DELETE",
44147
+ "access-control-allow-headers": "*"
44148
+ },
44149
+ body: ""
44150
+ });
44151
+ return;
44152
+ }
44153
+ await route.fulfill({
44154
+ status: 204,
44155
+ body: ""
44156
+ });
44157
+ });
44158
+ }
44159
+ }
44160
+ const tmpCachePath = task.getTmpPath();
44161
+ task.logger?.info("==>进入RPA操作:任务开始,下载图片开始...");
44162
+ const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
44163
+ const imagePromise = Promise.all(params.banners.map((url)=>{
44164
+ const fileName = getFilenameFromUrl(url);
44165
+ return downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
44166
+ }));
44167
+ let proxyUrl;
44168
+ if (params.localIP) {
44169
+ const args = [
44170
+ params.localIP,
44171
+ params.proxyLoc,
44172
+ params.accountId
44173
+ ];
44174
+ task.logger?.info(`==> 开始获取代理信息:${args}`);
44175
+ const ProxyAgentResult = await ProxyAgent({
44176
+ logger: task.logger
44177
+ }, ...args);
44178
+ task.logger?.info("==> 代理信息获取成功!");
44179
+ proxyUrl = ProxyAgentResult ? `http://${ProxyAgentResult.ip}:${ProxyAgentResult.port}` : void 0;
44180
+ }
44181
+ task.logger?.info("==>开始打开小红书页面...");
44182
+ const page = await task.createPage({
44183
+ show: task.debug,
44184
+ cookies: params.cookies,
44185
+ proxyUrl,
44186
+ url: params.url || "https://creator.xiaohongshu.com/publish/publish?source=official&from=menu&target=image",
44187
+ ...params.viewport ? {
44188
+ viewport: params.viewport
44189
+ } : {}
44190
+ });
44191
+ task.logger?.info("==>小红书页面打开成功");
44192
+ await updateTaskState?.({
44193
+ state: types_TaskState.ACTION,
44194
+ connectAddress: task.steelConnector?.getProxyUrl(task.sessionId || "", "v1/sessions/debug"),
44195
+ sessionId: task.sessionId
44196
+ });
44197
+ const clickTimeout = 10000;
44198
+ const selectAddress = async (selector, address)=>{
44199
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
44200
+ await instance.click({
44201
+ timeout: clickTimeout
44202
+ });
44203
+ await instance.locator("input").fill(address);
44204
+ const poperInstance = page.locator('.d-popover:not([style*="display: none"]) .d-options .d-grid-item');
44205
+ await poperInstance.first().waitFor();
44206
+ await poperInstance.first().click({
44207
+ timeout: clickTimeout
44208
+ });
44209
+ };
44210
+ const selectDate = async (selector, date)=>{
44211
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
44212
+ await instance.click({
44213
+ timeout: clickTimeout
44214
+ });
44215
+ await instance.fill(date);
44216
+ await instance.blur();
44217
+ };
44218
+ const getPoperInstance = async ()=>{
44219
+ await page.waitForTimeout(500);
44220
+ const elements = page.locator(".d-popover");
44221
+ const count = await elements.count();
44222
+ const visibleElements = [];
44223
+ for(let i = 0; i < count; i++){
44224
+ const element = elements.nth(i);
44225
+ const style = await element.getAttribute("style");
44226
+ if (style && !style.includes("display: none")) visibleElements.push(element);
44227
+ }
44228
+ if (visibleElements.length > 0) return visibleElements[visibleElements.length - 1];
44229
+ throw new Error("未找到 popover 弹窗");
44230
+ };
44231
+ const getDialogInstance = async ()=>{
44232
+ await page.waitForTimeout(1000);
44233
+ const elements = page.locator(".el-dialog");
44234
+ return elements.last();
44235
+ };
44236
+ try {
44237
+ await page.waitForSelector("#CreatorPlatform", {
44238
+ state: "attached"
44239
+ });
44240
+ } catch (error) {
44241
+ return {
44242
+ code: 414,
44243
+ message: "登录失效",
44244
+ data: page.url()
44245
+ };
44246
+ }
44247
+ const images = await imagePromise;
44248
+ task.logger?.info(`==>图片下载完成,共 ${images.length} 张,开始上传图片...`);
44249
+ const fileChooser = await page.waitForSelector("input.upload-input", {
44250
+ timeout: 10000
44251
+ });
44252
+ if (fileChooser) await fileChooser.setInputFiles(images, {
44253
+ timeout: 60000
44254
+ }).catch((err)=>{
44255
+ task.logger?.error(`设置上传文件失败:${err.message}`);
44256
+ });
44257
+ else task.logger?.error("文件上传输入框未找到");
44258
+ task.logger?.info("==>图片上传完成,开始渲染预览图...");
44259
+ const titleInstance = page.locator(".input input");
44260
+ await titleInstance.waitFor({
44261
+ state: "attached",
44262
+ timeout: 60000
44263
+ });
44264
+ await titleInstance.click({
44265
+ timeout: 24 * clickTimeout
44266
+ });
44267
+ task.logger?.info("==> 预览图渲染成功,开始RPA操作!");
44268
+ await titleInstance.fill(params.title);
44269
+ const descInstance = page.locator(".editor-container .tiptap.ProseMirror");
44270
+ await descInstance.click({
44271
+ timeout: clickTimeout
44272
+ });
44273
+ await descInstance.fill(`${params.content.replace(/#.*?\[.*?]#/g, "")}\n`);
44274
+ await page.keyboard.press("Control+End");
44275
+ if (params.topic && params.topic.length > 0) for (const it of params.topic){
44276
+ await page.keyboard.insertText(`#${it.name}`);
44277
+ await page.locator(".ql-mention-loading").waitFor({
44278
+ state: "detached"
44279
+ });
44280
+ await page.waitForTimeout(1000);
44281
+ await page.locator("#creator-editor-topic-container .item.is-selected").click({
44282
+ timeout: clickTimeout
44283
+ });
44284
+ await page.keyboard.press("Control+End");
44285
+ }
44286
+ const container = page.locator(".plugin.editor-container");
44287
+ await container.focus();
44288
+ await page.mouse.wheel(0, 500);
44289
+ if (params.address) await selectAddress(page.locator(".media-extension .address-input").filter({
44290
+ hasText: "添加地点"
44291
+ }), params.address.name);
44292
+ if (params.collectionBind) {
44293
+ await page.locator(".media-extension .collection-container").filter({
44294
+ hasText: "添加合集"
44295
+ }).click({
44296
+ timeout: clickTimeout
44297
+ });
44298
+ const collectionName = params.collectionBind.name;
44299
+ const collectionBindInstance = await getPoperInstance();
44300
+ const collectionItemInstance = collectionBindInstance.locator(".d-grid-item .item-label", {
44301
+ hasText: collectionName
44302
+ });
44303
+ await collectionBindInstance.locator(".loading").waitFor({
44304
+ state: "detached"
44305
+ });
44306
+ await collectionItemInstance.click({
44307
+ timeout: clickTimeout
44308
+ });
44309
+ }
44310
+ if (params.groupBind) {
44311
+ await page.locator(".media-extension .address-input").filter({
44312
+ hasText: "选择群聊"
44313
+ }).click({
44314
+ timeout: clickTimeout
44315
+ });
44316
+ const groupBindName = params.groupBind.group_name;
44317
+ const groupBindInstance = await getPoperInstance();
44318
+ const groupItemInstance = groupBindInstance.locator(".d-grid-item .name", {
44319
+ hasText: groupBindName
44320
+ });
44321
+ await groupBindInstance.locator(".loading").waitFor({
44322
+ state: "detached"
44323
+ });
44324
+ await groupItemInstance.click({
44325
+ timeout: clickTimeout
44326
+ });
44327
+ }
44328
+ const OriginalBindBtn = page.locator(".btn-text.red", {
44329
+ hasText: "去声明"
44330
+ });
44331
+ const isOriginalBindBtnVisible = await OriginalBindBtn.isVisible();
44332
+ if (isOriginalBindBtnVisible && params.originalBind) {
44333
+ await OriginalBindBtn.click({
44334
+ timeout: clickTimeout
44335
+ });
44336
+ const poperInstance = await getPoperInstance();
44337
+ await poperInstance.locator(".d-checkbox-simulator").click({
44338
+ timeout: clickTimeout
44339
+ });
44340
+ await poperInstance.locator(".footer .custom-button.bg-red").click({
44341
+ timeout: clickTimeout
44342
+ });
44343
+ }
44344
+ if (params.selfDeclaration) {
44345
+ await page.locator(".media-settings .flexbox").filter({
44346
+ hasText: "内容类型声明"
44347
+ }).locator(".d-select-placeholder").click({
44348
+ timeout: clickTimeout
44349
+ });
44350
+ const poperInstance = await getPoperInstance();
44351
+ const selfDeclarationInstance = poperInstance.locator(".d-options .d-option");
44352
+ if ("fictional-rendition" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
44353
+ hasText: "虚构演绎,仅供娱乐"
44354
+ }).click({
44355
+ timeout: clickTimeout
44356
+ });
44357
+ else if ("ai-generated" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
44358
+ hasText: "笔记含AI合成内容"
44359
+ }).click({
44360
+ timeout: clickTimeout
44361
+ });
44362
+ else if ("source-statement" === params.selfDeclaration.type) {
44363
+ await selfDeclarationInstance.filter({
44364
+ hasText: /内容来源声明/
44365
+ }).click({
44366
+ timeout: clickTimeout
44367
+ });
44368
+ const selfDeclarationSecondaryMenuInstance = (await getPoperInstance()).locator(".d-options .d-option");
44369
+ await selfDeclarationSecondaryMenuInstance.first().waitFor();
44370
+ if ("self-labeling" === params.selfDeclaration.childType) await selfDeclarationSecondaryMenuInstance.filter({
44371
+ hasText: "已在正文中自主标注"
44372
+ }).click({
44373
+ timeout: clickTimeout
44374
+ });
44375
+ else if ("self-shooting" === params.selfDeclaration.childType) {
44376
+ const { shootingDate, shootingLocation } = params.selfDeclaration;
44377
+ await selfDeclarationSecondaryMenuInstance.filter({
44378
+ hasText: "自主拍摄"
44379
+ }).click({
44380
+ timeout: clickTimeout
44381
+ });
44382
+ const selfShootingPopup = await getDialogInstance();
44383
+ const hasCustomContent = shootingDate || shootingLocation;
44384
+ if (shootingLocation) await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation.name);
44385
+ if (shootingDate) await selectDate(selfShootingPopup.locator(".date-picker input"), shootingDate);
44386
+ await selfShootingPopup.locator("footer button").filter({
44387
+ hasText: hasCustomContent ? "确认" : "取消"
44388
+ }).click({
44389
+ timeout: clickTimeout
44390
+ });
44391
+ } else if ("transshipment" === params.selfDeclaration.childType) {
44392
+ await selfDeclarationSecondaryMenuInstance.filter({
44393
+ hasText: "来源转载"
44394
+ }).click({
44395
+ timeout: clickTimeout
44396
+ });
44397
+ const selfShootingPopup = await getDialogInstance();
44398
+ const sourceMedia = params.selfDeclaration.sourceMedia;
44399
+ if (sourceMedia) await selfShootingPopup.locator(".el-input input").fill(sourceMedia);
44400
+ await selfShootingPopup.locator("footer button").filter({
44401
+ hasText: sourceMedia ? "确认" : "取消"
44402
+ }).click({
44403
+ timeout: clickTimeout
44404
+ });
44405
+ }
44406
+ }
44407
+ }
44408
+ if ("public" !== params.visibleRange) {
44409
+ await page.locator(".media-settings .flexbox").filter({
44410
+ hasText: "可见范围"
44411
+ }).locator(".d-select-wrapper").click({
44412
+ timeout: clickTimeout
44413
+ });
44414
+ const poperInstance = await getPoperInstance();
44415
+ const visibleText = "friends" === params.visibleRange ? "好友可见" : "仅自己可见";
44416
+ await poperInstance.locator(".d-options .custom-option").filter({
44417
+ hasText: visibleText
44418
+ }).click({
44419
+ timeout: clickTimeout
44420
+ });
44421
+ }
44422
+ async function setSwitch(page, label, target) {
44423
+ const item = page.locator(".d-new-form-item", {
44424
+ has: page.locator(".d-form-item__label", {
44425
+ hasText: label
44426
+ })
44427
+ });
44428
+ const switchUI = item.locator(".d-switch-simulator");
44429
+ const cls = await switchUI.getAttribute("class");
44430
+ const isChecked = cls?.includes("checked") || true;
44431
+ if (isChecked !== target) await switchUI.click({
44432
+ timeout: clickTimeout
44433
+ });
44434
+ }
44435
+ if (!params.coProduceBind) await setSwitch(page, "允许合拍", false);
44436
+ if (!params.noteCopyBind) await setSwitch(page, "允许正文复制", false);
44437
+ const releaseTimeInstance = page.locator("label").filter({
44438
+ hasText: params.isImmediatelyPublish ? "立即发布" : "定时发布"
44439
+ });
44440
+ await releaseTimeInstance.click({
44441
+ timeout: clickTimeout
44442
+ });
44443
+ if (params.scheduledPublish) await selectDate(".date-picker input", params.scheduledPublish);
44444
+ const imgPreviewArea = page.locator(".img-preview-area");
44445
+ try {
44446
+ await imgPreviewArea.locator(".mask.uploading").waitFor({
44447
+ state: "hidden",
44448
+ timeout: 50000
44449
+ });
44450
+ } catch (error) {
44451
+ throw new Error("上传图片超时,请重试!");
44452
+ }
44453
+ if (MockPublish) {
44454
+ const message = "文章模拟发布成功";
44455
+ const data = "123456789";
44456
+ await updateTaskState?.({
44457
+ state: types_TaskState.SUCCESS,
44458
+ result: {
44459
+ response: data
44460
+ }
44461
+ });
44462
+ return success(data, message);
44463
+ }
44464
+ const response = await new Promise((resolve)=>{
44465
+ const handleResponse = async (response)=>{
44466
+ if (response.url().includes("/web_api/sns/v2/note")) {
44467
+ const jsonResponse = await response.json();
44468
+ page.off("response", handleResponse);
44469
+ resolve(jsonResponse);
44470
+ }
44471
+ };
44472
+ page.on("response", handleResponse);
44473
+ page.locator(".submit .publishBtn").click({
44474
+ timeout: clickTimeout
44475
+ });
44476
+ page.waitForSelector(".d-toast-icon-danger", {
44477
+ state: "visible",
44478
+ timeout: 2000
44479
+ }).then(async ()=>{
44480
+ await page.waitForTimeout(300);
44481
+ const toastDesc = await page.locator(".d-toast-description").textContent();
44482
+ const desc = toastDesc?.trim();
44483
+ page.off("response", handleResponse);
44484
+ resolve({
44485
+ success: false,
44486
+ msg: desc || "未知错误"
44487
+ });
44488
+ }).catch(()=>{});
44489
+ setTimeout(()=>{
44490
+ page.off("response", handleResponse);
44491
+ resolve({
44492
+ success: false,
44493
+ msg: "发布超时"
44494
+ });
44495
+ }, 7000);
44496
+ });
44497
+ if (!response?.success) {
44498
+ const msg = `发布失败:${response?.msg || "未知错误"}`;
44499
+ await updateTaskState?.({
44500
+ state: types_TaskState.FAILED,
44501
+ error: msg
44502
+ });
44503
+ await page.close();
44504
+ return {
44505
+ code: 414,
44506
+ message: msg,
44507
+ data: ""
44508
+ };
44509
+ }
44510
+ await updateTaskState?.({
44511
+ state: types_TaskState.SUCCESS,
44512
+ result: {
44513
+ response: response?.data?.id || ""
44514
+ }
44515
+ });
44516
+ await page.close();
44517
+ return success(response?.data?.id || "");
44518
+ };
44519
+ const rpa_server_mock_encode_mnsv2 = __webpack_require__("./src/utils/xhs_ob/x_s.encoder.js");
44520
+ function Md5(input) {
44521
+ return external_node_crypto_default().createHash("md5").update(input).digest("hex");
44522
+ }
44523
+ const rpa_server_mock_errnoMap = {
44524
+ "-1": "未知拦截器错误,请稍后重试。",
44525
+ 915: "所属C端账号手机号被修改,请重新登录",
44526
+ 914: "所属C端账号密码被修改,请重新登录",
44527
+ 903: "账户已登出,需重新登陆重试!",
44528
+ 902: "登录已过期,请重新登录!",
44529
+ 906: "账号存在风险,请重新登录!",
44530
+ "-9136": "因违反社区规范禁止发笔记,请检查账号状态!"
44531
+ };
44532
+ const rpa_server_mock_xsEncrypt = new Xhshow();
44533
+ const rpaAction_Server_Mock = async (task, params)=>{
44534
+ const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
44535
+ const tmpCachePath = task.getTmpPath();
44536
+ if (params?.selfDeclaration?.type === "source-statement" && "transshipment" === params.selfDeclaration.childType && params.originalBind) return {
44537
+ code: 414,
44538
+ message: "原创声明与转载声明互斥,请重新选择后发布!",
44539
+ data: ""
44540
+ };
44541
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
44542
+ if (!a1Cookie) return {
44543
+ code: 414,
44544
+ message: "账号数据异常,请重新绑定账号后重试。",
44545
+ data: ""
44546
+ };
44547
+ const defaultPage = task.steelBrowserContext?.pages()[0];
44548
+ if (defaultPage) {
44549
+ if (!defaultPage._routeRegistered) {
44550
+ defaultPage._routeRegistered = true;
44551
+ const blockedPatterns = [
44552
+ "**/ffmpeg-core.wasm*",
44553
+ "**/apm-fe.xiaohongshu.com*",
44554
+ "**/t2.xiaohongshu.com*",
44555
+ "**/fe-video-qc.xhscdn.com*"
44556
+ ].map((pattern)=>new RegExp(pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*")));
44557
+ await defaultPage.route("**/*", async (route)=>{
44558
+ const req = route.request();
44559
+ const url = req.url();
44560
+ const blocked = blockedPatterns.some((regex)=>regex.test(url));
44561
+ if (!blocked) return route.continue();
44562
+ if ("OPTIONS" === req.method()) {
44563
+ console.log("处理 OPTIONS 预检:", url);
44564
+ await route.fulfill({
44565
+ status: 204,
44566
+ headers: {
44567
+ "access-control-allow-origin": "*",
44568
+ "access-control-allow-methods": "GET,POST,OPTIONS,PUT,DELETE",
44569
+ "access-control-allow-headers": "*"
44570
+ },
44571
+ body: ""
44572
+ });
44573
+ return;
44574
+ }
44575
+ await route.fulfill({
44576
+ status: 204,
44577
+ body: ""
44578
+ });
44579
+ });
44580
+ }
44581
+ }
44582
+ const pagePromise = task.createPage({
44583
+ show: task.debug,
44584
+ cookies: params.cookies,
44585
+ url: params.url || "https://creator.xiaohongshu.com/statistics/account/v2?source=official"
44586
+ });
44587
+ await updateTaskState?.({
44588
+ state: types_TaskState.ACTION
44589
+ });
44590
+ const headers = {
44591
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
44592
+ origin: "https://creator.xiaohongshu.com",
44593
+ referer: "https://creator.xiaohongshu.com/",
44594
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
44595
+ };
44596
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
44597
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
44598
+ return acc;
44599
+ }, {});
44600
+ const args = [
44601
+ {
44602
+ headers
44603
+ },
44604
+ task.logger,
44605
+ params.proxyLoc,
44606
+ params.localIP,
44607
+ params.accountId
44608
+ ];
44609
+ const http = new Http({
44610
+ headers
44611
+ });
44612
+ const proxyHttp = new Http(...args);
44613
+ proxyHttp.addResponseInterceptor((response)=>{
44614
+ const responseData = response.data;
44615
+ if (response && responseData?.code && 0 !== responseData.code || responseData?.code && !responseData.success) {
44616
+ const errmsg = rpa_server_mock_errnoMap[responseData.code] || response.config.defaultErrorMsg || "文章发布异常,请稍后重试。";
44617
+ return {
44618
+ code: rpa_server_mock_errnoMap[responseData.code] ? 414 : 500,
44619
+ message: errmsg,
44620
+ data: responseData
44621
+ };
44622
+ }
44623
+ });
44624
+ const fetchCoverUrl = "/api/media/v1/upload/creator/permit";
44625
+ const fetchCoverParams = {
44626
+ biz_name: "spectrum",
44627
+ scene: "image",
44628
+ file_count: params.banners.length,
44629
+ version: 1,
44630
+ source: "web"
44631
+ };
44632
+ const fetchCoverXsHeader = rpa_server_mock_xsEncrypt.signHeadersGet(fetchCoverUrl, recordCookie, "ugc", fetchCoverParams);
44633
+ const uploadInfos = [];
44634
+ if (params.banners.length > 18) {
44635
+ let num = Math.ceil(params.banners.length / 14);
44636
+ for(let i = 0; i < num; i++){
44637
+ const start = 14 * i;
44638
+ params.banners.length;
44639
+ ({
44640
+ ...fetchCoverParams
44641
+ });
44642
+ const batchCoverIdInfo = await proxyHttp.api({
44643
+ method: "get",
44644
+ baseURL: "https://creator.xiaohongshu.com",
44645
+ url: fetchCoverUrl,
44646
+ defaultErrorMsg: "获取小红书用户信息失败,请稍后重试发布。",
44647
+ headers: fetchCoverXsHeader,
44648
+ params: fetchCoverParams
44649
+ }, {
44650
+ retries: 3,
44651
+ retryDelay: 20,
44652
+ timeout: 3000
44653
+ });
44654
+ for (const item of batchCoverIdInfo.data.uploadTempPermits)for (const fileId of item.fileIds)uploadInfos.push({
44655
+ bucket: item.bucket || "",
44656
+ uploadAddr: item.uploadAddr || "",
44657
+ fileIds: fileId,
44658
+ token: item.token || ""
44659
+ });
44660
+ }
44661
+ } else {
44662
+ const coverIdInfo = await proxyHttp.api({
44663
+ method: "get",
44664
+ baseURL: "https://creator.xiaohongshu.com",
44665
+ url: fetchCoverUrl,
44666
+ defaultErrorMsg: "获取小红书用户信息失败,请稍后重试发布。",
44667
+ headers: fetchCoverXsHeader,
44668
+ params: fetchCoverParams
44669
+ }, {
44670
+ retries: 3,
44671
+ retryDelay: 20,
44672
+ timeout: 3000
44673
+ });
44674
+ for (const item of coverIdInfo.data.uploadTempPermits)for (const fileId of item.fileIds)uploadInfos.push({
44675
+ bucket: item.bucket || "",
44676
+ uploadAddr: item.uploadAddr || "",
44677
+ fileIds: fileId,
44678
+ token: item.token || ""
44679
+ });
44680
+ }
44681
+ if (uploadInfos.length < params.banners.length) return {
44682
+ code: 414,
44683
+ message: "可用 OSS bucket 数量不足,无法上传所有图片!",
44684
+ data: ""
44685
+ };
44686
+ if (0 === uploadInfos.length) return {
44687
+ code: 414,
44688
+ message: "图片上传失败,请稍后重试!",
44689
+ data: ""
44690
+ };
44691
+ const availableBuckets = Array.from({
44692
+ length: uploadInfos.length
44693
+ }, (_, i)=>i);
44694
+ const uploadFile = async (url, index)=>{
44695
+ const fileName = getFilenameFromUrl(url);
44696
+ const localUrl = await downloadImage(url, external_node_path_default().join(tmpCachePath, fileName));
44697
+ const fileBuffer = external_node_fs_default().readFileSync(localUrl);
44698
+ const MAX_RETRIES = uploadInfos.length;
44699
+ task.logger.debug(`上传图片 ${index + 1}:尝试使用最多 ${MAX_RETRIES} 个 bucket`);
44700
+ let attempt = 0;
44701
+ while(attempt < MAX_RETRIES){
44702
+ const ossBucketIndex = availableBuckets.shift();
44703
+ if (void 0 === ossBucketIndex) break;
44704
+ const currentInfo = uploadInfos[ossBucketIndex];
44705
+ const ossFileId = currentInfo.fileIds;
44706
+ const ossToken = currentInfo.token;
44707
+ const ossDomain = currentInfo.uploadAddr;
44708
+ try {
44709
+ await http.api({
44710
+ method: "put",
44711
+ url: `https://${ossDomain}/${ossFileId}`,
44712
+ data: fileBuffer,
44713
+ headers: {
44714
+ "x-cos-security-token": ossToken
44715
+ },
44716
+ defaultErrorMsg: "图片上传异常,请稍后重试发布。"
44717
+ });
44718
+ return {
44719
+ ossFileId,
44720
+ ossToken
44721
+ };
44722
+ } catch (error) {
44723
+ task.logger.warn(`上传图片 ${index + 1}:使用 bucket ${ossDomain} 失败,尝试下一个可用 bucket。错误信息:${error.message}`);
44724
+ attempt++;
44725
+ }
44726
+ }
44727
+ return {
44728
+ ossFileId: "",
44729
+ ossToken: ""
44730
+ };
44731
+ };
44732
+ const coverInfos = await Promise.all(params.banners.map((it, idx)=>uploadFile(it, idx)));
44733
+ const invalidUpload = coverInfos.find((it)=>"" === it.ossToken || "" === it.ossFileId);
44734
+ if (invalidUpload) return {
44735
+ code: 414,
44736
+ message: "图片上传异常,请稍后重试发布。",
44737
+ data: ""
44738
+ };
44739
+ if (params.topic && params.topic.length > 0) await Promise.all(params.topic.map(async (topic)=>{
44740
+ if (!topic.id) {
44741
+ const topicData = {
44742
+ topic_names: topic.name
44743
+ };
44744
+ const topicXsHeader = rpa_server_mock_xsEncrypt.signHeadersPost("/web_api/sns/capa/postgw/topic/batch_customized", recordCookie, "ugc", topicData);
44745
+ const createTopic = await proxyHttp.api({
44746
+ method: "POST",
44747
+ url: "https://edith.xiaohongshu.com/web_api/sns/capa/postgw/topic/batch_customized",
44748
+ headers: topicXsHeader,
44749
+ data: topicData,
44750
+ defaultErrorMsg: "话题创建异常,请稍后重试。"
44751
+ }, {
44752
+ retries: 3,
44753
+ retryDelay: 20,
44754
+ timeout: 3000
44755
+ });
44756
+ Object.assign(topic, createTopic.data.topic_infos[0]);
44757
+ }
44758
+ }));
44759
+ const visibleRangeMap = {
44760
+ public: 0,
44761
+ private: 1,
44762
+ friends: 4
44763
+ };
44764
+ const publishData = {
44765
+ common: {
44766
+ ats: [],
44767
+ biz_relations: [],
44768
+ desc: params?.content,
44769
+ goods_info: {},
44770
+ hash_tag: params.topic || [],
44771
+ note_id: "",
44772
+ source: JSON.stringify({
44773
+ type: "web",
44774
+ ids: "",
44775
+ extraInfo: '{"systemId":"web"}'
44776
+ }),
44777
+ title: params?.title,
44778
+ type: "normal",
44779
+ privacy_info: {
44780
+ op_type: 1,
44781
+ type: visibleRangeMap[params.visibleRange]
44782
+ },
44783
+ post_loc: params.address ? {
44784
+ name: params.address?.name,
44785
+ poi_id: params.address?.poi_id,
44786
+ poi_type: params.address?.poi_type,
44787
+ subname: params.address?.full_address
44788
+ } : null,
44789
+ business_binds: ""
44790
+ },
44791
+ image_info: {
44792
+ images: coverInfos.map((it)=>({
44793
+ extra_info_json: '{"mimeType":"image/png"}',
44794
+ file_id: it.ossFileId,
44795
+ metadata: {
44796
+ source: -1
44797
+ },
44798
+ stickers: {
44799
+ floating: [],
44800
+ version: 2
44801
+ }
44802
+ }))
44803
+ },
44804
+ video_info: null
44805
+ };
44806
+ const userDeclarationBind = {
44807
+ origin: 2,
44808
+ photoInfo: {},
44809
+ repostInfo: {}
44810
+ };
44811
+ if (params.selfDeclaration?.type === "fictional-rendition") userDeclarationBind.origin = 1;
44812
+ else if (params.selfDeclaration?.type === "ai-generated") userDeclarationBind.origin = 2;
44813
+ else if (params.selfDeclaration?.type === "source-statement") {
44814
+ if ("self-labeling" === params.selfDeclaration.childType) userDeclarationBind.origin = 3;
44815
+ else if ("self-shooting" === params.selfDeclaration.childType) {
44816
+ userDeclarationBind.origin = 4;
44817
+ const photoInfo = {};
44818
+ if (params.selfDeclaration.shootingLocation) photoInfo.photoPlace = {
44819
+ name: params.selfDeclaration.shootingLocation.name,
44820
+ poiId: params.selfDeclaration.shootingLocation.poi_id,
44821
+ poiType: params.selfDeclaration.shootingLocation.poi_type,
44822
+ subname: params.selfDeclaration.shootingLocation.full_address
44823
+ };
44824
+ if (params.selfDeclaration.shootingDate) photoInfo.photoTime = params.selfDeclaration.shootingDate;
44825
+ userDeclarationBind.photoInfo = photoInfo;
44826
+ } else if ("transshipment" === params.selfDeclaration.childType) {
44827
+ userDeclarationBind.origin = 5;
44828
+ if (params.selfDeclaration.sourceMedia) userDeclarationBind.repostInfo = {
44829
+ source: params.selfDeclaration.sourceMedia
44830
+ };
44831
+ }
44832
+ }
44833
+ const bizId = params?.originalBind && (params.cookies.find((it)=>"x-user-id-creator.xiaohongshu.com" === it.name)?.value || await proxyHttp.api({
44834
+ method: "get",
44835
+ url: "https://creator.xiaohongshu.com/api/galaxy/user/my-info"
44836
+ }, {
44837
+ retries: 3,
44838
+ retryDelay: 20,
44839
+ timeout: 3000
44840
+ }).then((userData)=>userData.data?.userDetail?.id));
44841
+ const business_binds = {
44842
+ version: 1,
44843
+ bizType: "",
44844
+ noteId: "",
44845
+ noteOrderBind: {},
44846
+ notePostTiming: params.isImmediatelyPublish ? {} : {
44847
+ postTime: params.scheduledPublish
44848
+ },
44849
+ coProduceBind: {
44850
+ enable: !!params?.coProduceBind
44851
+ },
44852
+ noteCopyBind: {
44853
+ copyable: !!params?.noteCopyBind
44854
+ },
44855
+ optionRelationList: params.originalBind ? [
44856
+ {
44857
+ type: "ORIGINAL_STATEMENT",
44858
+ relationList: [
44859
+ {
44860
+ bizId,
44861
+ bizType: "ORIGINAL_STATEMENT",
44862
+ extraInfo: "{}"
44863
+ }
44864
+ ]
44865
+ }
44866
+ ] : [],
44867
+ ...params?.groupBind ? {
44868
+ groupBind: {
44869
+ groupId: params?.groupBind?.group_id,
44870
+ groupName: params.groupBind?.group_name,
44871
+ desc: params.groupBind?.desc,
44872
+ avatar: params.groupBind?.avatar
44873
+ }
44874
+ } : {
44875
+ groupBind: {}
44876
+ },
44877
+ ...params.selfDeclaration ? {
44878
+ userDeclarationBind
44879
+ } : {},
44880
+ ...params?.collectionBind?.id ? {
44881
+ noteCollectionBind: {
44882
+ id: params.collectionBind.id
44883
+ }
44884
+ } : {}
44885
+ };
44886
+ publishData.common.business_binds = JSON.stringify(business_binds);
44887
+ task._timerRecord.PrePublish = Date.now();
44888
+ const page = await pagePromise;
44889
+ await updateTaskState?.({
44890
+ sessionId: task.sessionId
44891
+ });
44892
+ const publishXsHeader = {
44893
+ "x-s": "",
44894
+ "x-t": Date.now().toString()
44895
+ };
44896
+ await page.waitForFunction(()=>"function" == typeof window.mnsv2, {
44897
+ timeout: 10000
44898
+ });
44899
+ const encodeData = `/web_api/sns/v2/note${JSON.stringify(publishData)}`;
44900
+ const ticket_mnsv2 = await page.evaluate(({ c, d })=>{
44901
+ if ("function" == typeof window.mnsv2) return window.mnsv2(c, d);
44902
+ return "mnsv2 未定义";
44903
+ }, {
44904
+ c: encodeData,
44905
+ d: Md5(encodeData)
44906
+ });
44907
+ publishXsHeader["x-s"] = rpa_server_mock_encode_mnsv2(ticket_mnsv2, "Windows", "object");
44908
+ publishXsHeader["x-t"] = Date.now().toString();
44909
+ if (MockPublish) {
44910
+ const message = `文章模拟发布成功 ${http.proxyInfo}`;
44911
+ const data = "123456789";
44912
+ await updateTaskState?.({
44913
+ state: types_TaskState.SUCCESS,
44914
+ result: {
44915
+ response: data
44916
+ }
44917
+ });
44918
+ return success(data, message);
44919
+ }
44920
+ const publishResult = await proxyHttp.api({
44921
+ method: "post",
44922
+ url: "https://edith.xiaohongshu.com/web_api/sns/v2/note",
44923
+ data: publishData,
44924
+ headers: publishXsHeader,
44925
+ defaultErrorMsg: "文章发布异常,请稍后重试。"
44926
+ }, {
44927
+ retries: 2,
44928
+ retryDelay: 500,
44929
+ timeout: 12000
44930
+ });
44931
+ const isSuccess = publishResult.success;
44932
+ const message = `文章发布${isSuccess ? "成功" : `失败,原因:${publishResult.msg}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
44933
+ const data = isSuccess ? publishResult.data?.id || "" : "";
44934
+ if (!isSuccess) {
44935
+ await updateTaskState?.({
44936
+ state: types_TaskState.FAILED,
44937
+ error: message
44938
+ });
44939
+ return {
44940
+ code: 414,
44941
+ data,
44942
+ message
44943
+ };
44944
+ }
44945
+ await updateTaskState?.({
44946
+ state: types_TaskState.SUCCESS,
44947
+ result: {
44948
+ response: data
44949
+ }
44950
+ });
44951
+ return success(data, message);
44952
+ };
44953
+ const FictionalRendition = classic_schemas_object({
44954
+ type: literal("fictional-rendition")
44955
+ });
44956
+ const AIGenerated = classic_schemas_object({
44957
+ type: literal("ai-generated")
44958
+ });
44959
+ const SourceStatement = classic_schemas_object({
44960
+ type: literal("source-statement"),
44961
+ childType: classic_schemas_enum([
44962
+ "self-labeling",
44963
+ "self-shooting",
44964
+ "transshipment"
44965
+ ]),
44966
+ shootingLocation: custom().optional(),
44967
+ shootingDate: classic_schemas_string().optional(),
44968
+ sourceMedia: classic_schemas_string().optional()
44969
+ });
44970
+ schemas_union([
44971
+ FictionalRendition,
44972
+ AIGenerated,
44973
+ SourceStatement
44974
+ ]);
44975
+ const XiaohongshuPublishParamsSchema = ActionCommonParamsSchema.extend({
44976
+ banners: classic_schemas_array(classic_schemas_string()),
44977
+ title: classic_schemas_string(),
44978
+ content: classic_schemas_string(),
44979
+ address: custom().optional(),
44980
+ selfDeclaration: custom().optional(),
44981
+ topic: classic_schemas_array(custom()).optional(),
44982
+ proxyLoc: classic_schemas_string().optional(),
44983
+ localIP: classic_schemas_string().optional(),
44984
+ huiwenToken: classic_schemas_string().optional(),
44985
+ visibleRange: classic_schemas_enum([
44986
+ "public",
44987
+ "private",
44988
+ "friends"
44989
+ ]),
44990
+ isImmediatelyPublish: classic_schemas_boolean().optional(),
44991
+ scheduledPublish: classic_schemas_string().optional(),
44992
+ collectionId: classic_schemas_string().optional(),
44993
+ collectionBind: custom().optional(),
44994
+ groupBind: custom().optional(),
44995
+ noteCopyBind: classic_schemas_boolean().optional(),
44996
+ coProduceBind: classic_schemas_boolean().optional(),
44997
+ originalBind: classic_schemas_boolean().optional()
44998
+ });
44999
+ const xiaohongshuPublish = async (task, params)=>{
45000
+ if (DisabledReq) return {
45001
+ code: 414,
45002
+ data: "",
45003
+ message: "临时维护:小红书发布政策调整,本平台小红书发布功能临时暂停服务并进行维护调整,暂时无法正常发布,敬请理解知悉。"
45004
+ };
45005
+ if ("rpa" === params.actionType) return xiaohongshuPublish_rpa_rpaAction(task, params);
45006
+ if ("mockApi" === params.actionType) return xiaohongshuPublish_mock_mockAction(task, params);
45007
+ if ("server" === params.actionType) return xiaohongshuPublish_rpa_server_rpaAction_Server(task, params);
45008
+ return executeAction(xiaohongshuPublish_mock_mockAction, rpaAction_Server_Mock, xiaohongshuPublish_rpa_server_rpaAction_Server)(task, params);
45009
+ };
45010
+ const xiaohongshuWebCommentAction_xsEncrypt = new Xhshow();
45011
+ const xiaohongshuWebCommentAction = async (_task, params)=>{
45012
+ if (DisabledReq) return utils_response(414, "点赞相关操作失败", {});
45013
+ const headers = {
45014
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
45015
+ referer: "https://www.xiaohongshu.com/",
45016
+ origin: "https://www.xiaohongshu.com/"
45017
+ };
45018
+ const args = [
45019
+ {
45020
+ headers
45021
+ },
45022
+ _task.logger,
45023
+ params.proxyLoc,
45024
+ params.localIP,
45025
+ params.accountId
45026
+ ];
45027
+ const http = new Http(...args);
45028
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
45029
+ if (!a1Cookie) return {
45030
+ code: 414,
45031
+ message: "账号数据异常,请重新绑定账号后重试。",
45032
+ data: []
45033
+ };
45034
+ if (!params.note_id && !params.comment_id && !params.action) return {
45035
+ code: 414,
45036
+ message: "参数缺失,请检查后重试!",
45037
+ data: {}
45038
+ };
45039
+ const actionParams = {
45040
+ note_id: params.note_id,
45041
+ comment_id: params.comment_id
45042
+ };
45043
+ let likeActionRes = {
45044
+ code: 500,
45045
+ success: false,
45046
+ msg: ""
45047
+ };
45048
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
45049
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
45050
+ return acc;
45051
+ }, {});
45052
+ switch(params.action){
45053
+ case "like":
45054
+ {
45055
+ const likeAction = "/api/sns/web/v1/comment/like";
45056
+ const likeActionXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(likeAction, recordCookie, "xhs-pc-web", actionParams);
45057
+ likeActionRes = await http.api({
45058
+ method: "post",
45059
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/like",
45060
+ data: actionParams,
45061
+ headers: likeActionXsHeader
45062
+ }, {
45063
+ retries: 3,
45064
+ retryDelay: 20,
45065
+ timeout: 3000
45066
+ });
45067
+ break;
45068
+ }
45069
+ case "dislike":
45070
+ {
45071
+ const dislikeMentions = "/api/sns/web/v1/comment/dislike";
45072
+ const dislikeXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(dislikeMentions, recordCookie, "xhs-pc-web", actionParams);
45073
+ likeActionRes = await http.api({
45074
+ method: "post",
45075
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/dislike",
45076
+ data: actionParams,
45077
+ headers: dislikeXsHeader
45078
+ }, {
45079
+ retries: 3,
45080
+ retryDelay: 20,
45081
+ timeout: 3000
45082
+ });
45083
+ break;
45084
+ }
45085
+ default:
45086
+ return {
45087
+ code: 414,
45088
+ message: "参数action错误,请重试!",
45089
+ data: {}
45090
+ };
45091
+ }
45092
+ const isSuccess = 0 === likeActionRes.code;
45093
+ const message = `点赞相关操作${isSuccess ? "成功" : `失败,原因:${likeActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
45094
+ const data = isSuccess ? likeActionRes.success : {};
45095
+ return utils_response(isSuccess ? 0 : 414, message, data);
45096
+ };
45097
+ const xiaohongshuWebIntimacySearch = async (_task, params)=>{
45098
+ if (DisabledReq) return utils_response(0, "搜索@列表数据成功", []);
45099
+ const headers = {
45100
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
45101
+ referer: "https://www.xiaohongshu.com/",
45102
+ origin: "https://www.xiaohongshu.com"
45103
+ };
45104
+ const args = [
45105
+ {
45106
+ headers
45107
+ },
45108
+ _task.logger,
45109
+ params.proxyLoc,
45110
+ params.localIP,
45111
+ params.accountId
45112
+ ];
45113
+ const http = new Http(...args);
45114
+ let intimacyDetail = [];
45115
+ const res = await http.api({
45116
+ method: "get",
45117
+ url: `https://edith.xiaohongshu.com/api/sns/web/v1/intimacy/intimacy_list${params.searchValue ? "/search" : ""}`,
45118
+ ...params.searchValue ? {
45119
+ params: {
45120
+ keyword: params.searchValue,
45121
+ page: 1,
45122
+ rows: 30
45123
+ }
45124
+ } : {}
45125
+ }, {
45126
+ retries: 3,
45127
+ retryDelay: 20,
45128
+ timeout: 3000
45129
+ });
45130
+ const isSuccess = 0 === res.code;
45131
+ if (isSuccess) intimacyDetail = res.data.items;
45132
+ const message = `搜索@列表数据${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
45133
+ return utils_response(isSuccess ? 0 : 414, message, intimacyDetail);
45134
+ };
45135
+ const xiaohongshuWebMsgRead_xsEncrypt = new Xhshow();
45136
+ const xiaohongshuWebMsgRead = async (_task, params)=>{
45137
+ if (DisabledReq) return utils_response(414, "Read指定Tab失败", {});
45138
+ const headers = {
45139
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
45140
+ referer: "https://www.xiaohongshu.com/",
45141
+ origin: "https://www.xiaohongshu.com/"
45142
+ };
45143
+ const args = [
45144
+ {
45145
+ headers
45146
+ },
45147
+ _task.logger,
45148
+ params.proxyLoc,
45149
+ params.localIP,
45150
+ params.accountId
45151
+ ];
45152
+ const http = new Http(...args);
45153
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
45154
+ if (!a1Cookie) return {
45155
+ code: 414,
45156
+ message: "账号数据异常,请重新绑定账号后重试。",
45157
+ data: []
45158
+ };
45159
+ if (!params.type) return {
45160
+ code: 414,
45161
+ message: "参数缺失,请检查后重试!",
45162
+ data: {}
45163
+ };
45164
+ const replyParams = {
45165
+ type: params.type
45166
+ };
45167
+ const fatchMentions = "/api/sns/web/v1/message/read";
45168
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
45169
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
45170
+ return acc;
45171
+ }, {});
45172
+ const fatchMentionsXsHeader = xiaohongshuWebMsgRead_xsEncrypt.signHeadersPost(fatchMentions, recordCookie, "xhs-pc-web", replyParams);
45173
+ const res = await http.api({
45174
+ method: "post",
45175
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/message/read",
45176
+ data: replyParams,
45177
+ headers: fatchMentionsXsHeader
45178
+ }, {
45179
+ retries: 3,
45180
+ retryDelay: 20,
45181
+ timeout: 3000
45182
+ });
45183
+ const isSuccess = 0 === res.code;
45184
+ const message = `Read指定Tab${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
45185
+ const data = isSuccess ? res.success : {};
45186
+ return utils_response(isSuccess ? 0 : 414, message, data);
45187
+ };
45188
+ const xiaohongshuWebMsgReply_xsEncrypt = new Xhshow();
45189
+ const xiaohongshuWebMsgReply = async (_task, params)=>{
45190
+ if (DisabledReq) return utils_response(414, "评论回复失败", {});
45191
+ const headers = {
45192
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
45193
+ referer: "https://www.xiaohongshu.com/",
45194
+ origin: "https://www.xiaohongshu.com/"
45195
+ };
45196
+ const args = [
45197
+ {
45198
+ headers
45199
+ },
45200
+ _task.logger,
45201
+ params.proxyLoc,
45202
+ params.localIP,
45203
+ params.accountId
45204
+ ];
45205
+ const http = new Http(...args);
45206
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
45207
+ if (!a1Cookie) return {
45208
+ code: 414,
45209
+ message: "账号数据异常,请重新绑定账号后重试。",
45210
+ data: []
45211
+ };
45212
+ if (!params.note_id || !params.target_comment_id || !params.content) return {
45213
+ code: 414,
45214
+ message: "参数缺失,请检查后重试!",
45215
+ data: {}
45216
+ };
45217
+ const replyParams = {
45218
+ at_users: params.at_users ?? [],
45219
+ content: params.content,
45220
+ note_id: params.note_id,
45221
+ target_comment_id: params.target_comment_id
45222
+ };
45223
+ const replyPath = "/api/sns/web/v1/comment/post";
45224
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
45225
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
45226
+ return acc;
45227
+ }, {});
45228
+ const replyXsHeader = xiaohongshuWebMsgReply_xsEncrypt.signHeadersPost(replyPath, recordCookie, "xhs-pc-web", replyParams);
45229
+ const res = await http.api({
45230
+ method: "post",
45231
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/post",
45232
+ data: replyParams,
45233
+ headers: replyXsHeader
45234
+ }, {
45235
+ retries: 3,
45236
+ retryDelay: 20,
45237
+ timeout: 3000
45238
+ });
45239
+ const isSuccess = 0 === res.code;
45240
+ const message = `评论回复${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
45241
+ const data = isSuccess ? res.data : {};
45242
+ return utils_response(isSuccess ? 0 : 414, message, data);
45243
+ };
45244
+ const xiaohongshuWebNoteFeed_xsEncrypt = new xhs_ob_feed_Xhshow();
45245
+ const GenXSCommon = __webpack_require__("./src/utils/XhsXsCommonEnc.js");
45246
+ const xiaohongshuWebNoteFeed = async (_task, params)=>{
45247
+ if (DisabledReq) return utils_response(414, "获取指定文章详情失败", {});
45248
+ const headers = {
45249
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
45250
+ referer: "https://www.xiaohongshu.com/",
45251
+ origin: "https://www.xiaohongshu.com/"
45252
+ };
45253
+ const args = [
45254
+ {
45255
+ headers
45256
+ },
45257
+ _task.logger,
45258
+ params.proxyLoc,
45259
+ params.localIP,
45260
+ params.accountId
45261
+ ];
45262
+ const http = new Http(...args);
45263
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
45264
+ if (!a1Cookie) return {
45265
+ code: 414,
45266
+ message: "账号数据异常,请重新绑定账号后重试。",
45267
+ data: {}
45268
+ };
45269
+ if (!params.source_note_id && !params.xsec_token) return {
45270
+ code: 414,
45271
+ message: "参数缺失,请检查后重试!",
45272
+ data: {}
45273
+ };
45274
+ const feedParams = {
45275
+ source_note_id: params.source_note_id,
45276
+ image_formats: [
45277
+ "jpg",
45278
+ "webp",
45279
+ "avif"
45280
+ ],
45281
+ extra: {
45282
+ need_body_topic: "1"
45283
+ },
45284
+ xsec_source: "pc_feed",
45285
+ xsec_token: params.xsec_token
45286
+ };
45287
+ const fatchFeed = "/api/sns/web/v1/feed";
45288
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
45289
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
45290
+ return acc;
45291
+ }, {});
45292
+ const xsHeader = xiaohongshuWebNoteFeed_xsEncrypt.signHeadersPost(fatchFeed, recordCookie, "xhs-pc-web", feedParams);
45293
+ const xT = Date.now().toString();
45294
+ const xsCommon = GenXSCommon(a1Cookie, xT, xsHeader["X-S"]);
45295
+ _task.logger.info(`请求参数: ${JSON.stringify(feedParams)}`);
45296
+ _task.logger.info(`X-S: ${xsHeader["X-S"]}`);
45297
+ _task.logger.info(`x-s-common: ${xsCommon}`);
45298
+ const res = await http.api({
45299
+ method: "post",
45300
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/feed",
45301
+ data: feedParams,
45302
+ headers: {
45303
+ "X-S": xsHeader["X-S"],
45304
+ "X-S-Common": xsCommon,
45305
+ "X-T": xT
45306
+ }
45307
+ }, {
45308
+ retries: 3,
45309
+ retryDelay: 20,
45310
+ timeout: 3000
45311
+ });
45312
+ _task.logger.info(`API 响应: ${JSON.stringify(res)}`);
45313
+ const isSuccess = 0 === res.code && res.data && res.data.items && res.data.items.length > 0;
45314
+ const message = `获取指定文章详情${isSuccess ? "成功" : `失败,原因:${res.msg || "返回数据为空,可能笔记不存在或参数错误"}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
45315
+ const data = isSuccess ? res.data?.items[0].note_card || {} : {};
45316
+ return utils_response(isSuccess ? 0 : 414, message, data);
45317
+ };
45318
+ const xiaohongshuWebRelationAction_xsEncrypt = new Xhshow();
45319
+ const xiaohongshuWebRelationAction = async (_task, params)=>{
45320
+ if (DisabledReq) return utils_response(414, "用户关系操作失败", {});
45321
+ const headers = {
45322
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
45323
+ referer: "https://www.xiaohongshu.com/",
45324
+ origin: "https://www.xiaohongshu.com/"
45325
+ };
45326
+ const args = [
45327
+ {
45328
+ headers
45329
+ },
45330
+ _task.logger,
45331
+ params.proxyLoc,
45332
+ params.localIP,
45333
+ params.accountId
45334
+ ];
45335
+ const http = new Http(...args);
45336
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
45337
+ if (!a1Cookie) return {
45338
+ code: 414,
45339
+ message: "账号数据异常,请重新绑定账号后重试。",
45340
+ data: {}
45341
+ };
45342
+ if (!params.action || !params.target_user_id) return {
45343
+ code: 414,
45344
+ message: "参数缺失,请检查后重试!",
45345
+ data: {}
45346
+ };
45347
+ const relationParams = {
45348
+ target_user_id: params.target_user_id
45349
+ };
45350
+ let relationActionRes;
45351
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
45352
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
45353
+ return acc;
45354
+ }, {});
45355
+ switch(params.action){
45356
+ case "follow":
45357
+ {
45358
+ const followMentions = "/api/sns/web/v1/user/follow";
45359
+ const followXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(followMentions, recordCookie, "xhs-pc-web", relationParams);
45360
+ relationActionRes = await http.api({
45361
+ method: "post",
45362
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/follow",
45363
+ data: relationParams,
45364
+ headers: followXsHeader
45365
+ }, {
45366
+ retries: 3,
45367
+ retryDelay: 500,
45368
+ timeout: 3000
45369
+ });
45370
+ break;
45371
+ }
45372
+ case "unfollow":
45373
+ {
45374
+ const unfllowMentions = "/api/sns/web/v1/user/unfollow";
45375
+ const unfllowXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(unfllowMentions, recordCookie, "xhs-pc-web", relationParams);
45376
+ relationActionRes = await http.api({
45377
+ method: "post",
45378
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/unfollow",
45379
+ data: relationParams,
45380
+ headers: unfllowXsHeader
45381
+ }, {
45382
+ retries: 3,
45383
+ retryDelay: 20,
45384
+ timeout: 3000
45385
+ });
45386
+ break;
45387
+ }
45388
+ default:
45389
+ return {
45390
+ code: 414,
45391
+ message: "参数action错误,请重试!",
45392
+ data: {}
45393
+ };
45394
+ }
45395
+ const isSuccess = 0 === relationActionRes.code;
45396
+ const message = `用户关系操作${isSuccess ? "成功" : `失败,原因:${relationActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
45397
+ const data = isSuccess ? relationActionRes.data : {
45398
+ fstatus: null
45399
+ };
45400
+ return utils_response(isSuccess ? 0 : 414, message, data);
45401
+ };
45402
+ const xiaohongshuWebSearch_xsEncrypt = new Xhshow();
45403
+ const XhsWebSearchParamsSchema = ActionCommonParamsSchema.extend({
45404
+ keyword: classic_schemas_string(),
45405
+ page: classic_schemas_number(),
45406
+ page_size: classic_schemas_number(),
45407
+ sort_type: classic_schemas_enum([
45408
+ "general",
45409
+ "time_descending",
45410
+ "popular_descending"
45411
+ ]),
45412
+ time_filter: classic_schemas_enum([
45413
+ "不限",
45414
+ "一周内"
45415
+ ])
45416
+ });
45417
+ const createSearchId = ()=>{
45418
+ let r = BigInt(Date.now());
45419
+ const o = BigInt(Math.ceil(0x7ffffffe * Math.random()));
45420
+ r <<= BigInt(64);
45421
+ r += o;
45422
+ return r.toString(36);
45423
+ };
45424
+ const xiaohongshuWebSearch = async (_task, params)=>{
45425
+ const headers = {
45426
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
45427
+ referer: "https://www.xiaohongshu.com/",
45428
+ origin: "https://www.xiaohongshu.com/"
45429
+ };
45430
+ const args = [
45431
+ {
45432
+ headers
45433
+ },
45434
+ _task.logger,
45435
+ params.proxyLoc,
45436
+ params.localIP,
45437
+ params.accountId
45438
+ ];
45439
+ const http = new Http(...args);
45440
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
45441
+ if (!a1Cookie) return {
45442
+ code: 414,
45443
+ message: "账号数据异常,请重新绑定账号后重试。",
45444
+ data: {}
45445
+ };
45446
+ if (!params.keyword || !params.page || !params.page_size || !params.sort_type || !params.time_filter) {
45447
+ if ("general" !== params.sort_type && "time_descending" !== params.sort_type && "popular_descending" !== params.sort_type) return {
45448
+ code: 414,
45449
+ message: "排序类型参数错误,请检查后重试!",
45450
+ data: {}
45451
+ };
45452
+ if ("不限" !== params.time_filter && "一周内" !== params.time_filter) return {
45453
+ code: 414,
45454
+ message: "时间过滤参数错误,请检查后重试!",
45455
+ data: {}
45456
+ };
45457
+ return {
45458
+ code: 414,
45459
+ message: "参数缺失,请检查后重试!",
45460
+ data: {}
45461
+ };
45462
+ }
45463
+ const filterPath = "/api/sns/web/v1/search/notes";
45464
+ const filterParams = {
45465
+ ext_flags: [],
45466
+ geo: "",
45467
+ image_formats: [
45468
+ "jpg",
45469
+ "webp",
45470
+ "avif"
45471
+ ],
45472
+ filters: [
45473
+ {
45474
+ tags: [
45475
+ params.sort_type
45476
+ ],
45477
+ type: "sort_type"
45478
+ },
45479
+ {
45480
+ tags: [
45481
+ "不限"
45482
+ ],
45483
+ type: "filter_note_type"
45484
+ },
45485
+ {
45486
+ tags: [
45487
+ params.time_filter
45488
+ ],
45489
+ type: "filter_note_time"
45490
+ },
45491
+ {
45492
+ tags: [
45493
+ "不限"
45494
+ ],
45495
+ type: "filter_note_range"
45496
+ },
45497
+ {
45498
+ tags: [
45499
+ "不限"
45500
+ ],
45501
+ type: "filter_pos_distance"
45502
+ }
45503
+ ],
45504
+ keyword: params.keyword,
45505
+ note_type: 0,
45506
+ page: params.page,
45507
+ page_size: params.page_size,
45508
+ search_id: createSearchId() + (params.sort_type || params.time_filter ? `@${createSearchId()}` : ""),
45509
+ sort: "general"
45510
+ };
45511
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
45512
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
45513
+ return acc;
45514
+ }, {});
45515
+ const searchXsHeader = xiaohongshuWebSearch_xsEncrypt.signHeadersPost(filterPath, recordCookie, "xhs-pc-web", filterParams);
45516
+ const res = await http.api({
45517
+ method: "post",
45518
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/search/notes",
45519
+ data: filterParams,
45520
+ headers: searchXsHeader
45521
+ }, {
45522
+ retries: 3,
45523
+ retryDelay: 20,
45524
+ timeout: 3000
45525
+ });
45526
+ const isSuccess = 0 === res.code;
45527
+ const message = `Web笔记搜索${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
45528
+ const data = isSuccess ? res.data : {};
45529
+ return utils_response(isSuccess ? 0 : 414, message, data);
45530
+ };
45531
+ const ttConfigDataSchema = classic_schemas_object({
45532
+ fansNum: classic_schemas_number(),
45533
+ fansNumYesterday: classic_schemas_number().nullable(),
45534
+ readNum: classic_schemas_number(),
45535
+ incomeNum: classic_schemas_number(),
45536
+ incomeNumYesterday: classic_schemas_number().nullable(),
45537
+ showNumYesterday: classic_schemas_number().nullable(),
45538
+ readNumYesterday: classic_schemas_number().nullable(),
45539
+ likeNumYesterday: classic_schemas_number().nullable(),
45540
+ commentNumYesterday: classic_schemas_number().nullable()
45541
+ });
45542
+ const xhsConfigDataSchema = classic_schemas_object({
45543
+ fansNum: classic_schemas_number(),
45544
+ favedNum: classic_schemas_number(),
45545
+ watchNumLastWeek: classic_schemas_number(),
45546
+ likeNumLastWeek: classic_schemas_number(),
45547
+ collectNumLastWeek: classic_schemas_number(),
45548
+ commentNumLastWeek: classic_schemas_number(),
45549
+ fansNumLastWeek: classic_schemas_number(),
45550
+ fansNumYesterday: classic_schemas_number()
45551
+ });
45552
+ const wxConfigDataSchema = classic_schemas_object({
45553
+ fansNum: classic_schemas_number(),
45554
+ fansNumYesterday: classic_schemas_number(),
45555
+ readNumYesterday: classic_schemas_number(),
45556
+ shareNumYesterday: classic_schemas_number()
45557
+ });
45558
+ const bjhConfigDataSchema = classic_schemas_object({
45559
+ fansNum: classic_schemas_number(),
45560
+ fansNumYesterday: classic_schemas_number().nullable(),
45561
+ readNum: classic_schemas_number(),
45562
+ incomeNum: classic_schemas_number(),
45563
+ incomeNumYesterday: classic_schemas_number().nullable(),
45564
+ recommendNumYesterday: classic_schemas_number().nullable(),
45565
+ readNumYesterday: classic_schemas_number().nullable(),
45566
+ likeNumYesterday: classic_schemas_number().nullable(),
45567
+ commentNumYesterday: classic_schemas_number().nullable()
45568
+ });
44600
45569
  const BetaFlag = "HuiwenCanary";
44601
45570
  class Action {
44602
45571
  constructor(task){