@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/index.js CHANGED
@@ -5490,7 +5490,7 @@ var __webpack_exports__ = {};
5490
5490
  const package_json_namespaceObject = require("@iflyrpa/share/package.json");
5491
5491
  var package_json_default = /*#__PURE__*/ __webpack_require__.n(package_json_namespaceObject);
5492
5492
  var package_namespaceObject = {
5493
- i8: "3.0.1"
5493
+ i8: "3.0.2"
5494
5494
  };
5495
5495
  const share_namespaceObject = require("@iflyrpa/share");
5496
5496
  const external_node_fs_namespaceObject = require("node:fs");
@@ -9696,7 +9696,7 @@ var __webpack_exports__ = {};
9696
9696
  data: null
9697
9697
  });
9698
9698
  const MockPublish = false;
9699
- const DisabledReq = true;
9699
+ const DisabledReq = false;
9700
9700
  const scanRetryMaxCount = 60;
9701
9701
  const waitQrcodeResultMaxTime = 2000 * scanRetryMaxCount;
9702
9702
  const rpaServer = async (task, params)=>{
@@ -23291,671 +23291,1022 @@ var __webpack_exports__ = {};
23291
23291
  if ("server" === params.actionType) return xiaohongshuLogin_rpa_server_rpaServer(task, params);
23292
23292
  return executeAction(xiaohongshuLogin_rpa_rpaAction)(task, params);
23293
23293
  };
23294
- const FictionalRendition = schemas_object({
23295
- type: literal("fictional-rendition")
23296
- });
23297
- const AIGenerated = schemas_object({
23298
- type: literal("ai-generated")
23299
- });
23300
- const SourceStatement = schemas_object({
23301
- type: literal("source-statement"),
23302
- childType: schemas_enum([
23303
- "self-labeling",
23304
- "self-shooting",
23305
- "transshipment"
23306
- ]),
23307
- shootingLocation: custom().optional(),
23308
- shootingDate: schemas_string().optional(),
23309
- sourceMedia: schemas_string().optional()
23310
- });
23311
- union([
23312
- FictionalRendition,
23313
- AIGenerated,
23314
- SourceStatement
23315
- ]);
23316
- const XiaohongshuPublishParamsSchema = ActionCommonParamsSchema.extend({
23317
- banners: schemas_array(schemas_string()),
23318
- title: schemas_string(),
23319
- content: schemas_string(),
23320
- address: custom().optional(),
23321
- selfDeclaration: custom().optional(),
23322
- topic: schemas_array(custom()).optional(),
23323
- proxyLoc: schemas_string().optional(),
23324
- localIP: schemas_string().optional(),
23325
- huiwenToken: schemas_string().optional(),
23326
- visibleRange: schemas_enum([
23327
- "public",
23328
- "private",
23329
- "friends"
23330
- ]),
23331
- isImmediatelyPublish: schemas_boolean().optional(),
23332
- scheduledPublish: schemas_string().optional(),
23333
- collectionId: schemas_string().optional(),
23334
- collectionBind: custom().optional(),
23335
- groupBind: custom().optional(),
23336
- noteCopyBind: schemas_boolean().optional(),
23337
- coProduceBind: schemas_boolean().optional(),
23338
- originalBind: schemas_boolean().optional()
23339
- });
23340
- const xiaohongshuPublish = async (_task, _params)=>({
23294
+ let _windowCache = null;
23295
+ const getWindow = ()=>{
23296
+ if (_windowCache) return _windowCache;
23297
+ _windowCache = "undefined" != typeof window ? window : globalThis;
23298
+ return _windowCache;
23299
+ };
23300
+ if ("undefined" != typeof process) {
23301
+ process.on("uncaughtException", ()=>{});
23302
+ process.on("unhandledRejection", ()=>{});
23303
+ }
23304
+ const mnsv2_enc = (arg1, arg2, cookieString)=>{
23305
+ const win = getWindow();
23306
+ win.ck = cookieString;
23307
+ __webpack_require__("./src/utils/xhs_ob_feed/ob.env.js");
23308
+ try {
23309
+ __webpack_require__("./src/utils/xhs_ob_feed/ob.enc.js");
23310
+ } catch {}
23311
+ let result = "";
23312
+ try {
23313
+ result = win.mnsv2(arg1, arg2);
23314
+ } catch {}
23315
+ return result;
23316
+ };
23317
+ const mnsvc2 = mnsv2_enc;
23318
+ const xhs_ob_feed_encode_mnsv2 = __webpack_require__("./src/utils/xhs_ob_feed/x_s.encoder.js");
23319
+ class xhs_ob_feed_Xhshow {
23320
+ stringifyCookies(cookies) {
23321
+ return Object.entries(cookies).map(([key, value])=>`${key}=${value}`).join("; ");
23322
+ }
23323
+ signHeadersGet(uri, cookieString, xsecAppid = "ugc", params) {
23324
+ let para1 = "";
23325
+ if (params && 0 !== Object.keys(params).length) {
23326
+ const _queryPara = Object.entries(params).map(([key, value])=>{
23327
+ let valueStr = "";
23328
+ if (Array.isArray(value)) valueStr = value.map((v)=>String(v)).join(",");
23329
+ else if (null != value) valueStr = String(value);
23330
+ return `${key}=${valueStr}`;
23331
+ });
23332
+ para1 = `${uri}?${_queryPara.join("&")}`;
23333
+ } else para1 = uri;
23334
+ const md5Para1 = external_node_crypto_default().createHash("md5").update(para1).digest("hex");
23335
+ const mnsvc2_data = mnsvc2(para1, md5Para1, this.stringifyCookies(cookieString));
23336
+ return {
23337
+ "X-S": xhs_ob_feed_encode_mnsv2(mnsvc2_data, xsecAppid, "Windows", "object")
23338
+ };
23339
+ }
23340
+ signHeadersPost(uri, cookieString, xsecAppid = "ugc", payload) {
23341
+ const para1 = uri + JSON.stringify(payload || {});
23342
+ const md5Para1 = external_node_crypto_default().createHash("md5").update(para1).digest("hex");
23343
+ const mnsvc2_data = mnsvc2(para1, md5Para1, this.stringifyCookies(cookieString));
23344
+ return {
23345
+ "X-S": xhs_ob_feed_encode_mnsv2(mnsvc2_data, xsecAppid, "Windows", "object")
23346
+ };
23347
+ }
23348
+ }
23349
+ const xiaohongshuPublish_mock_errnoMap = {
23350
+ "-1": "未知拦截器错误,请稍后重试。",
23351
+ 915: "所属C端账号手机号被修改,请重新登录",
23352
+ 914: "所属C端账号密码被修改,请重新登录",
23353
+ 903: "账户已登出,需重新登陆重试!",
23354
+ 902: "登录已过期,请重新登录!",
23355
+ 906: "账号存在风险,请重新登录!",
23356
+ "-9136": "因违反社区规范禁止发笔记,请检查账号状态!"
23357
+ };
23358
+ const mock_xsEncrypt = new xhs_ob_feed_Xhshow();
23359
+ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
23360
+ const tmpCachePath = task.getTmpPath();
23361
+ if (params?.selfDeclaration?.type === "source-statement" && "transshipment" === params.selfDeclaration.childType && params.originalBind) return {
23341
23362
  code: 414,
23342
- data: "",
23343
- message: "临时维护:小红书发布政策调整,本平台小红书发布功能临时暂停服务并进行维护调整,暂时无法正常发布,敬请理解知悉。"
23344
- });
23345
- const xiaohongshuWebCommentAction_xsEncrypt = new Xhshow();
23346
- const xiaohongshuWebCommentAction = async (_task, params)=>{
23347
- if (DisabledReq) return (0, share_namespaceObject.response)(414, "点赞相关操作失败", {});
23348
- const headers = {
23349
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23350
- referer: "https://www.xiaohongshu.com/",
23351
- origin: "https://www.xiaohongshu.com/"
23363
+ message: "原创声明与转载声明互斥,请重新选择后发布!",
23364
+ data: ""
23352
23365
  };
23353
- const args = [
23354
- {
23355
- headers
23356
- },
23357
- _task.logger,
23358
- params.proxyLoc,
23359
- params.localIP,
23360
- params.accountId
23361
- ];
23362
- const http = new Http(...args);
23363
23366
  const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
23364
23367
  if (!a1Cookie) return {
23365
23368
  code: 414,
23366
23369
  message: "账号数据异常,请重新绑定账号后重试。",
23367
- data: []
23368
- };
23369
- if (!params.note_id && !params.comment_id && !params.action) return {
23370
- code: 414,
23371
- message: "参数缺失,请检查后重试!",
23372
- data: {}
23373
- };
23374
- const actionParams = {
23375
- note_id: params.note_id,
23376
- comment_id: params.comment_id
23370
+ data: ""
23377
23371
  };
23378
- let likeActionRes = {
23379
- code: 500,
23380
- success: false,
23381
- msg: ""
23372
+ const headers = {
23373
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23374
+ origin: "https://creator.xiaohongshu.com",
23375
+ referer: "https://creator.xiaohongshu.com/",
23376
+ "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"
23382
23377
  };
23383
23378
  const recordCookie = params.cookies.reduce((acc, cookie)=>{
23384
23379
  if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
23385
23380
  return acc;
23386
23381
  }, {});
23387
- switch(params.action){
23388
- case "like":
23389
- {
23390
- const likeAction = "/api/sns/web/v1/comment/like";
23391
- const likeActionXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(likeAction, recordCookie, "xhs-pc-web", actionParams);
23392
- likeActionRes = await http.api({
23393
- method: "post",
23394
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/like",
23395
- data: actionParams,
23396
- headers: likeActionXsHeader
23397
- }, {
23398
- retries: 3,
23399
- retryDelay: 20,
23400
- timeout: 3000
23401
- });
23402
- break;
23403
- }
23404
- case "dislike":
23405
- {
23406
- const dislikeMentions = "/api/sns/web/v1/comment/dislike";
23407
- const dislikeXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(dislikeMentions, recordCookie, "xhs-pc-web", actionParams);
23408
- likeActionRes = await http.api({
23409
- method: "post",
23410
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/dislike",
23411
- data: actionParams,
23412
- headers: dislikeXsHeader
23413
- }, {
23414
- retries: 3,
23415
- retryDelay: 20,
23416
- timeout: 3000
23417
- });
23418
- break;
23419
- }
23420
- default:
23421
- return {
23422
- code: 414,
23423
- message: "参数action错误,请重试!",
23424
- data: {}
23425
- };
23426
- }
23427
- const isSuccess = 0 === likeActionRes.code;
23428
- const message = `点赞相关操作${isSuccess ? "成功" : `失败,原因:${likeActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
23429
- const data = isSuccess ? likeActionRes.success : {};
23430
- return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
23431
- };
23432
- const xiaohongshuWebIntimacySearch = async (_task, params)=>{
23433
- if (DisabledReq) return (0, share_namespaceObject.response)(0, "搜索@列表数据成功", []);
23434
- const headers = {
23435
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23436
- referer: "https://www.xiaohongshu.com/",
23437
- origin: "https://www.xiaohongshu.com"
23438
- };
23439
23382
  const args = [
23440
23383
  {
23441
23384
  headers
23442
23385
  },
23443
- _task.logger,
23386
+ task.logger,
23444
23387
  params.proxyLoc,
23445
23388
  params.localIP,
23446
23389
  params.accountId
23447
23390
  ];
23448
- const http = new Http(...args);
23449
- let intimacyDetail = [];
23450
- const res = await http.api({
23451
- method: "get",
23452
- url: `https://edith.xiaohongshu.com/api/sns/web/v1/intimacy/intimacy_list${params.searchValue ? "/search" : ""}`,
23453
- ...params.searchValue ? {
23454
- params: {
23455
- keyword: params.searchValue,
23456
- page: 1,
23457
- rows: 30
23458
- }
23459
- } : {}
23460
- }, {
23461
- retries: 3,
23462
- retryDelay: 20,
23463
- timeout: 3000
23391
+ const http = new Http({
23392
+ headers
23464
23393
  });
23465
- const isSuccess = 0 === res.code;
23466
- if (isSuccess) intimacyDetail = res.data.items;
23467
- const message = `搜索@列表数据${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
23468
- return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, intimacyDetail);
23469
- };
23470
- const xiaohongshuWebMsgRead_xsEncrypt = new Xhshow();
23471
- const xiaohongshuWebMsgRead = async (_task, params)=>{
23472
- if (DisabledReq) return (0, share_namespaceObject.response)(414, "Read指定Tab失败", {});
23473
- const headers = {
23474
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23475
- referer: "https://www.xiaohongshu.com/",
23476
- origin: "https://www.xiaohongshu.com/"
23394
+ const proxyHttp = new Http(...args);
23395
+ proxyHttp.addResponseInterceptor((response)=>{
23396
+ const responseData = response.data;
23397
+ if (response && responseData?.code && 0 !== responseData.code || responseData?.code && !responseData.success) {
23398
+ const errmsg = xiaohongshuPublish_mock_errnoMap[responseData.code] || response.config.defaultErrorMsg || "文章发布异常,请稍后重试。";
23399
+ return {
23400
+ code: xiaohongshuPublish_mock_errnoMap[responseData.code] ? 414 : 500,
23401
+ message: errmsg,
23402
+ data: responseData
23403
+ };
23404
+ }
23405
+ });
23406
+ const fetchCoverUrl = "/api/media/v1/upload/creator/permit";
23407
+ const fetchCoverParams = {
23408
+ biz_name: "spectrum",
23409
+ scene: "image",
23410
+ file_count: params.banners.length,
23411
+ version: 1,
23412
+ source: "web"
23477
23413
  };
23478
- const args = [
23479
- {
23480
- headers
23481
- },
23482
- _task.logger,
23483
- params.proxyLoc,
23484
- params.localIP,
23485
- params.accountId
23486
- ];
23487
- const http = new Http(...args);
23488
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
23489
- if (!a1Cookie) return {
23414
+ const fetchCoverXsHeader = mock_xsEncrypt.signHeadersGet(fetchCoverUrl, recordCookie, "ugc", fetchCoverParams);
23415
+ const uploadInfos = [];
23416
+ if (params.banners.length > 18) {
23417
+ const num = Math.ceil(params.banners.length / 14);
23418
+ for(let i = 0; i < num; i++){
23419
+ const start = 14 * i;
23420
+ params.banners.length;
23421
+ ({
23422
+ ...fetchCoverParams
23423
+ });
23424
+ const batchCoverIdInfo = await proxyHttp.api({
23425
+ method: "get",
23426
+ baseURL: "https://creator.xiaohongshu.com",
23427
+ url: fetchCoverUrl,
23428
+ defaultErrorMsg: "获取小红书用户信息失败,请稍后重试发布。",
23429
+ headers: fetchCoverXsHeader,
23430
+ params: fetchCoverParams
23431
+ }, {
23432
+ retries: 3,
23433
+ retryDelay: 20,
23434
+ timeout: 3000
23435
+ });
23436
+ for (const item of batchCoverIdInfo.data.uploadTempPermits)for (const fileId of item.fileIds)uploadInfos.push({
23437
+ bucket: item.bucket || "",
23438
+ uploadAddr: item.uploadAddr || "",
23439
+ fileIds: fileId,
23440
+ token: item.token || ""
23441
+ });
23442
+ }
23443
+ } else {
23444
+ const coverIdInfo = await proxyHttp.api({
23445
+ method: "get",
23446
+ baseURL: "https://creator.xiaohongshu.com",
23447
+ url: fetchCoverUrl,
23448
+ defaultErrorMsg: "获取小红书用户信息失败,请稍后重试发布。",
23449
+ headers: fetchCoverXsHeader,
23450
+ params: fetchCoverParams
23451
+ }, {
23452
+ retries: 3,
23453
+ retryDelay: 20,
23454
+ timeout: 3000
23455
+ });
23456
+ for (const item of coverIdInfo.data.uploadTempPermits)for (const fileId of item.fileIds)uploadInfos.push({
23457
+ bucket: item.bucket || "",
23458
+ uploadAddr: item.uploadAddr || "",
23459
+ fileIds: fileId,
23460
+ token: item.token || ""
23461
+ });
23462
+ }
23463
+ if (uploadInfos.length < params.banners.length) return {
23490
23464
  code: 414,
23491
- message: "账号数据异常,请重新绑定账号后重试。",
23492
- data: []
23465
+ message: "可用 OSS bucket 数量不足,无法上传所有图片!",
23466
+ data: ""
23493
23467
  };
23494
- if (!params.type) return {
23468
+ if (0 === uploadInfos.length) return {
23495
23469
  code: 414,
23496
- message: "参数缺失,请检查后重试!",
23497
- data: {}
23470
+ message: "图片上传失败,请稍后重试!",
23471
+ data: ""
23498
23472
  };
23499
- const replyParams = {
23500
- type: params.type
23473
+ const availableBuckets = Array.from({
23474
+ length: uploadInfos.length
23475
+ }, (_, i)=>i);
23476
+ const uploadFile = async (url, index)=>{
23477
+ const fileName = (0, share_namespaceObject.getFilenameFromUrl)(url);
23478
+ const localUrl = await (0, share_namespaceObject.downloadImage)(url, external_node_path_default().join(tmpCachePath, fileName));
23479
+ const fileBuffer = external_node_fs_default().readFileSync(localUrl);
23480
+ const MAX_RETRIES = uploadInfos.length;
23481
+ let attempt = 0;
23482
+ while(attempt < MAX_RETRIES){
23483
+ const ossBucketIndex = availableBuckets.shift();
23484
+ if (void 0 === ossBucketIndex) break;
23485
+ const currentInfo = uploadInfos[ossBucketIndex];
23486
+ const ossFileId = currentInfo.fileIds;
23487
+ const ossToken = currentInfo.token;
23488
+ const ossDomain = currentInfo.uploadAddr;
23489
+ try {
23490
+ await http.api({
23491
+ method: "put",
23492
+ url: `https://${ossDomain}/${ossFileId}`,
23493
+ data: fileBuffer,
23494
+ headers: {
23495
+ "x-cos-security-token": ossToken
23496
+ },
23497
+ defaultErrorMsg: "图片上传异常,请稍后重试发布。"
23498
+ });
23499
+ return {
23500
+ ossFileId,
23501
+ ossToken
23502
+ };
23503
+ } catch (error) {
23504
+ attempt++;
23505
+ }
23506
+ }
23507
+ return {
23508
+ ossFileId: "",
23509
+ ossToken: ""
23510
+ };
23501
23511
  };
23502
- const fatchMentions = "/api/sns/web/v1/message/read";
23503
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
23504
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
23505
- return acc;
23506
- }, {});
23507
- const fatchMentionsXsHeader = xiaohongshuWebMsgRead_xsEncrypt.signHeadersPost(fatchMentions, recordCookie, "xhs-pc-web", replyParams);
23508
- const res = await http.api({
23509
- method: "post",
23510
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/message/read",
23511
- data: replyParams,
23512
- headers: fatchMentionsXsHeader
23512
+ const coverInfos = await Promise.all(params.banners.map((it, idx)=>uploadFile(it, idx)));
23513
+ const invalidUpload = coverInfos.find((it)=>"" === it.ossToken || "" === it.ossFileId);
23514
+ if (invalidUpload) return {
23515
+ code: 414,
23516
+ message: "图片上传异常,请稍后重试发布。",
23517
+ data: ""
23518
+ };
23519
+ if (params.topic && params.topic.length > 0) await Promise.all(params.topic.map(async (topic)=>{
23520
+ if (!topic.id) {
23521
+ const topicData = {
23522
+ topic_names: topic.name
23523
+ };
23524
+ const topicXsHeader = mock_xsEncrypt.signHeadersPost("/web_api/sns/capa/postgw/topic/batch_customized", recordCookie, "ugc", topicData);
23525
+ const createTopic = await proxyHttp.api({
23526
+ method: "POST",
23527
+ url: "https://edith.xiaohongshu.com/web_api/sns/capa/postgw/topic/batch_customized",
23528
+ headers: topicXsHeader,
23529
+ data: topicData,
23530
+ defaultErrorMsg: "话题创建异常,请稍后重试。"
23531
+ }, {
23532
+ retries: 3,
23533
+ retryDelay: 20,
23534
+ timeout: 3000
23535
+ });
23536
+ if (!createTopic?.data) throw types_errorResponse("话题创建失败,请检查话题字段!", 414);
23537
+ Object.assign(topic, createTopic?.data?.topic_infos[0]);
23538
+ }
23539
+ }));
23540
+ const visibleRangeMap = {
23541
+ public: 0,
23542
+ private: 1,
23543
+ friends: 4
23544
+ };
23545
+ const publishData = {
23546
+ common: {
23547
+ ats: [],
23548
+ biz_relations: [],
23549
+ desc: params?.content,
23550
+ goods_info: {},
23551
+ hash_tag: params.topic || [],
23552
+ note_id: "",
23553
+ source: JSON.stringify({
23554
+ type: "web",
23555
+ ids: "",
23556
+ extraInfo: '{"systemId":"web"}'
23557
+ }),
23558
+ title: params?.title,
23559
+ type: "normal",
23560
+ privacy_info: {
23561
+ op_type: 1,
23562
+ type: visibleRangeMap[params.visibleRange]
23563
+ },
23564
+ post_loc: params.address ? {
23565
+ name: params.address?.name,
23566
+ poi_id: params.address?.poi_id,
23567
+ poi_type: params.address?.poi_type,
23568
+ subname: params.address?.full_address
23569
+ } : null,
23570
+ business_binds: ""
23571
+ },
23572
+ image_info: {
23573
+ images: coverInfos.map((it)=>({
23574
+ extra_info_json: '{"mimeType":"image/png"}',
23575
+ file_id: it.ossFileId,
23576
+ metadata: {
23577
+ source: -1
23578
+ },
23579
+ stickers: {
23580
+ floating: [],
23581
+ version: 2
23582
+ }
23583
+ }))
23584
+ },
23585
+ video_info: null
23586
+ };
23587
+ const userDeclarationBind = {
23588
+ origin: 2,
23589
+ photoInfo: {},
23590
+ repostInfo: {}
23591
+ };
23592
+ if (params.selfDeclaration?.type === "fictional-rendition") userDeclarationBind.origin = 1;
23593
+ else if (params.selfDeclaration?.type === "ai-generated") userDeclarationBind.origin = 2;
23594
+ else if (params.selfDeclaration?.type === "source-statement") {
23595
+ if ("self-labeling" === params.selfDeclaration.childType) userDeclarationBind.origin = 3;
23596
+ else if ("self-shooting" === params.selfDeclaration.childType) {
23597
+ userDeclarationBind.origin = 4;
23598
+ const photoInfo = {};
23599
+ if (params.selfDeclaration.shootingLocation) photoInfo.photoPlace = {
23600
+ name: params.selfDeclaration.shootingLocation.name,
23601
+ poiId: params.selfDeclaration.shootingLocation.poi_id,
23602
+ poiType: params.selfDeclaration.shootingLocation.poi_type,
23603
+ subname: params.selfDeclaration.shootingLocation.full_address
23604
+ };
23605
+ if (params.selfDeclaration.shootingDate) photoInfo.photoTime = params.selfDeclaration.shootingDate;
23606
+ userDeclarationBind.photoInfo = photoInfo;
23607
+ } else if ("transshipment" === params.selfDeclaration.childType) {
23608
+ userDeclarationBind.origin = 5;
23609
+ if (params.selfDeclaration.sourceMedia) userDeclarationBind.repostInfo = {
23610
+ source: params.selfDeclaration.sourceMedia
23611
+ };
23612
+ }
23613
+ }
23614
+ const bizId = params?.originalBind && (params.cookies.find((it)=>"x-user-id-creator.xiaohongshu.com" === it.name)?.value || await proxyHttp.api({
23615
+ method: "get",
23616
+ url: "https://creator.xiaohongshu.com/api/galaxy/user/my-info"
23513
23617
  }, {
23514
23618
  retries: 3,
23515
23619
  retryDelay: 20,
23516
23620
  timeout: 3000
23517
- });
23518
- const isSuccess = 0 === res.code;
23519
- const message = `Read指定Tab${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
23520
- const data = isSuccess ? res.success : {};
23521
- return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
23522
- };
23523
- const xiaohongshuWebMsgReply_xsEncrypt = new Xhshow();
23524
- const xiaohongshuWebMsgReply = async (_task, params)=>{
23525
- if (DisabledReq) return (0, share_namespaceObject.response)(414, "评论回复失败", {});
23526
- const headers = {
23527
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23528
- referer: "https://www.xiaohongshu.com/",
23529
- origin: "https://www.xiaohongshu.com/"
23530
- };
23531
- const args = [
23532
- {
23533
- headers
23621
+ }).then((userData)=>userData.data?.userDetail?.id));
23622
+ const business_binds = {
23623
+ version: 1,
23624
+ bizType: "",
23625
+ noteId: "",
23626
+ noteOrderBind: {},
23627
+ notePostTiming: params.isImmediatelyPublish ? {} : {
23628
+ postTime: params.scheduledPublish
23534
23629
  },
23535
- _task.logger,
23536
- params.proxyLoc,
23537
- params.localIP,
23538
- params.accountId
23539
- ];
23540
- const http = new Http(...args);
23541
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
23542
- if (!a1Cookie) return {
23543
- code: 414,
23544
- message: "账号数据异常,请重新绑定账号后重试。",
23545
- data: []
23546
- };
23547
- if (!params.note_id || !params.target_comment_id || !params.content) return {
23548
- code: 414,
23549
- message: "参数缺失,请检查后重试!",
23550
- data: {}
23551
- };
23552
- const replyParams = {
23553
- at_users: params.at_users ?? [],
23554
- content: params.content,
23555
- note_id: params.note_id,
23556
- target_comment_id: params.target_comment_id
23630
+ coProduceBind: {
23631
+ enable: !!params?.coProduceBind
23632
+ },
23633
+ noteCopyBind: {
23634
+ copyable: !!params?.noteCopyBind
23635
+ },
23636
+ optionRelationList: params.originalBind ? [
23637
+ {
23638
+ type: "ORIGINAL_STATEMENT",
23639
+ relationList: [
23640
+ {
23641
+ bizId,
23642
+ bizType: "ORIGINAL_STATEMENT",
23643
+ extraInfo: "{}"
23644
+ }
23645
+ ]
23646
+ }
23647
+ ] : [],
23648
+ ...params?.groupBind ? {
23649
+ groupBind: {
23650
+ groupId: params?.groupBind?.group_id,
23651
+ groupName: params.groupBind?.group_name,
23652
+ desc: params.groupBind?.desc,
23653
+ avatar: params.groupBind?.avatar
23654
+ }
23655
+ } : {
23656
+ groupBind: {}
23657
+ },
23658
+ ...params.selfDeclaration ? {
23659
+ userDeclarationBind
23660
+ } : {},
23661
+ ...params?.collectionBind?.id ? {
23662
+ noteCollectionBind: {
23663
+ id: params.collectionBind.id
23664
+ }
23665
+ } : {}
23557
23666
  };
23558
- const replyPath = "/api/sns/web/v1/comment/post";
23559
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
23560
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
23561
- return acc;
23562
- }, {});
23563
- const replyXsHeader = xiaohongshuWebMsgReply_xsEncrypt.signHeadersPost(replyPath, recordCookie, "xhs-pc-web", replyParams);
23564
- const res = await http.api({
23667
+ publishData.common.business_binds = JSON.stringify(business_binds);
23668
+ const publishXsHeader = mock_xsEncrypt.signHeadersPost("/web_api/sns/v2/note", recordCookie, "ugc", publishData);
23669
+ task._timerRecord.PrePublish = Date.now();
23670
+ const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
23671
+ if (MockPublish) {
23672
+ const message = `文章模拟发布成功 ${http.proxyInfo}`;
23673
+ const data = "123456789";
23674
+ await updateTaskState?.({
23675
+ state: share_namespaceObject.TaskState.SUCCESS,
23676
+ result: {
23677
+ response: data
23678
+ }
23679
+ });
23680
+ return (0, share_namespaceObject.success)(data, message);
23681
+ }
23682
+ const publishResult = await proxyHttp.api({
23565
23683
  method: "post",
23566
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/post",
23567
- data: replyParams,
23568
- headers: replyXsHeader
23684
+ url: "https://edith.xiaohongshu.com/web_api/sns/v2/note",
23685
+ data: publishData,
23686
+ headers: publishXsHeader,
23687
+ defaultErrorMsg: "文章发布异常,请稍后重试。"
23569
23688
  }, {
23570
- retries: 3,
23571
- retryDelay: 20,
23572
- timeout: 3000
23689
+ retries: 2,
23690
+ retryDelay: 500,
23691
+ timeout: 12000
23573
23692
  });
23574
- const isSuccess = 0 === res.code;
23575
- const message = `评论回复${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
23576
- const data = isSuccess ? res.data : {};
23577
- return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
23578
- };
23579
- let _windowCache = null;
23580
- const getWindow = ()=>{
23581
- if (_windowCache) return _windowCache;
23582
- _windowCache = "undefined" != typeof window ? window : globalThis;
23583
- return _windowCache;
23584
- };
23585
- if ("undefined" != typeof process) {
23586
- process.on("uncaughtException", ()=>{});
23587
- process.on("unhandledRejection", ()=>{});
23588
- }
23589
- const mnsv2_enc = (arg1, arg2, cookieString)=>{
23590
- const win = getWindow();
23591
- win.ck = cookieString;
23592
- __webpack_require__("./src/utils/xhs_ob_feed/ob.env.js");
23593
- try {
23594
- __webpack_require__("./src/utils/xhs_ob_feed/ob.enc.js");
23595
- } catch {}
23596
- let result = "";
23597
- try {
23598
- result = win.mnsv2(arg1, arg2);
23599
- } catch {}
23600
- return result;
23601
- };
23602
- const mnsvc2 = mnsv2_enc;
23603
- const xhs_ob_feed_encode_mnsv2 = __webpack_require__("./src/utils/xhs_ob_feed/x_s.encoder.js");
23604
- class xhs_ob_feed_Xhshow {
23605
- stringifyCookies(cookies) {
23606
- return Object.entries(cookies).map(([key, value])=>`${key}=${value}`).join("; ");
23607
- }
23608
- signHeadersGet(uri, cookieString, xsecAppid = "ugc", params) {
23609
- let para1 = "";
23610
- if (params && 0 !== Object.keys(params).length) {
23611
- const _queryPara = Object.entries(params).map(([key, value])=>{
23612
- let valueStr = "";
23613
- if (Array.isArray(value)) valueStr = value.map((v)=>String(v)).join(",");
23614
- else if (null != value) valueStr = String(value);
23615
- return `${key}=${valueStr}`;
23616
- });
23617
- para1 = `${uri}?${_queryPara.join("&")}`;
23618
- } else para1 = uri;
23619
- const md5Para1 = external_node_crypto_default().createHash("md5").update(para1).digest("hex");
23620
- const mnsvc2_data = mnsvc2(para1, md5Para1, this.stringifyCookies(cookieString));
23621
- return {
23622
- "X-S": xhs_ob_feed_encode_mnsv2(mnsvc2_data, xsecAppid, "Windows", "object")
23623
- };
23624
- }
23625
- signHeadersPost(uri, cookieString, xsecAppid = "ugc", payload) {
23626
- const para1 = uri + JSON.stringify(payload || {});
23627
- const md5Para1 = external_node_crypto_default().createHash("md5").update(para1).digest("hex");
23628
- const mnsvc2_data = mnsvc2(para1, md5Para1, this.stringifyCookies(cookieString));
23693
+ reportLogger({
23694
+ token: params.huiwenToken || "",
23695
+ enverionment: task.enverionment || "development",
23696
+ postId: params.articleId,
23697
+ eip: proxyHttp.proxyInfo,
23698
+ proxyIp: params.localIP,
23699
+ accountId: params.accountId,
23700
+ uid: params.uid,
23701
+ platform: "xiaohongshu",
23702
+ publishParams: publishData
23703
+ });
23704
+ const isSuccess = publishResult.success;
23705
+ const message = `文章发布${isSuccess ? "成功" : `失败,原因:${publishResult.msg}`}${task.debug ? ` ${http.proxyInfo}` : ""}`;
23706
+ const data = isSuccess ? publishResult.data?.id || "" : "";
23707
+ if (!isSuccess) {
23708
+ await updateTaskState?.({
23709
+ state: share_namespaceObject.TaskState.FAILED,
23710
+ error: message
23711
+ });
23629
23712
  return {
23630
- "X-S": xhs_ob_feed_encode_mnsv2(mnsvc2_data, xsecAppid, "Windows", "object")
23713
+ code: 414,
23714
+ data,
23715
+ message
23631
23716
  };
23632
23717
  }
23633
- }
23634
- const xiaohongshuWebNoteFeed_xsEncrypt = new xhs_ob_feed_Xhshow();
23635
- const GenXSCommon = __webpack_require__("./src/utils/XhsXsCommonEnc.js");
23636
- const xiaohongshuWebNoteFeed = async (_task, params)=>{
23637
- if (DisabledReq) return (0, share_namespaceObject.response)(414, "获取指定文章详情失败", {});
23638
- const headers = {
23639
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23640
- referer: "https://www.xiaohongshu.com/",
23641
- origin: "https://www.xiaohongshu.com/"
23642
- };
23643
- const args = [
23644
- {
23645
- headers
23646
- },
23647
- _task.logger,
23648
- params.proxyLoc,
23649
- params.localIP,
23650
- params.accountId
23651
- ];
23652
- const http = new Http(...args);
23653
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
23654
- if (!a1Cookie) return {
23655
- code: 414,
23656
- message: "账号数据异常,请重新绑定账号后重试。",
23657
- data: {}
23658
- };
23659
- if (!params.source_note_id && !params.xsec_token) return {
23660
- code: 414,
23661
- message: "参数缺失,请检查后重试!",
23662
- data: {}
23663
- };
23664
- const feedParams = {
23665
- source_note_id: params.source_note_id,
23666
- image_formats: [
23667
- "jpg",
23668
- "webp",
23669
- "avif"
23670
- ],
23671
- extra: {
23672
- need_body_topic: "1"
23673
- },
23674
- xsec_source: "pc_feed",
23675
- xsec_token: params.xsec_token
23676
- };
23677
- const fatchFeed = "/api/sns/web/v1/feed";
23678
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
23679
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
23680
- return acc;
23681
- }, {});
23682
- const xsHeader = xiaohongshuWebNoteFeed_xsEncrypt.signHeadersPost(fatchFeed, recordCookie, "xhs-pc-web", feedParams);
23683
- const xT = Date.now().toString();
23684
- const xsCommon = GenXSCommon(a1Cookie, xT, xsHeader["X-S"]);
23685
- _task.logger.info(`请求参数: ${JSON.stringify(feedParams)}`);
23686
- _task.logger.info(`X-S: ${xsHeader["X-S"]}`);
23687
- _task.logger.info(`x-s-common: ${xsCommon}`);
23688
- const res = await http.api({
23689
- method: "post",
23690
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/feed",
23691
- data: feedParams,
23692
- headers: {
23693
- "X-S": xsHeader["X-S"],
23694
- "X-S-Common": xsCommon,
23695
- "X-T": xT
23718
+ await updateTaskState?.({
23719
+ state: share_namespaceObject.TaskState.SUCCESS,
23720
+ result: {
23721
+ response: data
23696
23722
  }
23697
- }, {
23698
- retries: 3,
23699
- retryDelay: 20,
23700
- timeout: 3000
23701
23723
  });
23702
- _task.logger.info(`API 响应: ${JSON.stringify(res)}`);
23703
- const isSuccess = 0 === res.code && res.data && res.data.items && res.data.items.length > 0;
23704
- const message = `获取指定文章详情${isSuccess ? "成功" : `失败,原因:${res.msg || "返回数据为空,可能笔记不存在或参数错误"}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
23705
- const data = isSuccess ? res.data?.items[0].note_card || {} : {};
23706
23724
  return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
23707
23725
  };
23708
- const xiaohongshuWebRelationAction_xsEncrypt = new Xhshow();
23709
- const xiaohongshuWebRelationAction = async (_task, params)=>{
23710
- if (DisabledReq) return (0, share_namespaceObject.response)(414, "用户关系操作失败", {});
23711
- const headers = {
23712
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23713
- referer: "https://www.xiaohongshu.com/",
23714
- origin: "https://www.xiaohongshu.com/"
23726
+ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
23727
+ const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
23728
+ const commonCookies = {
23729
+ path: "/",
23730
+ sameSite: "lax",
23731
+ secure: false,
23732
+ domain: ".xiaohongshu.com",
23733
+ url: "https://creator.xiaohongshu.com",
23734
+ httpOnly: true
23715
23735
  };
23716
- const args = [
23717
- {
23718
- headers
23719
- },
23720
- _task.logger,
23721
- params.proxyLoc,
23722
- params.localIP,
23723
- params.accountId
23724
- ];
23725
- const http = new Http(...args);
23726
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
23727
- if (!a1Cookie) return {
23728
- code: 414,
23729
- message: "账号数据异常,请重新绑定账号后重试。",
23730
- data: {}
23731
- };
23732
- if (!params.action || !params.target_user_id) return {
23733
- code: 414,
23734
- message: "参数缺失,请检查后重试!",
23735
- data: {}
23736
- };
23737
- const relationParams = {
23738
- target_user_id: params.target_user_id
23739
- };
23740
- let relationActionRes;
23741
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
23742
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
23743
- return acc;
23744
- }, {});
23745
- switch(params.action){
23746
- case "follow":
23747
- {
23748
- const followMentions = "/api/sns/web/v1/user/follow";
23749
- const followXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(followMentions, recordCookie, "xhs-pc-web", relationParams);
23750
- relationActionRes = await http.api({
23751
- method: "post",
23752
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/follow",
23753
- data: relationParams,
23754
- headers: followXsHeader
23755
- }, {
23756
- retries: 3,
23757
- retryDelay: 500,
23758
- timeout: 3000
23759
- });
23760
- break;
23761
- }
23762
- case "unfollow":
23763
- {
23764
- const unfllowMentions = "/api/sns/web/v1/user/unfollow";
23765
- const unfllowXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(unfllowMentions, recordCookie, "xhs-pc-web", relationParams);
23766
- relationActionRes = await http.api({
23767
- method: "post",
23768
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/unfollow",
23769
- data: relationParams,
23770
- headers: unfllowXsHeader
23771
- }, {
23772
- retries: 3,
23773
- retryDelay: 20,
23774
- timeout: 3000
23775
- });
23776
- break;
23777
- }
23778
- default:
23779
- return {
23780
- code: 414,
23781
- message: "参数action错误,请重试!",
23782
- data: {}
23783
- };
23784
- }
23785
- const isSuccess = 0 === relationActionRes.code;
23786
- const message = `用户关系操作${isSuccess ? "成功" : `失败,原因:${relationActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
23787
- const data = isSuccess ? relationActionRes.data : {
23788
- fstatus: null
23736
+ const page = await task.createPage({
23737
+ show: task.debug,
23738
+ url: params.url || "https://creator.xiaohongshu.com/publish/publish",
23739
+ cookies: params.cookies?.map((it)=>({
23740
+ ...it,
23741
+ ...commonCookies
23742
+ }))
23743
+ });
23744
+ await updateTaskState?.({
23745
+ state: share_namespaceObject.TaskState.ACTION,
23746
+ connectAddress: task.steelConnector?.getProxyUrl(task.sessionId || "", "v1/sessions/debug"),
23747
+ sessionId: task.sessionId
23748
+ });
23749
+ const tmpCachePath = task.getTmpPath();
23750
+ const selectAddress = async (selector, address)=>{
23751
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
23752
+ await instance.click();
23753
+ await instance.locator("input").fill(address);
23754
+ const poperInstance = page.locator('.d-popover:not([style*="display: none"]) .d-options .d-grid-item');
23755
+ await poperInstance.first().waitFor();
23756
+ await poperInstance.first().click();
23789
23757
  };
23790
- return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
23791
- };
23792
- const xiaohongshuWebSearch_xsEncrypt = new Xhshow();
23793
- const XhsWebSearchParamsSchema = ActionCommonParamsSchema.extend({
23794
- keyword: schemas_string(),
23795
- page: schemas_number(),
23796
- page_size: schemas_number(),
23797
- sort_type: schemas_enum([
23798
- "general",
23799
- "time_descending",
23800
- "popular_descending"
23801
- ]),
23802
- time_filter: schemas_enum([
23803
- "不限",
23804
- "一周内"
23805
- ])
23806
- });
23807
- const createSearchId = ()=>{
23808
- let r = BigInt(Date.now());
23809
- const o = BigInt(Math.ceil(0x7ffffffe * Math.random()));
23810
- r <<= BigInt(64);
23811
- r += o;
23812
- return r.toString(36);
23813
- };
23814
- const xiaohongshuWebSearch = async (_task, params)=>{
23815
- const headers = {
23816
- cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
23817
- referer: "https://www.xiaohongshu.com/",
23818
- origin: "https://www.xiaohongshu.com/"
23758
+ const selectDate = async (selector, date)=>{
23759
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
23760
+ await instance.click();
23761
+ await instance.fill(date);
23762
+ await instance.blur();
23819
23763
  };
23820
- const args = [
23821
- {
23822
- headers
23823
- },
23824
- _task.logger,
23825
- params.proxyLoc,
23826
- params.localIP,
23827
- params.accountId
23828
- ];
23829
- const http = new Http(...args);
23830
- const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
23831
- if (!a1Cookie) return {
23832
- code: 414,
23833
- message: "账号数据异常,请重新绑定账号后重试。",
23834
- data: {}
23764
+ const getPoperInstance = async ()=>{
23765
+ await page.waitForTimeout(500);
23766
+ const elements = page.locator(".d-popover");
23767
+ const count = await elements.count();
23768
+ const visibleElements = [];
23769
+ for(let i = 0; i < count; i++){
23770
+ const element = elements.nth(i);
23771
+ const style = await element.getAttribute("style");
23772
+ if (style && !style.includes("display: none")) visibleElements.push(element);
23773
+ }
23774
+ if (visibleElements.length > 0) return visibleElements[visibleElements.length - 1];
23775
+ throw new Error("未找到 popover 弹窗");
23776
+ };
23777
+ const getDialogInstance = async ()=>{
23778
+ await page.waitForTimeout(1000);
23779
+ const elements = page.locator(".el-dialog");
23780
+ return elements.last();
23835
23781
  };
23836
- if (!params.keyword || !params.page || !params.page_size || !params.sort_type || !params.time_filter) {
23837
- if ("general" !== params.sort_type && "time_descending" !== params.sort_type && "popular_descending" !== params.sort_type) return {
23838
- code: 414,
23839
- message: "排序类型参数错误,请检查后重试!",
23840
- data: {}
23841
- };
23842
- if ("不限" !== params.time_filter && "一周内" !== params.time_filter) return {
23843
- code: 414,
23844
- message: "时间过滤参数错误,请检查后重试!",
23845
- data: {}
23846
- };
23782
+ try {
23783
+ await page.waitForSelector("#CreatorPlatform", {
23784
+ state: "visible"
23785
+ });
23786
+ } catch (error) {
23847
23787
  return {
23848
23788
  code: 414,
23849
- message: "参数缺失,请检查后重试!",
23850
- data: {}
23789
+ message: "登录失效",
23790
+ data: page.url()
23851
23791
  };
23852
23792
  }
23853
- const filterPath = "/api/sns/web/v1/search/notes";
23854
- const filterParams = {
23855
- ext_flags: [],
23856
- geo: "",
23857
- image_formats: [
23858
- "jpg",
23859
- "webp",
23860
- "avif"
23861
- ],
23862
- filters: [
23863
- {
23864
- tags: [
23865
- params.sort_type
23866
- ],
23867
- type: "sort_type"
23868
- },
23869
- {
23870
- tags: [
23871
- "不限"
23872
- ],
23873
- type: "filter_note_type"
23874
- },
23875
- {
23876
- tags: [
23877
- params.time_filter
23878
- ],
23879
- type: "filter_note_time"
23880
- },
23881
- {
23882
- tags: [
23883
- "不限"
23884
- ],
23885
- type: "filter_note_range"
23886
- },
23887
- {
23888
- tags: [
23889
- "不限"
23890
- ],
23891
- type: "filter_pos_distance"
23793
+ await page.locator("#content-area .menu-container .publish-video .btn-wrapper .btn-inner").click();
23794
+ await page.locator('.header-tabs .creator-tab:not([style*="-9999px"])').filter({
23795
+ hasText: /^上传图文$/
23796
+ }).click();
23797
+ const images = await Promise.all(params.banners.map((url)=>{
23798
+ const fileName = (0, share_namespaceObject.getFilenameFromUrl)(url);
23799
+ return (0, share_namespaceObject.downloadImage)(url, external_node_path_default().join(tmpCachePath, fileName));
23800
+ }));
23801
+ const fileChooser = await page.$("input.upload-input");
23802
+ if (fileChooser) await fileChooser.setInputFiles(images);
23803
+ const titleInstance = page.locator(".input input");
23804
+ await titleInstance.waitFor({
23805
+ state: "visible",
23806
+ timeout: 50000
23807
+ });
23808
+ await titleInstance.click();
23809
+ await titleInstance.fill(params.title);
23810
+ const descInstance = page.locator(".editor-container .tiptap.ProseMirror");
23811
+ await descInstance.click();
23812
+ await descInstance.pressSequentially(params.content.replace(/#.*?\[.*?]#/g, ""));
23813
+ if (params.topic && params.topic.length > 0) for (const it of params.topic){
23814
+ await descInstance.pressSequentially(`#${it.name}`);
23815
+ await page.locator("#creator-editor-topic-container").waitFor({
23816
+ state: "visible"
23817
+ });
23818
+ await page.waitForTimeout(500);
23819
+ await page.locator("#creator-editor-topic-container .item").first().click();
23820
+ }
23821
+ if (params.address) await selectAddress(page.locator(".address-card-wrapper .d-select-wrapper"), params.address.name);
23822
+ if (params.selfDeclaration) {
23823
+ await page.locator(".declaration-wrapper .d-select-wrapper").click();
23824
+ const poperInstance = await getPoperInstance();
23825
+ const selfDeclarationInstance = poperInstance.locator(".d-options .d-option");
23826
+ if ("fictional-rendition" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
23827
+ hasText: "虚构演绎,仅供娱乐"
23828
+ }).click();
23829
+ else if ("ai-generated" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
23830
+ hasText: "笔记含AI合成内容"
23831
+ }).click();
23832
+ else if ("source-statement" === params.selfDeclaration.type) {
23833
+ await selfDeclarationInstance.filter({
23834
+ hasText: /内容来源声明/
23835
+ }).click();
23836
+ const selfDeclarationSecondaryMenuInstance = (await getPoperInstance()).locator(".d-options .d-option");
23837
+ await selfDeclarationSecondaryMenuInstance.first().waitFor();
23838
+ if ("self-labeling" === params.selfDeclaration.childType) await selfDeclarationSecondaryMenuInstance.filter({
23839
+ hasText: "已在正文中自主标注"
23840
+ }).click();
23841
+ else if ("self-shooting" === params.selfDeclaration.childType) {
23842
+ const { shootingDate, shootingLocation } = params.selfDeclaration;
23843
+ await selfDeclarationSecondaryMenuInstance.filter({
23844
+ hasText: "自主拍摄"
23845
+ }).click();
23846
+ const selfShootingPopup = await getDialogInstance();
23847
+ const hasCustomContent = shootingDate || shootingLocation;
23848
+ if (shootingLocation) await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation.name);
23849
+ if (shootingDate) await selectDate(selfShootingPopup.locator(".date-picker input"), shootingDate);
23850
+ await selfShootingPopup.locator("footer button").filter({
23851
+ hasText: hasCustomContent ? "确认" : "取消"
23852
+ }).click();
23853
+ } else if ("transshipment" === params.selfDeclaration.childType) {
23854
+ await selfDeclarationSecondaryMenuInstance.filter({
23855
+ hasText: "来源转载"
23856
+ }).click();
23857
+ const selfShootingPopup = await getDialogInstance();
23858
+ const sourceMedia = params.selfDeclaration.sourceMedia;
23859
+ if (sourceMedia) await selfShootingPopup.locator(".el-input input").fill(sourceMedia);
23860
+ await selfShootingPopup.locator("footer button").filter({
23861
+ hasText: sourceMedia ? "确认" : "取消"
23862
+ }).click();
23892
23863
  }
23893
- ],
23894
- keyword: params.keyword,
23895
- note_type: 0,
23896
- page: params.page,
23897
- page_size: params.page_size,
23898
- search_id: createSearchId() + (params.sort_type || params.time_filter ? `@${createSearchId()}` : ""),
23899
- sort: "general"
23900
- };
23901
- const recordCookie = params.cookies.reduce((acc, cookie)=>{
23902
- if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
23903
- return acc;
23904
- }, {});
23905
- const searchXsHeader = xiaohongshuWebSearch_xsEncrypt.signHeadersPost(filterPath, recordCookie, "xhs-pc-web", filterParams);
23906
- const res = await http.api({
23907
- method: "post",
23908
- url: "https://edith.xiaohongshu.com/api/sns/web/v1/search/notes",
23909
- data: filterParams,
23910
- headers: searchXsHeader
23864
+ }
23865
+ }
23866
+ if ("private" === params.visibleRange) {
23867
+ await page.locator(".publish-page-content-setting-content .d-select-wrapper").last().click();
23868
+ const poperInstance = await getPoperInstance();
23869
+ await poperInstance.locator(".d-options .d-option").filter({
23870
+ hasText: "仅自己可见"
23871
+ }).click();
23872
+ }
23873
+ task._timerRecord.PrePublish = Date.now();
23874
+ const releaseTimeInstance = page.locator("label").filter({
23875
+ hasText: params.isImmediatelyPublish ? "立即发布" : "定时发布"
23876
+ });
23877
+ await releaseTimeInstance.click();
23878
+ if (params.scheduledPublish) await selectDate(".date-picker input", params.scheduledPublish);
23879
+ await page.waitForFunction(()=>{
23880
+ const publishBtn = Array.from(document.querySelectorAll("button")).find((b)=>b.textContent?.trim() === "发布");
23881
+ const uploading = document.querySelector(".progress-container");
23882
+ return !!publishBtn && !uploading;
23911
23883
  }, {
23912
- retries: 3,
23913
- retryDelay: 20,
23914
- timeout: 3000
23884
+ timeout: 180000,
23885
+ polling: 2000
23915
23886
  });
23916
- const isSuccess = 0 === res.code;
23917
- const message = `Web笔记搜索${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
23918
- const data = isSuccess ? res.data : {};
23919
- return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
23887
+ const response = await new Promise((resolve, reject)=>{
23888
+ const handleResponse = async (response)=>{
23889
+ if (response.url().includes("/web_api/sns/v2/note")) {
23890
+ const jsonResponse = await response.json();
23891
+ page.off("response", handleResponse);
23892
+ if (jsonResponse?.success) resolve(jsonResponse?.data?.id);
23893
+ else reject(new Error(jsonResponse?.msg || "发布失败"));
23894
+ }
23895
+ };
23896
+ page.on("response", handleResponse);
23897
+ page.locator(".publish-page-publish-btn button").filter({
23898
+ hasText: "发布"
23899
+ }).click();
23900
+ });
23901
+ await updateTaskState?.({
23902
+ state: share_namespaceObject.TaskState.SUCCESS,
23903
+ result: {
23904
+ response
23905
+ }
23906
+ });
23907
+ await page.close();
23908
+ return (0, share_namespaceObject.success)(response);
23909
+ };
23910
+ const xiaohongshuPublish_rpa_server_rpaAction_Server = async (task, params)=>{
23911
+ if (params.originalBind && params?.selfDeclaration?.type === "source-statement") return {
23912
+ code: 414,
23913
+ message: "已声明原创不可选择“来源转载”",
23914
+ data: ""
23915
+ };
23916
+ const defaultPage = task.steelBrowserContext?.pages()[0];
23917
+ if (defaultPage) {
23918
+ if (!defaultPage._routeRegistered) {
23919
+ defaultPage._routeRegistered = true;
23920
+ const blockedPatterns = [
23921
+ "**/ffmpeg-core.wasm*",
23922
+ "**/apm-fe.xiaohongshu.com*",
23923
+ "**/t2.xiaohongshu.com*",
23924
+ "**/fe-video-qc.xhscdn.com*"
23925
+ ].map((pattern)=>new RegExp(pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*")));
23926
+ await defaultPage.route("**/*", async (route)=>{
23927
+ const req = route.request();
23928
+ const url = req.url();
23929
+ const blocked = blockedPatterns.some((regex)=>regex.test(url));
23930
+ if (!blocked) return route.continue();
23931
+ if ("OPTIONS" === req.method()) {
23932
+ console.log("处理 OPTIONS 预检:", url);
23933
+ await route.fulfill({
23934
+ status: 204,
23935
+ headers: {
23936
+ "access-control-allow-origin": "*",
23937
+ "access-control-allow-methods": "GET,POST,OPTIONS,PUT,DELETE",
23938
+ "access-control-allow-headers": "*"
23939
+ },
23940
+ body: ""
23941
+ });
23942
+ return;
23943
+ }
23944
+ await route.fulfill({
23945
+ status: 204,
23946
+ body: ""
23947
+ });
23948
+ });
23949
+ }
23950
+ }
23951
+ const tmpCachePath = task.getTmpPath();
23952
+ task.logger?.info("==>进入RPA操作:任务开始,下载图片开始...");
23953
+ const updateTaskState = task.taskStageStore?.update?.bind(task.taskStageStore, task.taskId || "");
23954
+ const imagePromise = Promise.all(params.banners.map((url)=>{
23955
+ const fileName = (0, share_namespaceObject.getFilenameFromUrl)(url);
23956
+ return (0, share_namespaceObject.downloadImage)(url, external_node_path_default().join(tmpCachePath, fileName));
23957
+ }));
23958
+ let proxyUrl;
23959
+ if (params.localIP) {
23960
+ const args = [
23961
+ params.localIP,
23962
+ params.proxyLoc,
23963
+ params.accountId
23964
+ ];
23965
+ task.logger?.info(`==> 开始获取代理信息:${args}`);
23966
+ const ProxyAgentResult = await ProxyAgent({
23967
+ logger: task.logger
23968
+ }, ...args);
23969
+ task.logger?.info("==> 代理信息获取成功!");
23970
+ proxyUrl = ProxyAgentResult ? `http://${ProxyAgentResult.ip}:${ProxyAgentResult.port}` : void 0;
23971
+ }
23972
+ task.logger?.info("==>开始打开小红书页面...");
23973
+ const page = await task.createPage({
23974
+ show: task.debug,
23975
+ cookies: params.cookies,
23976
+ proxyUrl,
23977
+ url: params.url || "https://creator.xiaohongshu.com/publish/publish?source=official&from=menu&target=image",
23978
+ ...params.viewport ? {
23979
+ viewport: params.viewport
23980
+ } : {}
23981
+ });
23982
+ task.logger?.info("==>小红书页面打开成功");
23983
+ await updateTaskState?.({
23984
+ state: share_namespaceObject.TaskState.ACTION,
23985
+ connectAddress: task.steelConnector?.getProxyUrl(task.sessionId || "", "v1/sessions/debug"),
23986
+ sessionId: task.sessionId
23987
+ });
23988
+ const clickTimeout = 10000;
23989
+ const selectAddress = async (selector, address)=>{
23990
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
23991
+ await instance.click({
23992
+ timeout: clickTimeout
23993
+ });
23994
+ await instance.locator("input").fill(address);
23995
+ const poperInstance = page.locator('.d-popover:not([style*="display: none"]) .d-options .d-grid-item');
23996
+ await poperInstance.first().waitFor();
23997
+ await poperInstance.first().click({
23998
+ timeout: clickTimeout
23999
+ });
24000
+ };
24001
+ const selectDate = async (selector, date)=>{
24002
+ const instance = "string" == typeof selector ? page.locator(selector) : selector;
24003
+ await instance.click({
24004
+ timeout: clickTimeout
24005
+ });
24006
+ await instance.fill(date);
24007
+ await instance.blur();
24008
+ };
24009
+ const getPoperInstance = async ()=>{
24010
+ await page.waitForTimeout(500);
24011
+ const elements = page.locator(".d-popover");
24012
+ const count = await elements.count();
24013
+ const visibleElements = [];
24014
+ for(let i = 0; i < count; i++){
24015
+ const element = elements.nth(i);
24016
+ const style = await element.getAttribute("style");
24017
+ if (style && !style.includes("display: none")) visibleElements.push(element);
24018
+ }
24019
+ if (visibleElements.length > 0) return visibleElements[visibleElements.length - 1];
24020
+ throw new Error("未找到 popover 弹窗");
24021
+ };
24022
+ const getDialogInstance = async ()=>{
24023
+ await page.waitForTimeout(1000);
24024
+ const elements = page.locator(".el-dialog");
24025
+ return elements.last();
24026
+ };
24027
+ try {
24028
+ await page.waitForSelector("#CreatorPlatform", {
24029
+ state: "attached"
24030
+ });
24031
+ } catch (error) {
24032
+ return {
24033
+ code: 414,
24034
+ message: "登录失效",
24035
+ data: page.url()
24036
+ };
24037
+ }
24038
+ const images = await imagePromise;
24039
+ task.logger?.info(`==>图片下载完成,共 ${images.length} 张,开始上传图片...`);
24040
+ const fileChooser = await page.waitForSelector("input.upload-input", {
24041
+ timeout: 10000
24042
+ });
24043
+ if (fileChooser) await fileChooser.setInputFiles(images, {
24044
+ timeout: 60000
24045
+ }).catch((err)=>{
24046
+ task.logger?.error(`设置上传文件失败:${err.message}`);
24047
+ });
24048
+ else task.logger?.error("文件上传输入框未找到");
24049
+ task.logger?.info("==>图片上传完成,开始渲染预览图...");
24050
+ const titleInstance = page.locator(".input input");
24051
+ await titleInstance.waitFor({
24052
+ state: "attached",
24053
+ timeout: 60000
24054
+ });
24055
+ await titleInstance.click({
24056
+ timeout: 24 * clickTimeout
24057
+ });
24058
+ task.logger?.info("==> 预览图渲染成功,开始RPA操作!");
24059
+ await titleInstance.fill(params.title);
24060
+ const descInstance = page.locator(".editor-container .tiptap.ProseMirror");
24061
+ await descInstance.click({
24062
+ timeout: clickTimeout
24063
+ });
24064
+ await descInstance.fill(`${params.content.replace(/#.*?\[.*?]#/g, "")}\n`);
24065
+ await page.keyboard.press("Control+End");
24066
+ if (params.topic && params.topic.length > 0) for (const it of params.topic){
24067
+ await page.keyboard.insertText(`#${it.name}`);
24068
+ await page.locator(".ql-mention-loading").waitFor({
24069
+ state: "detached"
24070
+ });
24071
+ await page.waitForTimeout(1000);
24072
+ await page.locator("#creator-editor-topic-container .item.is-selected").click({
24073
+ timeout: clickTimeout
24074
+ });
24075
+ await page.keyboard.press("Control+End");
24076
+ }
24077
+ const container = page.locator(".plugin.editor-container");
24078
+ await container.focus();
24079
+ await page.mouse.wheel(0, 500);
24080
+ if (params.address) await selectAddress(page.locator(".media-extension .address-input").filter({
24081
+ hasText: "添加地点"
24082
+ }), params.address.name);
24083
+ if (params.collectionBind) {
24084
+ await page.locator(".media-extension .collection-container").filter({
24085
+ hasText: "添加合集"
24086
+ }).click({
24087
+ timeout: clickTimeout
24088
+ });
24089
+ const collectionName = params.collectionBind.name;
24090
+ const collectionBindInstance = await getPoperInstance();
24091
+ const collectionItemInstance = collectionBindInstance.locator(".d-grid-item .item-label", {
24092
+ hasText: collectionName
24093
+ });
24094
+ await collectionBindInstance.locator(".loading").waitFor({
24095
+ state: "detached"
24096
+ });
24097
+ await collectionItemInstance.click({
24098
+ timeout: clickTimeout
24099
+ });
24100
+ }
24101
+ if (params.groupBind) {
24102
+ await page.locator(".media-extension .address-input").filter({
24103
+ hasText: "选择群聊"
24104
+ }).click({
24105
+ timeout: clickTimeout
24106
+ });
24107
+ const groupBindName = params.groupBind.group_name;
24108
+ const groupBindInstance = await getPoperInstance();
24109
+ const groupItemInstance = groupBindInstance.locator(".d-grid-item .name", {
24110
+ hasText: groupBindName
24111
+ });
24112
+ await groupBindInstance.locator(".loading").waitFor({
24113
+ state: "detached"
24114
+ });
24115
+ await groupItemInstance.click({
24116
+ timeout: clickTimeout
24117
+ });
24118
+ }
24119
+ const OriginalBindBtn = page.locator(".btn-text.red", {
24120
+ hasText: "去声明"
24121
+ });
24122
+ const isOriginalBindBtnVisible = await OriginalBindBtn.isVisible();
24123
+ if (isOriginalBindBtnVisible && params.originalBind) {
24124
+ await OriginalBindBtn.click({
24125
+ timeout: clickTimeout
24126
+ });
24127
+ const poperInstance = await getPoperInstance();
24128
+ await poperInstance.locator(".d-checkbox-simulator").click({
24129
+ timeout: clickTimeout
24130
+ });
24131
+ await poperInstance.locator(".footer .custom-button.bg-red").click({
24132
+ timeout: clickTimeout
24133
+ });
24134
+ }
24135
+ if (params.selfDeclaration) {
24136
+ await page.locator(".media-settings .flexbox").filter({
24137
+ hasText: "内容类型声明"
24138
+ }).locator(".d-select-placeholder").click({
24139
+ timeout: clickTimeout
24140
+ });
24141
+ const poperInstance = await getPoperInstance();
24142
+ const selfDeclarationInstance = poperInstance.locator(".d-options .d-option");
24143
+ if ("fictional-rendition" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
24144
+ hasText: "虚构演绎,仅供娱乐"
24145
+ }).click({
24146
+ timeout: clickTimeout
24147
+ });
24148
+ else if ("ai-generated" === params.selfDeclaration.type) await selfDeclarationInstance.filter({
24149
+ hasText: "笔记含AI合成内容"
24150
+ }).click({
24151
+ timeout: clickTimeout
24152
+ });
24153
+ else if ("source-statement" === params.selfDeclaration.type) {
24154
+ await selfDeclarationInstance.filter({
24155
+ hasText: /内容来源声明/
24156
+ }).click({
24157
+ timeout: clickTimeout
24158
+ });
24159
+ const selfDeclarationSecondaryMenuInstance = (await getPoperInstance()).locator(".d-options .d-option");
24160
+ await selfDeclarationSecondaryMenuInstance.first().waitFor();
24161
+ if ("self-labeling" === params.selfDeclaration.childType) await selfDeclarationSecondaryMenuInstance.filter({
24162
+ hasText: "已在正文中自主标注"
24163
+ }).click({
24164
+ timeout: clickTimeout
24165
+ });
24166
+ else if ("self-shooting" === params.selfDeclaration.childType) {
24167
+ const { shootingDate, shootingLocation } = params.selfDeclaration;
24168
+ await selfDeclarationSecondaryMenuInstance.filter({
24169
+ hasText: "自主拍摄"
24170
+ }).click({
24171
+ timeout: clickTimeout
24172
+ });
24173
+ const selfShootingPopup = await getDialogInstance();
24174
+ const hasCustomContent = shootingDate || shootingLocation;
24175
+ if (shootingLocation) await selectAddress(selfShootingPopup.locator(".address-input"), shootingLocation.name);
24176
+ if (shootingDate) await selectDate(selfShootingPopup.locator(".date-picker input"), shootingDate);
24177
+ await selfShootingPopup.locator("footer button").filter({
24178
+ hasText: hasCustomContent ? "确认" : "取消"
24179
+ }).click({
24180
+ timeout: clickTimeout
24181
+ });
24182
+ } else if ("transshipment" === params.selfDeclaration.childType) {
24183
+ await selfDeclarationSecondaryMenuInstance.filter({
24184
+ hasText: "来源转载"
24185
+ }).click({
24186
+ timeout: clickTimeout
24187
+ });
24188
+ const selfShootingPopup = await getDialogInstance();
24189
+ const sourceMedia = params.selfDeclaration.sourceMedia;
24190
+ if (sourceMedia) await selfShootingPopup.locator(".el-input input").fill(sourceMedia);
24191
+ await selfShootingPopup.locator("footer button").filter({
24192
+ hasText: sourceMedia ? "确认" : "取消"
24193
+ }).click({
24194
+ timeout: clickTimeout
24195
+ });
24196
+ }
24197
+ }
24198
+ }
24199
+ if ("public" !== params.visibleRange) {
24200
+ await page.locator(".media-settings .flexbox").filter({
24201
+ hasText: "可见范围"
24202
+ }).locator(".d-select-wrapper").click({
24203
+ timeout: clickTimeout
24204
+ });
24205
+ const poperInstance = await getPoperInstance();
24206
+ const visibleText = "friends" === params.visibleRange ? "好友可见" : "仅自己可见";
24207
+ await poperInstance.locator(".d-options .custom-option").filter({
24208
+ hasText: visibleText
24209
+ }).click({
24210
+ timeout: clickTimeout
24211
+ });
24212
+ }
24213
+ async function setSwitch(page, label, target) {
24214
+ const item = page.locator(".d-new-form-item", {
24215
+ has: page.locator(".d-form-item__label", {
24216
+ hasText: label
24217
+ })
24218
+ });
24219
+ const switchUI = item.locator(".d-switch-simulator");
24220
+ const cls = await switchUI.getAttribute("class");
24221
+ const isChecked = cls?.includes("checked") || true;
24222
+ if (isChecked !== target) await switchUI.click({
24223
+ timeout: clickTimeout
24224
+ });
24225
+ }
24226
+ if (!params.coProduceBind) await setSwitch(page, "允许合拍", false);
24227
+ if (!params.noteCopyBind) await setSwitch(page, "允许正文复制", false);
24228
+ const releaseTimeInstance = page.locator("label").filter({
24229
+ hasText: params.isImmediatelyPublish ? "立即发布" : "定时发布"
24230
+ });
24231
+ await releaseTimeInstance.click({
24232
+ timeout: clickTimeout
24233
+ });
24234
+ if (params.scheduledPublish) await selectDate(".date-picker input", params.scheduledPublish);
24235
+ const imgPreviewArea = page.locator(".img-preview-area");
24236
+ try {
24237
+ await imgPreviewArea.locator(".mask.uploading").waitFor({
24238
+ state: "hidden",
24239
+ timeout: 50000
24240
+ });
24241
+ } catch (error) {
24242
+ throw new Error("上传图片超时,请重试!");
24243
+ }
24244
+ if (MockPublish) {
24245
+ const message = "文章模拟发布成功";
24246
+ const data = "123456789";
24247
+ await updateTaskState?.({
24248
+ state: share_namespaceObject.TaskState.SUCCESS,
24249
+ result: {
24250
+ response: data
24251
+ }
24252
+ });
24253
+ return (0, share_namespaceObject.success)(data, message);
24254
+ }
24255
+ const response = await new Promise((resolve)=>{
24256
+ const handleResponse = async (response)=>{
24257
+ if (response.url().includes("/web_api/sns/v2/note")) {
24258
+ const jsonResponse = await response.json();
24259
+ page.off("response", handleResponse);
24260
+ resolve(jsonResponse);
24261
+ }
24262
+ };
24263
+ page.on("response", handleResponse);
24264
+ page.locator(".submit .publishBtn").click({
24265
+ timeout: clickTimeout
24266
+ });
24267
+ page.waitForSelector(".d-toast-icon-danger", {
24268
+ state: "visible",
24269
+ timeout: 2000
24270
+ }).then(async ()=>{
24271
+ await page.waitForTimeout(300);
24272
+ const toastDesc = await page.locator(".d-toast-description").textContent();
24273
+ const desc = toastDesc?.trim();
24274
+ page.off("response", handleResponse);
24275
+ resolve({
24276
+ success: false,
24277
+ msg: desc || "未知错误"
24278
+ });
24279
+ }).catch(()=>{});
24280
+ setTimeout(()=>{
24281
+ page.off("response", handleResponse);
24282
+ resolve({
24283
+ success: false,
24284
+ msg: "发布超时"
24285
+ });
24286
+ }, 7000);
24287
+ });
24288
+ if (!response?.success) {
24289
+ const msg = `发布失败:${response?.msg || "未知错误"}`;
24290
+ await updateTaskState?.({
24291
+ state: share_namespaceObject.TaskState.FAILED,
24292
+ error: msg
24293
+ });
24294
+ await page.close();
24295
+ return {
24296
+ code: 414,
24297
+ message: msg,
24298
+ data: ""
24299
+ };
24300
+ }
24301
+ await updateTaskState?.({
24302
+ state: share_namespaceObject.TaskState.SUCCESS,
24303
+ result: {
24304
+ response: response?.data?.id || ""
24305
+ }
24306
+ });
24307
+ await page.close();
24308
+ return (0, share_namespaceObject.success)(response?.data?.id || "");
23920
24309
  };
23921
- const ttConfigDataSchema = schemas_object({
23922
- fansNum: schemas_number(),
23923
- fansNumYesterday: schemas_number().nullable(),
23924
- readNum: schemas_number(),
23925
- incomeNum: schemas_number(),
23926
- incomeNumYesterday: schemas_number().nullable(),
23927
- showNumYesterday: schemas_number().nullable(),
23928
- readNumYesterday: schemas_number().nullable(),
23929
- likeNumYesterday: schemas_number().nullable(),
23930
- commentNumYesterday: schemas_number().nullable()
23931
- });
23932
- const xhsConfigDataSchema = schemas_object({
23933
- fansNum: schemas_number(),
23934
- favedNum: schemas_number(),
23935
- watchNumLastWeek: schemas_number(),
23936
- likeNumLastWeek: schemas_number(),
23937
- collectNumLastWeek: schemas_number(),
23938
- commentNumLastWeek: schemas_number(),
23939
- fansNumLastWeek: schemas_number(),
23940
- fansNumYesterday: schemas_number()
23941
- });
23942
- const wxConfigDataSchema = schemas_object({
23943
- fansNum: schemas_number(),
23944
- fansNumYesterday: schemas_number(),
23945
- readNumYesterday: schemas_number(),
23946
- shareNumYesterday: schemas_number()
23947
- });
23948
- const bjhConfigDataSchema = schemas_object({
23949
- fansNum: schemas_number(),
23950
- fansNumYesterday: schemas_number().nullable(),
23951
- readNum: schemas_number(),
23952
- incomeNum: schemas_number(),
23953
- incomeNumYesterday: schemas_number().nullable(),
23954
- recommendNumYesterday: schemas_number().nullable(),
23955
- readNumYesterday: schemas_number().nullable(),
23956
- likeNumYesterday: schemas_number().nullable(),
23957
- commentNumYesterday: schemas_number().nullable()
23958
- });
23959
24310
  const rpa_server_mock_encode_mnsv2 = __webpack_require__("./src/utils/xhs_ob/x_s.encoder.js");
23960
24311
  function Md5(input) {
23961
24312
  return external_node_crypto_default().createHash("md5").update(input).digest("hex");
@@ -24390,6 +24741,622 @@ var __webpack_exports__ = {};
24390
24741
  });
24391
24742
  return (0, share_namespaceObject.success)(data, message);
24392
24743
  };
24744
+ const FictionalRendition = schemas_object({
24745
+ type: literal("fictional-rendition")
24746
+ });
24747
+ const AIGenerated = schemas_object({
24748
+ type: literal("ai-generated")
24749
+ });
24750
+ const SourceStatement = schemas_object({
24751
+ type: literal("source-statement"),
24752
+ childType: schemas_enum([
24753
+ "self-labeling",
24754
+ "self-shooting",
24755
+ "transshipment"
24756
+ ]),
24757
+ shootingLocation: custom().optional(),
24758
+ shootingDate: schemas_string().optional(),
24759
+ sourceMedia: schemas_string().optional()
24760
+ });
24761
+ union([
24762
+ FictionalRendition,
24763
+ AIGenerated,
24764
+ SourceStatement
24765
+ ]);
24766
+ const XiaohongshuPublishParamsSchema = ActionCommonParamsSchema.extend({
24767
+ banners: schemas_array(schemas_string()),
24768
+ title: schemas_string(),
24769
+ content: schemas_string(),
24770
+ address: custom().optional(),
24771
+ selfDeclaration: custom().optional(),
24772
+ topic: schemas_array(custom()).optional(),
24773
+ proxyLoc: schemas_string().optional(),
24774
+ localIP: schemas_string().optional(),
24775
+ huiwenToken: schemas_string().optional(),
24776
+ visibleRange: schemas_enum([
24777
+ "public",
24778
+ "private",
24779
+ "friends"
24780
+ ]),
24781
+ isImmediatelyPublish: schemas_boolean().optional(),
24782
+ scheduledPublish: schemas_string().optional(),
24783
+ collectionId: schemas_string().optional(),
24784
+ collectionBind: custom().optional(),
24785
+ groupBind: custom().optional(),
24786
+ noteCopyBind: schemas_boolean().optional(),
24787
+ coProduceBind: schemas_boolean().optional(),
24788
+ originalBind: schemas_boolean().optional()
24789
+ });
24790
+ const xiaohongshuPublish = async (task, params)=>{
24791
+ if (DisabledReq) return {
24792
+ code: 414,
24793
+ data: "",
24794
+ message: "临时维护:小红书发布政策调整,本平台小红书发布功能临时暂停服务并进行维护调整,暂时无法正常发布,敬请理解知悉。"
24795
+ };
24796
+ if ("rpa" === params.actionType) return xiaohongshuPublish_rpa_rpaAction(task, params);
24797
+ if ("mockApi" === params.actionType) return xiaohongshuPublish_mock_mockAction(task, params);
24798
+ if ("server" === params.actionType) return xiaohongshuPublish_rpa_server_rpaAction_Server(task, params);
24799
+ return executeAction(xiaohongshuPublish_mock_mockAction, rpaAction_Server_Mock, xiaohongshuPublish_rpa_server_rpaAction_Server)(task, params);
24800
+ };
24801
+ const xiaohongshuWebCommentAction_xsEncrypt = new Xhshow();
24802
+ const xiaohongshuWebCommentAction = async (_task, params)=>{
24803
+ if (DisabledReq) return (0, share_namespaceObject.response)(414, "点赞相关操作失败", {});
24804
+ const headers = {
24805
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
24806
+ referer: "https://www.xiaohongshu.com/",
24807
+ origin: "https://www.xiaohongshu.com/"
24808
+ };
24809
+ const args = [
24810
+ {
24811
+ headers
24812
+ },
24813
+ _task.logger,
24814
+ params.proxyLoc,
24815
+ params.localIP,
24816
+ params.accountId
24817
+ ];
24818
+ const http = new Http(...args);
24819
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
24820
+ if (!a1Cookie) return {
24821
+ code: 414,
24822
+ message: "账号数据异常,请重新绑定账号后重试。",
24823
+ data: []
24824
+ };
24825
+ if (!params.note_id && !params.comment_id && !params.action) return {
24826
+ code: 414,
24827
+ message: "参数缺失,请检查后重试!",
24828
+ data: {}
24829
+ };
24830
+ const actionParams = {
24831
+ note_id: params.note_id,
24832
+ comment_id: params.comment_id
24833
+ };
24834
+ let likeActionRes = {
24835
+ code: 500,
24836
+ success: false,
24837
+ msg: ""
24838
+ };
24839
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
24840
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
24841
+ return acc;
24842
+ }, {});
24843
+ switch(params.action){
24844
+ case "like":
24845
+ {
24846
+ const likeAction = "/api/sns/web/v1/comment/like";
24847
+ const likeActionXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(likeAction, recordCookie, "xhs-pc-web", actionParams);
24848
+ likeActionRes = await http.api({
24849
+ method: "post",
24850
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/like",
24851
+ data: actionParams,
24852
+ headers: likeActionXsHeader
24853
+ }, {
24854
+ retries: 3,
24855
+ retryDelay: 20,
24856
+ timeout: 3000
24857
+ });
24858
+ break;
24859
+ }
24860
+ case "dislike":
24861
+ {
24862
+ const dislikeMentions = "/api/sns/web/v1/comment/dislike";
24863
+ const dislikeXsHeader = xiaohongshuWebCommentAction_xsEncrypt.signHeadersPost(dislikeMentions, recordCookie, "xhs-pc-web", actionParams);
24864
+ likeActionRes = await http.api({
24865
+ method: "post",
24866
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/dislike",
24867
+ data: actionParams,
24868
+ headers: dislikeXsHeader
24869
+ }, {
24870
+ retries: 3,
24871
+ retryDelay: 20,
24872
+ timeout: 3000
24873
+ });
24874
+ break;
24875
+ }
24876
+ default:
24877
+ return {
24878
+ code: 414,
24879
+ message: "参数action错误,请重试!",
24880
+ data: {}
24881
+ };
24882
+ }
24883
+ const isSuccess = 0 === likeActionRes.code;
24884
+ const message = `点赞相关操作${isSuccess ? "成功" : `失败,原因:${likeActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
24885
+ const data = isSuccess ? likeActionRes.success : {};
24886
+ return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
24887
+ };
24888
+ const xiaohongshuWebIntimacySearch = async (_task, params)=>{
24889
+ if (DisabledReq) return (0, share_namespaceObject.response)(0, "搜索@列表数据成功", []);
24890
+ const headers = {
24891
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
24892
+ referer: "https://www.xiaohongshu.com/",
24893
+ origin: "https://www.xiaohongshu.com"
24894
+ };
24895
+ const args = [
24896
+ {
24897
+ headers
24898
+ },
24899
+ _task.logger,
24900
+ params.proxyLoc,
24901
+ params.localIP,
24902
+ params.accountId
24903
+ ];
24904
+ const http = new Http(...args);
24905
+ let intimacyDetail = [];
24906
+ const res = await http.api({
24907
+ method: "get",
24908
+ url: `https://edith.xiaohongshu.com/api/sns/web/v1/intimacy/intimacy_list${params.searchValue ? "/search" : ""}`,
24909
+ ...params.searchValue ? {
24910
+ params: {
24911
+ keyword: params.searchValue,
24912
+ page: 1,
24913
+ rows: 30
24914
+ }
24915
+ } : {}
24916
+ }, {
24917
+ retries: 3,
24918
+ retryDelay: 20,
24919
+ timeout: 3000
24920
+ });
24921
+ const isSuccess = 0 === res.code;
24922
+ if (isSuccess) intimacyDetail = res.data.items;
24923
+ const message = `搜索@列表数据${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
24924
+ return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, intimacyDetail);
24925
+ };
24926
+ const xiaohongshuWebMsgRead_xsEncrypt = new Xhshow();
24927
+ const xiaohongshuWebMsgRead = async (_task, params)=>{
24928
+ if (DisabledReq) return (0, share_namespaceObject.response)(414, "Read指定Tab失败", {});
24929
+ const headers = {
24930
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
24931
+ referer: "https://www.xiaohongshu.com/",
24932
+ origin: "https://www.xiaohongshu.com/"
24933
+ };
24934
+ const args = [
24935
+ {
24936
+ headers
24937
+ },
24938
+ _task.logger,
24939
+ params.proxyLoc,
24940
+ params.localIP,
24941
+ params.accountId
24942
+ ];
24943
+ const http = new Http(...args);
24944
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
24945
+ if (!a1Cookie) return {
24946
+ code: 414,
24947
+ message: "账号数据异常,请重新绑定账号后重试。",
24948
+ data: []
24949
+ };
24950
+ if (!params.type) return {
24951
+ code: 414,
24952
+ message: "参数缺失,请检查后重试!",
24953
+ data: {}
24954
+ };
24955
+ const replyParams = {
24956
+ type: params.type
24957
+ };
24958
+ const fatchMentions = "/api/sns/web/v1/message/read";
24959
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
24960
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
24961
+ return acc;
24962
+ }, {});
24963
+ const fatchMentionsXsHeader = xiaohongshuWebMsgRead_xsEncrypt.signHeadersPost(fatchMentions, recordCookie, "xhs-pc-web", replyParams);
24964
+ const res = await http.api({
24965
+ method: "post",
24966
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/message/read",
24967
+ data: replyParams,
24968
+ headers: fatchMentionsXsHeader
24969
+ }, {
24970
+ retries: 3,
24971
+ retryDelay: 20,
24972
+ timeout: 3000
24973
+ });
24974
+ const isSuccess = 0 === res.code;
24975
+ const message = `Read指定Tab${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
24976
+ const data = isSuccess ? res.success : {};
24977
+ return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
24978
+ };
24979
+ const xiaohongshuWebMsgReply_xsEncrypt = new Xhshow();
24980
+ const xiaohongshuWebMsgReply = async (_task, params)=>{
24981
+ if (DisabledReq) return (0, share_namespaceObject.response)(414, "评论回复失败", {});
24982
+ const headers = {
24983
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
24984
+ referer: "https://www.xiaohongshu.com/",
24985
+ origin: "https://www.xiaohongshu.com/"
24986
+ };
24987
+ const args = [
24988
+ {
24989
+ headers
24990
+ },
24991
+ _task.logger,
24992
+ params.proxyLoc,
24993
+ params.localIP,
24994
+ params.accountId
24995
+ ];
24996
+ const http = new Http(...args);
24997
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
24998
+ if (!a1Cookie) return {
24999
+ code: 414,
25000
+ message: "账号数据异常,请重新绑定账号后重试。",
25001
+ data: []
25002
+ };
25003
+ if (!params.note_id || !params.target_comment_id || !params.content) return {
25004
+ code: 414,
25005
+ message: "参数缺失,请检查后重试!",
25006
+ data: {}
25007
+ };
25008
+ const replyParams = {
25009
+ at_users: params.at_users ?? [],
25010
+ content: params.content,
25011
+ note_id: params.note_id,
25012
+ target_comment_id: params.target_comment_id
25013
+ };
25014
+ const replyPath = "/api/sns/web/v1/comment/post";
25015
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
25016
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
25017
+ return acc;
25018
+ }, {});
25019
+ const replyXsHeader = xiaohongshuWebMsgReply_xsEncrypt.signHeadersPost(replyPath, recordCookie, "xhs-pc-web", replyParams);
25020
+ const res = await http.api({
25021
+ method: "post",
25022
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/comment/post",
25023
+ data: replyParams,
25024
+ headers: replyXsHeader
25025
+ }, {
25026
+ retries: 3,
25027
+ retryDelay: 20,
25028
+ timeout: 3000
25029
+ });
25030
+ const isSuccess = 0 === res.code;
25031
+ const message = `评论回复${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
25032
+ const data = isSuccess ? res.data : {};
25033
+ return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
25034
+ };
25035
+ const xiaohongshuWebNoteFeed_xsEncrypt = new xhs_ob_feed_Xhshow();
25036
+ const GenXSCommon = __webpack_require__("./src/utils/XhsXsCommonEnc.js");
25037
+ const xiaohongshuWebNoteFeed = async (_task, params)=>{
25038
+ if (DisabledReq) return (0, share_namespaceObject.response)(414, "获取指定文章详情失败", {});
25039
+ const headers = {
25040
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
25041
+ referer: "https://www.xiaohongshu.com/",
25042
+ origin: "https://www.xiaohongshu.com/"
25043
+ };
25044
+ const args = [
25045
+ {
25046
+ headers
25047
+ },
25048
+ _task.logger,
25049
+ params.proxyLoc,
25050
+ params.localIP,
25051
+ params.accountId
25052
+ ];
25053
+ const http = new Http(...args);
25054
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
25055
+ if (!a1Cookie) return {
25056
+ code: 414,
25057
+ message: "账号数据异常,请重新绑定账号后重试。",
25058
+ data: {}
25059
+ };
25060
+ if (!params.source_note_id && !params.xsec_token) return {
25061
+ code: 414,
25062
+ message: "参数缺失,请检查后重试!",
25063
+ data: {}
25064
+ };
25065
+ const feedParams = {
25066
+ source_note_id: params.source_note_id,
25067
+ image_formats: [
25068
+ "jpg",
25069
+ "webp",
25070
+ "avif"
25071
+ ],
25072
+ extra: {
25073
+ need_body_topic: "1"
25074
+ },
25075
+ xsec_source: "pc_feed",
25076
+ xsec_token: params.xsec_token
25077
+ };
25078
+ const fatchFeed = "/api/sns/web/v1/feed";
25079
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
25080
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
25081
+ return acc;
25082
+ }, {});
25083
+ const xsHeader = xiaohongshuWebNoteFeed_xsEncrypt.signHeadersPost(fatchFeed, recordCookie, "xhs-pc-web", feedParams);
25084
+ const xT = Date.now().toString();
25085
+ const xsCommon = GenXSCommon(a1Cookie, xT, xsHeader["X-S"]);
25086
+ _task.logger.info(`请求参数: ${JSON.stringify(feedParams)}`);
25087
+ _task.logger.info(`X-S: ${xsHeader["X-S"]}`);
25088
+ _task.logger.info(`x-s-common: ${xsCommon}`);
25089
+ const res = await http.api({
25090
+ method: "post",
25091
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/feed",
25092
+ data: feedParams,
25093
+ headers: {
25094
+ "X-S": xsHeader["X-S"],
25095
+ "X-S-Common": xsCommon,
25096
+ "X-T": xT
25097
+ }
25098
+ }, {
25099
+ retries: 3,
25100
+ retryDelay: 20,
25101
+ timeout: 3000
25102
+ });
25103
+ _task.logger.info(`API 响应: ${JSON.stringify(res)}`);
25104
+ const isSuccess = 0 === res.code && res.data && res.data.items && res.data.items.length > 0;
25105
+ const message = `获取指定文章详情${isSuccess ? "成功" : `失败,原因:${res.msg || "返回数据为空,可能笔记不存在或参数错误"}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
25106
+ const data = isSuccess ? res.data?.items[0].note_card || {} : {};
25107
+ return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
25108
+ };
25109
+ const xiaohongshuWebRelationAction_xsEncrypt = new Xhshow();
25110
+ const xiaohongshuWebRelationAction = async (_task, params)=>{
25111
+ if (DisabledReq) return (0, share_namespaceObject.response)(414, "用户关系操作失败", {});
25112
+ const headers = {
25113
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
25114
+ referer: "https://www.xiaohongshu.com/",
25115
+ origin: "https://www.xiaohongshu.com/"
25116
+ };
25117
+ const args = [
25118
+ {
25119
+ headers
25120
+ },
25121
+ _task.logger,
25122
+ params.proxyLoc,
25123
+ params.localIP,
25124
+ params.accountId
25125
+ ];
25126
+ const http = new Http(...args);
25127
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
25128
+ if (!a1Cookie) return {
25129
+ code: 414,
25130
+ message: "账号数据异常,请重新绑定账号后重试。",
25131
+ data: {}
25132
+ };
25133
+ if (!params.action || !params.target_user_id) return {
25134
+ code: 414,
25135
+ message: "参数缺失,请检查后重试!",
25136
+ data: {}
25137
+ };
25138
+ const relationParams = {
25139
+ target_user_id: params.target_user_id
25140
+ };
25141
+ let relationActionRes;
25142
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
25143
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
25144
+ return acc;
25145
+ }, {});
25146
+ switch(params.action){
25147
+ case "follow":
25148
+ {
25149
+ const followMentions = "/api/sns/web/v1/user/follow";
25150
+ const followXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(followMentions, recordCookie, "xhs-pc-web", relationParams);
25151
+ relationActionRes = await http.api({
25152
+ method: "post",
25153
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/follow",
25154
+ data: relationParams,
25155
+ headers: followXsHeader
25156
+ }, {
25157
+ retries: 3,
25158
+ retryDelay: 500,
25159
+ timeout: 3000
25160
+ });
25161
+ break;
25162
+ }
25163
+ case "unfollow":
25164
+ {
25165
+ const unfllowMentions = "/api/sns/web/v1/user/unfollow";
25166
+ const unfllowXsHeader = xiaohongshuWebRelationAction_xsEncrypt.signHeadersPost(unfllowMentions, recordCookie, "xhs-pc-web", relationParams);
25167
+ relationActionRes = await http.api({
25168
+ method: "post",
25169
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/user/unfollow",
25170
+ data: relationParams,
25171
+ headers: unfllowXsHeader
25172
+ }, {
25173
+ retries: 3,
25174
+ retryDelay: 20,
25175
+ timeout: 3000
25176
+ });
25177
+ break;
25178
+ }
25179
+ default:
25180
+ return {
25181
+ code: 414,
25182
+ message: "参数action错误,请重试!",
25183
+ data: {}
25184
+ };
25185
+ }
25186
+ const isSuccess = 0 === relationActionRes.code;
25187
+ const message = `用户关系操作${isSuccess ? "成功" : `失败,原因:${relationActionRes.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
25188
+ const data = isSuccess ? relationActionRes.data : {
25189
+ fstatus: null
25190
+ };
25191
+ return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
25192
+ };
25193
+ const xiaohongshuWebSearch_xsEncrypt = new Xhshow();
25194
+ const XhsWebSearchParamsSchema = ActionCommonParamsSchema.extend({
25195
+ keyword: schemas_string(),
25196
+ page: schemas_number(),
25197
+ page_size: schemas_number(),
25198
+ sort_type: schemas_enum([
25199
+ "general",
25200
+ "time_descending",
25201
+ "popular_descending"
25202
+ ]),
25203
+ time_filter: schemas_enum([
25204
+ "不限",
25205
+ "一周内"
25206
+ ])
25207
+ });
25208
+ const createSearchId = ()=>{
25209
+ let r = BigInt(Date.now());
25210
+ const o = BigInt(Math.ceil(0x7ffffffe * Math.random()));
25211
+ r <<= BigInt(64);
25212
+ r += o;
25213
+ return r.toString(36);
25214
+ };
25215
+ const xiaohongshuWebSearch = async (_task, params)=>{
25216
+ const headers = {
25217
+ cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
25218
+ referer: "https://www.xiaohongshu.com/",
25219
+ origin: "https://www.xiaohongshu.com/"
25220
+ };
25221
+ const args = [
25222
+ {
25223
+ headers
25224
+ },
25225
+ _task.logger,
25226
+ params.proxyLoc,
25227
+ params.localIP,
25228
+ params.accountId
25229
+ ];
25230
+ const http = new Http(...args);
25231
+ const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
25232
+ if (!a1Cookie) return {
25233
+ code: 414,
25234
+ message: "账号数据异常,请重新绑定账号后重试。",
25235
+ data: {}
25236
+ };
25237
+ if (!params.keyword || !params.page || !params.page_size || !params.sort_type || !params.time_filter) {
25238
+ if ("general" !== params.sort_type && "time_descending" !== params.sort_type && "popular_descending" !== params.sort_type) return {
25239
+ code: 414,
25240
+ message: "排序类型参数错误,请检查后重试!",
25241
+ data: {}
25242
+ };
25243
+ if ("不限" !== params.time_filter && "一周内" !== params.time_filter) return {
25244
+ code: 414,
25245
+ message: "时间过滤参数错误,请检查后重试!",
25246
+ data: {}
25247
+ };
25248
+ return {
25249
+ code: 414,
25250
+ message: "参数缺失,请检查后重试!",
25251
+ data: {}
25252
+ };
25253
+ }
25254
+ const filterPath = "/api/sns/web/v1/search/notes";
25255
+ const filterParams = {
25256
+ ext_flags: [],
25257
+ geo: "",
25258
+ image_formats: [
25259
+ "jpg",
25260
+ "webp",
25261
+ "avif"
25262
+ ],
25263
+ filters: [
25264
+ {
25265
+ tags: [
25266
+ params.sort_type
25267
+ ],
25268
+ type: "sort_type"
25269
+ },
25270
+ {
25271
+ tags: [
25272
+ "不限"
25273
+ ],
25274
+ type: "filter_note_type"
25275
+ },
25276
+ {
25277
+ tags: [
25278
+ params.time_filter
25279
+ ],
25280
+ type: "filter_note_time"
25281
+ },
25282
+ {
25283
+ tags: [
25284
+ "不限"
25285
+ ],
25286
+ type: "filter_note_range"
25287
+ },
25288
+ {
25289
+ tags: [
25290
+ "不限"
25291
+ ],
25292
+ type: "filter_pos_distance"
25293
+ }
25294
+ ],
25295
+ keyword: params.keyword,
25296
+ note_type: 0,
25297
+ page: params.page,
25298
+ page_size: params.page_size,
25299
+ search_id: createSearchId() + (params.sort_type || params.time_filter ? `@${createSearchId()}` : ""),
25300
+ sort: "general"
25301
+ };
25302
+ const recordCookie = params.cookies.reduce((acc, cookie)=>{
25303
+ if (cookie.name && cookie.value) acc[cookie.name] = cookie.value;
25304
+ return acc;
25305
+ }, {});
25306
+ const searchXsHeader = xiaohongshuWebSearch_xsEncrypt.signHeadersPost(filterPath, recordCookie, "xhs-pc-web", filterParams);
25307
+ const res = await http.api({
25308
+ method: "post",
25309
+ url: "https://edith.xiaohongshu.com/api/sns/web/v1/search/notes",
25310
+ data: filterParams,
25311
+ headers: searchXsHeader
25312
+ }, {
25313
+ retries: 3,
25314
+ retryDelay: 20,
25315
+ timeout: 3000
25316
+ });
25317
+ const isSuccess = 0 === res.code;
25318
+ const message = `Web笔记搜索${isSuccess ? "成功" : `失败,原因:${res.msg}`}${_task.debug ? ` ${http.proxyInfo}` : ""}`;
25319
+ const data = isSuccess ? res.data : {};
25320
+ return (0, share_namespaceObject.response)(isSuccess ? 0 : 414, message, data);
25321
+ };
25322
+ const ttConfigDataSchema = schemas_object({
25323
+ fansNum: schemas_number(),
25324
+ fansNumYesterday: schemas_number().nullable(),
25325
+ readNum: schemas_number(),
25326
+ incomeNum: schemas_number(),
25327
+ incomeNumYesterday: schemas_number().nullable(),
25328
+ showNumYesterday: schemas_number().nullable(),
25329
+ readNumYesterday: schemas_number().nullable(),
25330
+ likeNumYesterday: schemas_number().nullable(),
25331
+ commentNumYesterday: schemas_number().nullable()
25332
+ });
25333
+ const xhsConfigDataSchema = schemas_object({
25334
+ fansNum: schemas_number(),
25335
+ favedNum: schemas_number(),
25336
+ watchNumLastWeek: schemas_number(),
25337
+ likeNumLastWeek: schemas_number(),
25338
+ collectNumLastWeek: schemas_number(),
25339
+ commentNumLastWeek: schemas_number(),
25340
+ fansNumLastWeek: schemas_number(),
25341
+ fansNumYesterday: schemas_number()
25342
+ });
25343
+ const wxConfigDataSchema = schemas_object({
25344
+ fansNum: schemas_number(),
25345
+ fansNumYesterday: schemas_number(),
25346
+ readNumYesterday: schemas_number(),
25347
+ shareNumYesterday: schemas_number()
25348
+ });
25349
+ const bjhConfigDataSchema = schemas_object({
25350
+ fansNum: schemas_number(),
25351
+ fansNumYesterday: schemas_number().nullable(),
25352
+ readNum: schemas_number(),
25353
+ incomeNum: schemas_number(),
25354
+ incomeNumYesterday: schemas_number().nullable(),
25355
+ recommendNumYesterday: schemas_number().nullable(),
25356
+ readNumYesterday: schemas_number().nullable(),
25357
+ likeNumYesterday: schemas_number().nullable(),
25358
+ commentNumYesterday: schemas_number().nullable()
25359
+ });
24393
25360
  const BetaFlag = "HuiwenCanary";
24394
25361
  class Action {
24395
25362
  constructor(task){