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