@ikenxuan/amagi 4.5.1 → 4.5.2

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.
@@ -27,7 +27,7 @@ var express__default = /*#__PURE__*/_interopDefault(express);
27
27
  * GPL-3.0 Licensed
28
28
  */
29
29
 
30
- // node_modules/.pnpm/tsup@8.5.0_@swc+core@1.12.9_tsx@4.20.3_typescript@5.8.3/node_modules/tsup/assets/cjs_shims.js
30
+ // node_modules/.pnpm/tsup@8.5.0_@swc+core@1.12.11_tsx@4.20.3_typescript@5.8.3/node_modules/tsup/assets/cjs_shims.js
31
31
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
32
32
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
33
33
  var getPackageLogsPath = () => {
@@ -353,7 +353,20 @@ var BiLiBiLiAPI = class {
353
353
  }
354
354
  /** 评论区类型,type参数详见 [评论区类型代码](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/comment/readme.md#评论区类型代码) */
355
355
  \u8BC4\u8BBA\u533A\u660E\u7EC6(data2) {
356
- return `https://api.bilibili.com/x/v2/reply?sort=1&ps=${data2.number ?? 20}&type=${data2.type}&oid=${data2.oid}&pn=${data2.pn}`;
356
+ const params = new URLSearchParams({
357
+ oid: data2.oid.toString(),
358
+ type: data2.type.toString(),
359
+ mode: (data2.mode ?? 3).toString(),
360
+ plat: "1",
361
+ seek_rpid: "",
362
+ web_location: "1315875"
363
+ });
364
+ if (data2.pagination_str) {
365
+ params.append("pagination_str", JSON.stringify({ offset: data2.pagination_str }));
366
+ } else {
367
+ params.append("pagination_str", JSON.stringify({ offset: "" }));
368
+ }
369
+ return `https://api.bilibili.com/x/v2/reply/wbi/main?${params.toString()}`;
357
370
  }
358
371
  \u8BC4\u8BBA\u533A\u72B6\u6001(data2) {
359
372
  return `https://api.bilibili.com/x/v2/reply/subject/description?type=${data2.type}&oid=${data2.oid}`;
@@ -409,6 +422,112 @@ var kuaishouAPIErrorCode = /* @__PURE__ */ ((kuaishouAPIErrorCode2) => {
409
422
  kuaishouAPIErrorCode2["UNKNOWN"] = "UNKNOWN_ERROR" /* UNKNOWN */;
410
423
  return kuaishouAPIErrorCode2;
411
424
  })(kuaishouAPIErrorCode || {});
425
+ var mixinKeyEncTab = [
426
+ 46,
427
+ 47,
428
+ 18,
429
+ 2,
430
+ 53,
431
+ 8,
432
+ 23,
433
+ 32,
434
+ 15,
435
+ 50,
436
+ 10,
437
+ 31,
438
+ 58,
439
+ 3,
440
+ 45,
441
+ 35,
442
+ 27,
443
+ 43,
444
+ 5,
445
+ 49,
446
+ 33,
447
+ 9,
448
+ 42,
449
+ 19,
450
+ 29,
451
+ 28,
452
+ 14,
453
+ 39,
454
+ 12,
455
+ 38,
456
+ 41,
457
+ 13,
458
+ 37,
459
+ 48,
460
+ 7,
461
+ 16,
462
+ 24,
463
+ 55,
464
+ 40,
465
+ 61,
466
+ 26,
467
+ 17,
468
+ 0,
469
+ 1,
470
+ 60,
471
+ 51,
472
+ 30,
473
+ 4,
474
+ 22,
475
+ 25,
476
+ 54,
477
+ 21,
478
+ 56,
479
+ 59,
480
+ 6,
481
+ 63,
482
+ 57,
483
+ 62,
484
+ 11,
485
+ 36,
486
+ 20,
487
+ 34,
488
+ 44,
489
+ 52
490
+ ];
491
+ var getMixinKey = (orig) => mixinKeyEncTab.map((n) => orig[n]).join("").slice(0, 32);
492
+ var encWbi = (params, img_key, sub_key) => {
493
+ const mixin_key = getMixinKey(img_key + sub_key);
494
+ const curr_time = Math.round(Date.now() / 1e3);
495
+ const chr_filter = /[!'()*]/g;
496
+ Object.assign(params, { wts: curr_time });
497
+ const query = Object.keys(params).sort().map((key) => {
498
+ const value = params[key].toString().replace(chr_filter, "");
499
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
500
+ }).join("&");
501
+ const wbi_sign2 = crypto__default.default.createHash("md5").update(query + mixin_key).digest("hex");
502
+ return `&wts=${curr_time}&w_rid=${wbi_sign2}`;
503
+ };
504
+ var getWbiKeys = async (cookie) => {
505
+ const res = await axios__default.default("https://api.bilibili.com/x/web-interface/nav", {
506
+ headers: {
507
+ Cookie: cookie
508
+ }
509
+ });
510
+ const response = res.data;
511
+ const {
512
+ data: {
513
+ wbi_img: { img_url, sub_url }
514
+ }
515
+ } = response;
516
+ return {
517
+ img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
518
+ sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
519
+ };
520
+ };
521
+ var wbi_sign = async (BASEURL, cookie) => {
522
+ const web_keys = await getWbiKeys(cookie);
523
+ const url = new URL(BASEURL);
524
+ const params = {};
525
+ for (const [key, value] of url.searchParams.entries()) {
526
+ params[key] = value;
527
+ }
528
+ const query = encWbi(params, web_keys.img_key, web_keys.sub_key);
529
+ return query;
530
+ };
412
531
 
413
532
  // src/platform/bilibili/getdata.ts
414
533
  var defheaders = {
@@ -427,6 +546,7 @@ var defheaders = {
427
546
  referer: "https://www.bilibili.com/"
428
547
  };
429
548
  var fetchBilibili = async (data2, cookie) => {
549
+ var _a, _b, _c;
430
550
  const headers2 = {
431
551
  ...defheaders,
432
552
  cookie: cookie ? cookie.replace(/\s+/g, "") : ""
@@ -450,67 +570,65 @@ var fetchBilibili = async (data2, cookie) => {
450
570
  return DATA;
451
571
  }
452
572
  case "\u8BC4\u8BBA\u6570\u636E": {
453
- let { oid, number, pn, type } = data2;
573
+ let { oid, number, type, mode, pagination_str, plat, seek_rpid, web_location } = data2;
454
574
  let fetchedComments = [];
455
- pn = pn ?? 1;
456
575
  const maxRequestCount = 100;
457
- const commentGrowthStabilized = 5;
458
- let lastFetchedCount = 0;
459
- let stabilizedCount = 0;
460
576
  let requestCount = 0;
461
577
  let tmpresp;
462
- while (fetchedComments.length < Number(number ?? 20) && requestCount < maxRequestCount) {
463
- if (number === 0 || number === void 0) {
464
- requestCount = 0;
465
- } else {
466
- requestCount = Math.min(20, Number(number) - fetchedComments.length);
467
- }
468
- const url = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u660E\u7EC6({
578
+ let nextPaginationStr = pagination_str;
579
+ let isEnd = false;
580
+ const checkStatusUrl = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u72B6\u6001({ oid, type });
581
+ const checkStatusRes = await GlobalGetData({
582
+ url: checkStatusUrl,
583
+ headers: headers2,
584
+ ...data2
585
+ });
586
+ if (checkStatusRes.data === null) {
587
+ logger.error("\u8BC4\u8BBA\u533A\u672A\u5F00\u653E");
588
+ return {
589
+ code: 404,
590
+ message: "\u8BC4\u8BBA\u533A\u672A\u5F00\u653E",
591
+ data: null
592
+ };
593
+ }
594
+ while (fetchedComments.length < Number(number ?? 20) && requestCount < maxRequestCount && !isEnd) {
595
+ const baseUrl = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u660E\u7EC6({
469
596
  type,
470
597
  oid,
471
- number: requestCount,
472
- pn
473
- });
474
- const checkStatusUrl = bilibiliApiUrls.\u8BC4\u8BBA\u533A\u72B6\u6001({ oid, type });
475
- const checkStatusRes = await GlobalGetData({
476
- url: checkStatusUrl,
477
- headers: headers2,
478
- ...data2
598
+ mode: mode ?? 3,
599
+ pagination_str: nextPaginationStr,
600
+ plat: plat ?? 1,
601
+ seek_rpid,
602
+ web_location: web_location ?? "1315875"
479
603
  });
480
- if (checkStatusRes.data === null) {
481
- logger.error("\u8BC4\u8BBA\u533A\u672A\u5F00\u653E");
482
- return {
483
- code: 404,
484
- message: "\u8BC4\u8BBA\u533A\u672A\u5F00\u653E",
485
- data: null
486
- };
487
- }
604
+ const wbiSignQuery = await wbi_sign(baseUrl, headers2.cookie);
605
+ const finalUrl = baseUrl + wbiSignQuery;
488
606
  const response = await GlobalGetData({
489
- url,
607
+ url: finalUrl,
490
608
  headers: headers2,
491
609
  ...data2
492
610
  });
493
611
  tmpresp = response;
494
- const currentCount = response.data.replies ? response.data.replies.length : 0;
495
- fetchedComments.push(...response.data.replies || []);
496
- if (currentCount === lastFetchedCount) {
497
- stabilizedCount++;
612
+ const currentComments = ((_a = response.data) == null ? void 0 : _a.replies) || [];
613
+ fetchedComments.push(...currentComments);
614
+ if ((_b = response.data) == null ? void 0 : _b.cursor) {
615
+ nextPaginationStr = (_c = response.data.cursor.pagination_reply) == null ? void 0 : _c.next_offset;
616
+ isEnd = response.data.cursor.is_end;
498
617
  } else {
499
- stabilizedCount = 0;
618
+ isEnd = true;
500
619
  }
501
- lastFetchedCount = currentCount;
502
- if (stabilizedCount >= commentGrowthStabilized || requestCount >= maxRequestCount) {
620
+ requestCount++;
621
+ if (isEnd || currentComments.length === 0 || !nextPaginationStr) {
622
+ logger.info("\u5DF2\u5230\u8FBE\u8BC4\u8BBA\u672B\u5C3E\u6216\u65E0\u66F4\u591A\u8BC4\u8BBA");
503
623
  break;
504
624
  }
505
- pn++;
506
- requestCount++;
507
625
  }
508
626
  const finalResponse = {
509
627
  ...tmpresp,
510
628
  data: {
511
629
  ...tmpresp.data,
512
- // 去重
513
- replies: Array.from(new Map(fetchedComments.map((item) => [item.rpid, item])).values()).slice(0, Number(data2.number))
630
+ // 去重并限制数量
631
+ replies: Array.from(new Map(fetchedComments.map((item) => [item.rpid, item])).values()).slice(0, Number(data2.number || 20))
514
632
  }
515
633
  };
516
634
  return finalResponse;
@@ -767,112 +885,6 @@ var bilibiliErrorCodeMap = {
767
885
  "-799": "\u8BF7\u6C42\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",
768
886
  "-8888": "\u5BF9\u4E0D\u8D77\uFF0C\u670D\u52A1\u5668\u5F00\u5C0F\u5DEE\u4E86~ (\u0CA5\uFE4F\u0CA5)"
769
887
  };
770
- var mixinKeyEncTab = [
771
- 46,
772
- 47,
773
- 18,
774
- 2,
775
- 53,
776
- 8,
777
- 23,
778
- 32,
779
- 15,
780
- 50,
781
- 10,
782
- 31,
783
- 58,
784
- 3,
785
- 45,
786
- 35,
787
- 27,
788
- 43,
789
- 5,
790
- 49,
791
- 33,
792
- 9,
793
- 42,
794
- 19,
795
- 29,
796
- 28,
797
- 14,
798
- 39,
799
- 12,
800
- 38,
801
- 41,
802
- 13,
803
- 37,
804
- 48,
805
- 7,
806
- 16,
807
- 24,
808
- 55,
809
- 40,
810
- 61,
811
- 26,
812
- 17,
813
- 0,
814
- 1,
815
- 60,
816
- 51,
817
- 30,
818
- 4,
819
- 22,
820
- 25,
821
- 54,
822
- 21,
823
- 56,
824
- 59,
825
- 6,
826
- 63,
827
- 57,
828
- 62,
829
- 11,
830
- 36,
831
- 20,
832
- 34,
833
- 44,
834
- 52
835
- ];
836
- var getMixinKey = (orig) => mixinKeyEncTab.map((n) => orig[n]).join("").slice(0, 32);
837
- var encWbi = (params, img_key, sub_key) => {
838
- const mixin_key = getMixinKey(img_key + sub_key);
839
- const curr_time = Math.round(Date.now() / 1e3);
840
- const chr_filter = /[!'()*]/g;
841
- Object.assign(params, { wts: curr_time });
842
- const query = Object.keys(params).sort().map((key) => {
843
- const value = params[key].toString().replace(chr_filter, "");
844
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
845
- }).join("&");
846
- const wbi_sign2 = crypto__default.default.createHash("md5").update(query + mixin_key).digest("hex");
847
- return `&wts=${curr_time}&w_rid=${wbi_sign2}`;
848
- };
849
- var getWbiKeys = async (cookie) => {
850
- const res = await axios__default.default("https://api.bilibili.com/x/web-interface/nav", {
851
- headers: {
852
- Cookie: cookie
853
- }
854
- });
855
- const response = res.data;
856
- const {
857
- data: {
858
- wbi_img: { img_url, sub_url }
859
- }
860
- } = response;
861
- return {
862
- img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
863
- sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
864
- };
865
- };
866
- var wbi_sign = async (BASEURL, cookie) => {
867
- const web_keys = await getWbiKeys(cookie);
868
- const url = new URL(BASEURL);
869
- const params = {};
870
- for (const [key, value] of url.searchParams.entries()) {
871
- params[key] = value;
872
- }
873
- const query = encWbi(params, web_keys.img_key, web_keys.sub_key);
874
- return query;
875
- };
876
888
 
877
889
  // src/platform/douyin/sign/a_bogus.ts
878
890
  var SM3 = class {
@@ -1859,7 +1871,7 @@ var BilibiliVideoDownloadParamsSchema = zod.z.object({
1859
1871
  });
1860
1872
  var BilibiliCommentParamsSchema = zod.z.object({
1861
1873
  methodType: zod.z.literal("\u8BC4\u8BBA\u6570\u636E"),
1862
- oid: smartNumber("OID\u4E0D\u80FD\u4E3A\u7A7A", 1, true),
1874
+ oid: zod.z.string({ required_error: "OID\u4E0D\u80FD\u4E3A\u7A7A" }).min(1, "OID\u4E0D\u80FD\u4E3A\u7A7A"),
1863
1875
  type: smartNumber("\u8BC4\u8BBA\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A", 1, true).refine(
1864
1876
  (val) => [1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 33].includes(val),
1865
1877
  { message: "\u65E0\u6548\u7684\u8BC4\u8BBA\u533A\u7C7B\u578B" }