@ikenxuan/amagi 4.4.15 → 4.4.17

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 我是真爱粉 🧩
6
6
 
7
- "amagi" /ˈæmədʒi/ 名称灵感来源于网络流行的"你干嘛~哎呦~"视频,这是由歌手 cxk 的一段采访视频衍生而来的网络文化现象。这个梗在抖音和 bilibili [BV1St41137jm](https://www.bilibili.com/video/BV1St41137jm) 上广泛传播,成为了中国互联网文化的一部分。选择这个名称也象征着本项目与这些平台内容的紧密联系。🎤💃
7
+ "amagi" /ˈæmədʒi/ 名称灵感来源于网络谐音梗,在网络上 [BV1St41137jm](https://www.bilibili.com/video/BV1St41137jm) 上广泛传播。🎤💃
8
8
 
9
9
  此生必看 [BV1DL411X7jE](https://www.bilibili.com/video/BV1DL411X7jE)
10
10
 
@@ -16,53 +16,54 @@ amagi 将作为一个独立的上游模块,提供给下游 [karin-plugin-kkk](
16
16
 
17
17
  当然,如果你的下游有新的业务需求,欢迎提 issue 或 pr。(其实作者本人很菜,issue 不一定能解决)
18
18
 
19
- ## 安装 📦
19
+ ## 安装/更新 📦
20
20
 
21
21
  ```bash
22
22
  pnpm add @ikenxuan/amagi@latest
23
23
  ```
24
24
 
25
- ## 默认导出使用方法 🚀
25
+ ## 快速开始 🚀
26
26
 
27
27
  ### 基本用法 ✨
28
+ 主要就两个方法,`getDouyinData` 和 `getBilibiliData`。
29
+ 它接收三个参数,第一个参数是 API 名称,第二个参数是 API 所需的参数,第三个参数是用户的 cookies。
30
+ 若通过构造器创建实例,就不需要传入 cookies 参数了。
28
31
 
29
32
  ```javascript
30
33
  import Client from '@ikenxuan/amagi'
34
+ // or
35
+ // import { getDouyinData, getBilibiliData } from '@ikenxuan/amagi'
31
36
 
32
- // 创建客户端实例
33
- const amagi = new Client({
34
- douyin: '', // 抖音 cookie(可选)
35
- bilibili: '', // B站 cookie(可选)
36
- })
37
+ // you can use it as a class/function/object
38
+ const amagi = Client({...options})
39
+ const amagi = new Client({...options})
37
40
 
38
41
  // 使用示例
39
42
  async function example() {
40
43
  // 获取抖音搜索数据
41
- const searchData = await amagi.getDouyinData('搜索数据', {
42
- query: '热门视频',
43
- number: 10,
44
- })
44
+ const searchData = await amagi.getDouyinData(
45
+ '搜索数据',
46
+ { ...opt }
47
+ )
45
48
 
46
49
  // 获取B站视频数据
47
- const videoData = await amagi.getBilibiliData('单个视频作品数据', {
48
- bvid: 'BV1fK4y1q79u',
49
- })
50
+ const videoData = await amagi.getBilibiliData(
51
+ '单个视频作品数据',
52
+ { ...opt }
53
+ )
50
54
 
51
55
  console.log(searchData)
52
56
  }
53
57
 
54
58
  example()
55
59
  ```
56
-
60
+ ## Advanced
57
61
  ### 启动本地 HTTP 服务 🌐
58
62
 
59
63
  ```javascript
60
64
  import Client from '@ikenxuan/amagi'
61
65
 
62
- const amagi = new Client({
63
- douyin: '你的抖音cookie',
64
- bilibili: '你的B站cookie',
65
- })
66
+ const amagi = new Client({...options})
66
67
 
67
68
  // 启动本地服务,默认端口 4567
68
69
  const app = amagi.startClient()
@@ -95,24 +96,20 @@ const abSign = douyinUtils.sign.AB('需要签名的地址')
95
96
 
96
97
  // 使用 API 接口
97
98
  const videoData = await douyinUtils.api.getWorkInfo(
98
- {
99
- aweme_id: '视频ID',
100
- },
101
- '有效的用户 Cookie'
99
+ { ...opt },
100
+ 'cookies'
102
101
  )
103
102
 
104
103
  const userInfo = await douyinUtils.api.getUserProfile(
105
- {
106
- sec_uid: '用户ID',
107
- },
108
- '有效的用户 Cookie'
104
+ { ...opt },
105
+ 'cookies'
109
106
  )
110
107
 
111
108
  // 直接获取数据
112
- const searchResult = await douyinUtils.getDouyinData('搜索数据', {
113
- query: '搜索关键词',
114
- number: 10,
115
- })
109
+ const searchResult = await douyinUtils.getDouyinData(
110
+ '搜索数据',
111
+ { ...opt }
112
+ )
116
113
  ```
117
114
 
118
115
  主要功能:
@@ -133,20 +130,16 @@ bilibili 相关功能模块提供了获取 bilibili 平台数据的工具和 API
133
130
  import { bilibiliUtils } from '@ikenxuan/amagi'
134
131
 
135
132
  // 获取视频信息
136
- const videoInfo = await bilibiliUtils.api.getVideoInfo({
137
- bvid: 'BV1fK4y1q79u',
138
- })
133
+ const videoInfo = await bilibiliUtils.api.getVideoInfo({ ...opt })
139
134
 
140
135
  // 获取评论数据
141
- const comments = await bilibiliUtils.api.getComments({
142
- oid: 111111, // 稿件ID,也就是AV号去除前缀后的内容
143
- type: 1,
144
- })
136
+ const comments = await bilibiliUtils.api.getComments({ ...opt })
145
137
 
146
138
  // 直接获取数据
147
- const userInfo = await bilibiliUtils.getBilibiliData('用户主页数据', {
148
- host_mid: 1340190821, // 用户ID
149
- })
139
+ const userInfo = await bilibiliUtils.getBilibiliData(
140
+ '用户主页数据',
141
+ { ...opt }
142
+ )
150
143
  ```
151
144
 
152
145
  主要功能:
@@ -474,7 +474,7 @@ var registerBilibiliRoutes = (cookie) => {
474
474
  }, req.headers.cookie || cookie);
475
475
  res.json(data2);
476
476
  });
477
- router.get("/fetch_work_comments", async (req, res) => {
477
+ router.get("/fetch_emoji_list", async (req, res) => {
478
478
  const data2 = await fetchBilibili({
479
479
  methodType: "Emoji\u6570\u636E"
480
480
  }, req.headers.cookie || cookie);
@@ -547,7 +547,7 @@ var registerBilibiliRoutes = (cookie) => {
547
547
  router.get("/av_to_bv", async (req, res) => {
548
548
  const data2 = await fetchBilibili({
549
549
  methodType: "AV\u8F6CBV",
550
- avid: parseInt(req.query.avid)
550
+ avid: req.query.avid
551
551
  }, req.headers.cookie || cookie);
552
552
  res.json(data2);
553
553
  });
@@ -835,44 +835,66 @@ var fetchBilibili = async (data2, cookie) => {
835
835
  }
836
836
  };
837
837
  var GlobalGetData = async (options) => {
838
+ let warningMessage = "";
838
839
  try {
839
840
  const result = await new Networks(options).getData();
840
- if (result && result.code === 0) {
841
- return result;
842
- } else if (result.code === 12061) {
843
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01
844
- \u8BF7\u6C42\u63A5\u53E3\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
845
- \u8BF7\u6C42URL\uFF1A${options.url}
846
- \u9519\u8BEF\u4EE3\u7801\uFF1A${result.code}\uFF0C
847
- \u542B\u4E49\uFF1A${result.message}`;
841
+ if (!result || result === "") {
842
+ const Err = {
843
+ errorDescription: "\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684B\u7AD9ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01",
844
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
845
+ requestUrl: options.url
846
+ };
847
+ warningMessage = `
848
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684B\u7AD9ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
849
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
850
+ \u8BF7\u6C42URL\uFF1A${options.url}
851
+ `;
848
852
  logger.warn(warningMessage);
849
853
  throw {
850
- ...result,
851
- warning: warningMessage
854
+ code: "-352" /* RISK_CONTROL_FAILED */,
855
+ data: result,
856
+ amagiError: Err
852
857
  };
853
- } else {
854
- const errorMessage = errorMap[result.code] || result.message || "\u672A\u77E5\u9519\u8BEF";
855
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01
856
- \u8BF7\u6C42\u63A5\u53E3\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
857
- \u8BF7\u6C42URL\uFF1A${options.url}
858
- \u9519\u8BEF\u4EE3\u7801\uFF1A${result.code}\uFF0C
859
- \u542B\u4E49\uFF1A${errorMessage}`;
858
+ }
859
+ if (result.code !== 0) {
860
+ const errorMessage = bilibiliErrorCodeMap[result.code] || result.message || "\u672A\u77E5\u9519\u8BEF";
861
+ const Err = {
862
+ errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${errorMessage}\uFF01`,
863
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
864
+ requestUrl: options.url
865
+ };
866
+ warningMessage = `
867
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow(errorMessage)}
868
+ \u9519\u8BEF\u4EE3\u7801\uFF1A${result.code}
869
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
870
+ \u8BF7\u6C42URL\uFF1A${options.url}
871
+ `;
860
872
  logger.warn(warningMessage);
861
873
  throw {
862
- ...result,
863
- warning: warningMessage
874
+ code: result.code,
875
+ data: result,
876
+ amagiError: Err
864
877
  };
865
878
  }
879
+ return result;
866
880
  } catch (error) {
867
881
  if (error && typeof error === "object") {
868
- return {
869
- ...error,
870
- warning: error.warning || "\u672A\u77E5\u9519\u8BEF"
871
- };
882
+ const err = error;
883
+ return { ...err, amagiMessage: warningMessage };
872
884
  }
885
+ return {
886
+ code: "UNKNOWN_ERROR" /* UNKNOWN */,
887
+ data: error.data,
888
+ amagiError: {
889
+ errorDescription: "\u672A\u77E5\u9519\u8BEF",
890
+ requestType: options.methodType,
891
+ requestUrl: options.url
892
+ },
893
+ amagiMessage: warningMessage
894
+ };
873
895
  }
874
896
  };
875
- var errorMap = {
897
+ var bilibiliErrorCodeMap = {
876
898
  "-1": "\u5E94\u7528\u7A0B\u5E8F\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5C01\u7981",
877
899
  "-2": "Access Key \u9519\u8BEF",
878
900
  "-3": "API \u6821\u9A8C\u5BC6\u5319\u9519\u8BEF",
@@ -1660,7 +1682,7 @@ var douyinUtils = {
1660
1682
  var defheaders2 = {
1661
1683
  accept: "*/*",
1662
1684
  priority: "u=0, i",
1663
- "content-type": "application/json",
1685
+ "content-type": "application/json; charset=utf-8",
1664
1686
  "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
1665
1687
  "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
1666
1688
  referer: "https://www.douyin.com/",
@@ -1668,6 +1690,7 @@ var defheaders2 = {
1668
1690
  connection: "keep-alive"
1669
1691
  };
1670
1692
  var DouyinData = async (data2, cookie) => {
1693
+ var _a, _b;
1671
1694
  const headers2 = {
1672
1695
  ...defheaders2,
1673
1696
  cookie: cookie ? cookie.replace(/\s+/g, "") : ""
@@ -1814,15 +1837,29 @@ var DouyinData = async (data2, cookie) => {
1814
1837
  case "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E": {
1815
1838
  DouyinValidateData(data2, ["sec_uid"]);
1816
1839
  let url = douyinApiUrls.\u7528\u6237\u4E3B\u9875\u4FE1\u606F({ sec_uid: data2.sec_uid });
1840
+ const fetchUrl = `${url}&a_bogus=${douyinSign.AB(url)}`;
1817
1841
  const UserInfoData = await GlobalGetData2({
1818
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1842
+ url: fetchUrl,
1819
1843
  headers: {
1820
1844
  ...headers2,
1821
1845
  Referer: `https://www.douyin.com/user/${data2.sec_uid}`
1822
1846
  },
1823
1847
  ...data2
1824
1848
  });
1825
- if (UserInfoData.user.live_status !== 1) logger.error(UserInfoData.user.nickname + "\u672A\u5F00\u542F\u76F4\u64AD\uFF01");
1849
+ if (!((_a = UserInfoData == null ? void 0 : UserInfoData.user) == null ? void 0 : _a.live_status) || UserInfoData.user.live_status !== 1) {
1850
+ logger.error((((_b = UserInfoData == null ? void 0 : UserInfoData.user) == null ? void 0 : _b.nickname) || "\u7528\u6237") + "\u5F53\u524D\u672A\u5728\u76F4\u64AD");
1851
+ const Err = {
1852
+ errorDescription: "\u68C0\u67E5\u5931\u8D25\uFF01\u8BE5\u7528\u6237\u5F53\u524D\u672A\u5728\u76F4\u64AD\uFF01 TypeError: Cannot read properties of undefined (reading 'live_status')",
1853
+ requestType: data2.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1854
+ requestUrl: fetchUrl
1855
+ };
1856
+ return {
1857
+ code: "USER_NOT_LIVE" /* NOT_LIVE */,
1858
+ data: UserInfoData,
1859
+ amagiError: Err,
1860
+ amagiMessage: Err.errorDescription
1861
+ };
1862
+ }
1826
1863
  if (!UserInfoData.user.room_data) {
1827
1864
  logger.error("\u672A\u83B7\u53D6\u5230\u76F4\u64AD\u95F4\u4FE1\u606F\uFF01");
1828
1865
  return {
@@ -1889,29 +1926,62 @@ var fetchPaginatedData = async (apiUrlGenerator, params, maxPageSize, headers2)
1889
1926
  return finalResponse;
1890
1927
  };
1891
1928
  async function GlobalGetData2(options) {
1929
+ let warningMessage = "";
1892
1930
  try {
1893
1931
  const result = await new Networks(options).getData();
1894
- if (result === "" || !result) {
1895
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A
1896
- \u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01
1897
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1898
- \u8BF7\u6C42URL\uFF1A ${options.url}`;
1932
+ if (!result || result === "") {
1933
+ const Err = {
1934
+ errorDescription: "\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01",
1935
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1936
+ requestUrl: options.url
1937
+ };
1938
+ warningMessage = `
1939
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
1940
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1941
+ \u8BF7\u6C42URL\uFF1A${options.url}
1942
+ `;
1943
+ logger.warn(warningMessage);
1944
+ throw {
1945
+ code: "INVALID_COOKIE" /* COOKIE */,
1946
+ data: result,
1947
+ amagiError: Err
1948
+ };
1949
+ }
1950
+ if (result.filter_detail && result.filter_detail.filter_reason) {
1951
+ const filterReason = result.filter_detail.filter_reason;
1952
+ const Err = {
1953
+ errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${filterReason}\uFF01`,
1954
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1955
+ requestUrl: options.url
1956
+ };
1957
+ warningMessage = `
1958
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow(filterReason)}
1959
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1960
+ \u8BF7\u6C42URL\uFF1A${options.url}
1961
+ `;
1899
1962
  logger.warn(warningMessage);
1900
1963
  throw {
1901
- ...result,
1902
- code: result.status_code,
1903
- warning: warningMessage
1964
+ code: "CONTENT_FILTERED" /* FILTER */,
1965
+ data: result,
1966
+ amagiError: Err
1904
1967
  };
1905
1968
  }
1906
1969
  return result;
1907
1970
  } catch (error) {
1908
1971
  if (error && typeof error === "object") {
1909
- return {
1910
- ...error,
1911
- code: error.status_code || 500,
1912
- warning: error.warning || "\u672A\u77E5\u9519\u8BEF"
1913
- };
1972
+ const err = error;
1973
+ return { ...err, amagiMessage: warningMessage };
1914
1974
  }
1975
+ return {
1976
+ code: "UNKNOWN_ERROR" /* UNKNOWN */,
1977
+ data: null,
1978
+ amagiError: {
1979
+ errorDescription: "\u672A\u77E5\u9519\u8BEF",
1980
+ requestType: options.methodType,
1981
+ requestUrl: options.url
1982
+ },
1983
+ amagiMessage: warningMessage
1984
+ };
1915
1985
  }
1916
1986
  }
1917
1987
 
@@ -2087,31 +2157,45 @@ var KuaishouData = async (data2, cookie) => {
2087
2157
  }
2088
2158
  };
2089
2159
  async function GlobalGetData3(options) {
2160
+ let warningMessage = "";
2090
2161
  try {
2091
2162
  const result = await new Networks(options).getData();
2092
2163
  if (result === "" || !result || result.result === 2) {
2093
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A
2094
- \u4F60\u7684\u5FEB\u624Bck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01
2095
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
2096
- \u8BF7\u6C42URL\uFF1A${options.url}
2097
- \u8BF7\u6C42\u53C2\u6570\uFF1A${JSON.stringify(options.body, null, 2)}`;
2164
+ const Err = {
2165
+ errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF01`,
2166
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
2167
+ requestUrl: options.url,
2168
+ requestBody: JSON.stringify(options.body)
2169
+ };
2170
+ warningMessage = `
2171
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u5FEB\u624Bck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
2172
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
2173
+ \u8BF7\u6C42URL\uFF1A${options.url}
2174
+ \u8BF7\u6C42\u53C2\u6570\uFF1A${JSON.stringify(options.body, null, 2)}
2175
+ `;
2098
2176
  logger.warn(warningMessage);
2099
2177
  throw {
2100
- ...result,
2101
- code: result.result,
2102
- warning: warningMessage
2178
+ code: "INVALID_COOKIE" /* COOKIE */,
2179
+ data: result,
2180
+ amagiError: Err
2103
2181
  };
2104
2182
  }
2105
2183
  return result;
2106
2184
  } catch (error) {
2107
2185
  if (error && typeof error === "object") {
2108
- return {
2109
- ...error,
2110
- code: error.result || 500,
2111
- message: error.error_msg,
2112
- warning: error.warning || "\u672A\u77E5\u9519\u8BEF"
2113
- };
2186
+ const err = error;
2187
+ return { ...err, amagiMessage: warningMessage };
2114
2188
  }
2189
+ return {
2190
+ code: "UNKNOWN_ERROR" /* UNKNOWN */,
2191
+ data: null,
2192
+ amagiError: {
2193
+ errorDescription: "\u672A\u77E5\u9519\u8BEF",
2194
+ requestType: options.methodType,
2195
+ requestUrl: options.url
2196
+ },
2197
+ amagiMessage: warningMessage
2198
+ };
2115
2199
  }
2116
2200
  }
2117
2201
 
@@ -2498,17 +2582,13 @@ function createAmagiClient(options = {}) {
2498
2582
  }
2499
2583
  return new amagiClient(options);
2500
2584
  }
2501
- var CreateApp = Object.assign(
2502
- createAmagiClient,
2503
- {
2504
- /** 抖音相关功能模块 (工具集) */
2505
- douyin: douyinUtils,
2506
- /** B站相关功能模块 (工具集) */
2507
- bilibili: bilibiliUtils,
2508
- /** 快手相关功能模块 (工具集) */
2509
- kuaishou: kuaishouUtils
2510
- }
2511
- );
2585
+ createAmagiClient.douyin = douyinUtils;
2586
+ createAmagiClient.bilibili = bilibiliUtils;
2587
+ createAmagiClient.kuaishou = kuaishouUtils;
2588
+ createAmagiClient.getDouyinData = () => douyinUtils.getDouyinData;
2589
+ createAmagiClient.getBilibiliData = () => bilibiliUtils.getBilibiliData;
2590
+ createAmagiClient.getKuaishouData = () => kuaishouUtils.getKuaishouData;
2591
+ var CreateApp = createAmagiClient;
2512
2592
  var Client = CreateApp;
2513
2593
  var amagi = Client;
2514
2594
 
@@ -2524,6 +2604,7 @@ exports.av2bv = av2bv;
2524
2604
  exports.bilibili = bilibili;
2525
2605
  exports.bilibiliAPI = bilibiliAPI;
2526
2606
  exports.bilibiliApiUrls = bilibiliApiUrls;
2607
+ exports.bilibiliErrorCodeMap = bilibiliErrorCodeMap;
2527
2608
  exports.bilibiliUtils = bilibiliUtils;
2528
2609
  exports.bv2av = bv2av;
2529
2610
  exports.default = Client;
@@ -462,7 +462,7 @@ var registerBilibiliRoutes = (cookie) => {
462
462
  }, req.headers.cookie || cookie);
463
463
  res.json(data2);
464
464
  });
465
- router.get("/fetch_work_comments", async (req, res) => {
465
+ router.get("/fetch_emoji_list", async (req, res) => {
466
466
  const data2 = await fetchBilibili({
467
467
  methodType: "Emoji\u6570\u636E"
468
468
  }, req.headers.cookie || cookie);
@@ -535,7 +535,7 @@ var registerBilibiliRoutes = (cookie) => {
535
535
  router.get("/av_to_bv", async (req, res) => {
536
536
  const data2 = await fetchBilibili({
537
537
  methodType: "AV\u8F6CBV",
538
- avid: parseInt(req.query.avid)
538
+ avid: req.query.avid
539
539
  }, req.headers.cookie || cookie);
540
540
  res.json(data2);
541
541
  });
@@ -823,44 +823,66 @@ var fetchBilibili = async (data2, cookie) => {
823
823
  }
824
824
  };
825
825
  var GlobalGetData = async (options) => {
826
+ let warningMessage = "";
826
827
  try {
827
828
  const result = await new Networks(options).getData();
828
- if (result && result.code === 0) {
829
- return result;
830
- } else if (result.code === 12061) {
831
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01
832
- \u8BF7\u6C42\u63A5\u53E3\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
833
- \u8BF7\u6C42URL\uFF1A${options.url}
834
- \u9519\u8BEF\u4EE3\u7801\uFF1A${result.code}\uFF0C
835
- \u542B\u4E49\uFF1A${result.message}`;
829
+ if (!result || result === "") {
830
+ const Err = {
831
+ errorDescription: "\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684B\u7AD9ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01",
832
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
833
+ requestUrl: options.url
834
+ };
835
+ warningMessage = `
836
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684B\u7AD9ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
837
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
838
+ \u8BF7\u6C42URL\uFF1A${options.url}
839
+ `;
836
840
  logger.warn(warningMessage);
837
841
  throw {
838
- ...result,
839
- warning: warningMessage
842
+ code: "-352" /* RISK_CONTROL_FAILED */,
843
+ data: result,
844
+ amagiError: Err
840
845
  };
841
- } else {
842
- const errorMessage = errorMap[result.code] || result.message || "\u672A\u77E5\u9519\u8BEF";
843
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01
844
- \u8BF7\u6C42\u63A5\u53E3\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
845
- \u8BF7\u6C42URL\uFF1A${options.url}
846
- \u9519\u8BEF\u4EE3\u7801\uFF1A${result.code}\uFF0C
847
- \u542B\u4E49\uFF1A${errorMessage}`;
846
+ }
847
+ if (result.code !== 0) {
848
+ const errorMessage = bilibiliErrorCodeMap[result.code] || result.message || "\u672A\u77E5\u9519\u8BEF";
849
+ const Err = {
850
+ errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${errorMessage}\uFF01`,
851
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
852
+ requestUrl: options.url
853
+ };
854
+ warningMessage = `
855
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow(errorMessage)}
856
+ \u9519\u8BEF\u4EE3\u7801\uFF1A${result.code}
857
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
858
+ \u8BF7\u6C42URL\uFF1A${options.url}
859
+ `;
848
860
  logger.warn(warningMessage);
849
861
  throw {
850
- ...result,
851
- warning: warningMessage
862
+ code: result.code,
863
+ data: result,
864
+ amagiError: Err
852
865
  };
853
866
  }
867
+ return result;
854
868
  } catch (error) {
855
869
  if (error && typeof error === "object") {
856
- return {
857
- ...error,
858
- warning: error.warning || "\u672A\u77E5\u9519\u8BEF"
859
- };
870
+ const err = error;
871
+ return { ...err, amagiMessage: warningMessage };
860
872
  }
873
+ return {
874
+ code: "UNKNOWN_ERROR" /* UNKNOWN */,
875
+ data: error.data,
876
+ amagiError: {
877
+ errorDescription: "\u672A\u77E5\u9519\u8BEF",
878
+ requestType: options.methodType,
879
+ requestUrl: options.url
880
+ },
881
+ amagiMessage: warningMessage
882
+ };
861
883
  }
862
884
  };
863
- var errorMap = {
885
+ var bilibiliErrorCodeMap = {
864
886
  "-1": "\u5E94\u7528\u7A0B\u5E8F\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5C01\u7981",
865
887
  "-2": "Access Key \u9519\u8BEF",
866
888
  "-3": "API \u6821\u9A8C\u5BC6\u5319\u9519\u8BEF",
@@ -1648,7 +1670,7 @@ var douyinUtils = {
1648
1670
  var defheaders2 = {
1649
1671
  accept: "*/*",
1650
1672
  priority: "u=0, i",
1651
- "content-type": "application/json",
1673
+ "content-type": "application/json; charset=utf-8",
1652
1674
  "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
1653
1675
  "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
1654
1676
  referer: "https://www.douyin.com/",
@@ -1656,6 +1678,7 @@ var defheaders2 = {
1656
1678
  connection: "keep-alive"
1657
1679
  };
1658
1680
  var DouyinData = async (data2, cookie) => {
1681
+ var _a, _b;
1659
1682
  const headers2 = {
1660
1683
  ...defheaders2,
1661
1684
  cookie: cookie ? cookie.replace(/\s+/g, "") : ""
@@ -1802,15 +1825,29 @@ var DouyinData = async (data2, cookie) => {
1802
1825
  case "\u76F4\u64AD\u95F4\u4FE1\u606F\u6570\u636E": {
1803
1826
  DouyinValidateData(data2, ["sec_uid"]);
1804
1827
  let url = douyinApiUrls.\u7528\u6237\u4E3B\u9875\u4FE1\u606F({ sec_uid: data2.sec_uid });
1828
+ const fetchUrl = `${url}&a_bogus=${douyinSign.AB(url)}`;
1805
1829
  const UserInfoData = await GlobalGetData2({
1806
- url: `${url}&a_bogus=${douyinSign.AB(url)}`,
1830
+ url: fetchUrl,
1807
1831
  headers: {
1808
1832
  ...headers2,
1809
1833
  Referer: `https://www.douyin.com/user/${data2.sec_uid}`
1810
1834
  },
1811
1835
  ...data2
1812
1836
  });
1813
- if (UserInfoData.user.live_status !== 1) logger.error(UserInfoData.user.nickname + "\u672A\u5F00\u542F\u76F4\u64AD\uFF01");
1837
+ if (!((_a = UserInfoData == null ? void 0 : UserInfoData.user) == null ? void 0 : _a.live_status) || UserInfoData.user.live_status !== 1) {
1838
+ logger.error((((_b = UserInfoData == null ? void 0 : UserInfoData.user) == null ? void 0 : _b.nickname) || "\u7528\u6237") + "\u5F53\u524D\u672A\u5728\u76F4\u64AD");
1839
+ const Err = {
1840
+ errorDescription: "\u68C0\u67E5\u5931\u8D25\uFF01\u8BE5\u7528\u6237\u5F53\u524D\u672A\u5728\u76F4\u64AD\uFF01 TypeError: Cannot read properties of undefined (reading 'live_status')",
1841
+ requestType: data2.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1842
+ requestUrl: fetchUrl
1843
+ };
1844
+ return {
1845
+ code: "USER_NOT_LIVE" /* NOT_LIVE */,
1846
+ data: UserInfoData,
1847
+ amagiError: Err,
1848
+ amagiMessage: Err.errorDescription
1849
+ };
1850
+ }
1814
1851
  if (!UserInfoData.user.room_data) {
1815
1852
  logger.error("\u672A\u83B7\u53D6\u5230\u76F4\u64AD\u95F4\u4FE1\u606F\uFF01");
1816
1853
  return {
@@ -1877,29 +1914,62 @@ var fetchPaginatedData = async (apiUrlGenerator, params, maxPageSize, headers2)
1877
1914
  return finalResponse;
1878
1915
  };
1879
1916
  async function GlobalGetData2(options) {
1917
+ let warningMessage = "";
1880
1918
  try {
1881
1919
  const result = await new Networks(options).getData();
1882
- if (result === "" || !result) {
1883
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A
1884
- \u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01
1885
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1886
- \u8BF7\u6C42URL\uFF1A ${options.url}`;
1920
+ if (!result || result === "") {
1921
+ const Err = {
1922
+ errorDescription: "\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01",
1923
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1924
+ requestUrl: options.url
1925
+ };
1926
+ warningMessage = `
1927
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u6296\u97F3ck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
1928
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1929
+ \u8BF7\u6C42URL\uFF1A${options.url}
1930
+ `;
1931
+ logger.warn(warningMessage);
1932
+ throw {
1933
+ code: "INVALID_COOKIE" /* COOKIE */,
1934
+ data: result,
1935
+ amagiError: Err
1936
+ };
1937
+ }
1938
+ if (result.filter_detail && result.filter_detail.filter_reason) {
1939
+ const filterReason = result.filter_detail.filter_reason;
1940
+ const Err = {
1941
+ errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${filterReason}\uFF01`,
1942
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
1943
+ requestUrl: options.url
1944
+ };
1945
+ warningMessage = `
1946
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow(filterReason)}
1947
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
1948
+ \u8BF7\u6C42URL\uFF1A${options.url}
1949
+ `;
1887
1950
  logger.warn(warningMessage);
1888
1951
  throw {
1889
- ...result,
1890
- code: result.status_code,
1891
- warning: warningMessage
1952
+ code: "CONTENT_FILTERED" /* FILTER */,
1953
+ data: result,
1954
+ amagiError: Err
1892
1955
  };
1893
1956
  }
1894
1957
  return result;
1895
1958
  } catch (error) {
1896
1959
  if (error && typeof error === "object") {
1897
- return {
1898
- ...error,
1899
- code: error.status_code || 500,
1900
- warning: error.warning || "\u672A\u77E5\u9519\u8BEF"
1901
- };
1960
+ const err = error;
1961
+ return { ...err, amagiMessage: warningMessage };
1902
1962
  }
1963
+ return {
1964
+ code: "UNKNOWN_ERROR" /* UNKNOWN */,
1965
+ data: null,
1966
+ amagiError: {
1967
+ errorDescription: "\u672A\u77E5\u9519\u8BEF",
1968
+ requestType: options.methodType,
1969
+ requestUrl: options.url
1970
+ },
1971
+ amagiMessage: warningMessage
1972
+ };
1903
1973
  }
1904
1974
  }
1905
1975
 
@@ -2075,31 +2145,45 @@ var KuaishouData = async (data2, cookie) => {
2075
2145
  }
2076
2146
  };
2077
2147
  async function GlobalGetData3(options) {
2148
+ let warningMessage = "";
2078
2149
  try {
2079
2150
  const result = await new Networks(options).getData();
2080
2151
  if (result === "" || !result || result.result === 2) {
2081
- const warningMessage = `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A
2082
- \u4F60\u7684\u5FEB\u624Bck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01
2083
- \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
2084
- \u8BF7\u6C42URL\uFF1A${options.url}
2085
- \u8BF7\u6C42\u53C2\u6570\uFF1A${JSON.stringify(options.body, null, 2)}`;
2152
+ const Err = {
2153
+ errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF01`,
2154
+ requestType: options.methodType ?? "\u672A\u77E5\u8BF7\u6C42\u7C7B\u578B",
2155
+ requestUrl: options.url,
2156
+ requestBody: JSON.stringify(options.body)
2157
+ };
2158
+ warningMessage = `
2159
+ \u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${logger.yellow("\u63A5\u53E3\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u4F60\u7684\u5FEB\u624Bck\u53EF\u80FD\u5DF2\u7ECF\u5931\u6548\uFF01")}
2160
+ \u8BF7\u6C42\u7C7B\u578B\uFF1A\u300C${options.methodType}\u300D
2161
+ \u8BF7\u6C42URL\uFF1A${options.url}
2162
+ \u8BF7\u6C42\u53C2\u6570\uFF1A${JSON.stringify(options.body, null, 2)}
2163
+ `;
2086
2164
  logger.warn(warningMessage);
2087
2165
  throw {
2088
- ...result,
2089
- code: result.result,
2090
- warning: warningMessage
2166
+ code: "INVALID_COOKIE" /* COOKIE */,
2167
+ data: result,
2168
+ amagiError: Err
2091
2169
  };
2092
2170
  }
2093
2171
  return result;
2094
2172
  } catch (error) {
2095
2173
  if (error && typeof error === "object") {
2096
- return {
2097
- ...error,
2098
- code: error.result || 500,
2099
- message: error.error_msg,
2100
- warning: error.warning || "\u672A\u77E5\u9519\u8BEF"
2101
- };
2174
+ const err = error;
2175
+ return { ...err, amagiMessage: warningMessage };
2102
2176
  }
2177
+ return {
2178
+ code: "UNKNOWN_ERROR" /* UNKNOWN */,
2179
+ data: null,
2180
+ amagiError: {
2181
+ errorDescription: "\u672A\u77E5\u9519\u8BEF",
2182
+ requestType: options.methodType,
2183
+ requestUrl: options.url
2184
+ },
2185
+ amagiMessage: warningMessage
2186
+ };
2103
2187
  }
2104
2188
  }
2105
2189
 
@@ -2486,18 +2570,14 @@ function createAmagiClient(options = {}) {
2486
2570
  }
2487
2571
  return new amagiClient(options);
2488
2572
  }
2489
- var CreateApp = Object.assign(
2490
- createAmagiClient,
2491
- {
2492
- /** 抖音相关功能模块 (工具集) */
2493
- douyin: douyinUtils,
2494
- /** B站相关功能模块 (工具集) */
2495
- bilibili: bilibiliUtils,
2496
- /** 快手相关功能模块 (工具集) */
2497
- kuaishou: kuaishouUtils
2498
- }
2499
- );
2573
+ createAmagiClient.douyin = douyinUtils;
2574
+ createAmagiClient.bilibili = bilibiliUtils;
2575
+ createAmagiClient.kuaishou = kuaishouUtils;
2576
+ createAmagiClient.getDouyinData = () => douyinUtils.getDouyinData;
2577
+ createAmagiClient.getBilibiliData = () => bilibiliUtils.getBilibiliData;
2578
+ createAmagiClient.getKuaishouData = () => kuaishouUtils.getKuaishouData;
2579
+ var CreateApp = createAmagiClient;
2500
2580
  var Client = CreateApp;
2501
2581
  var amagi = Client;
2502
2582
 
2503
- export { BilibiliValidateData, CreateApp, DouyinValidateData, KuaishouAPI, KusiahouValidateData, Networks, amagi, amagiClient, av2bv, bilibili, bilibiliAPI, bilibiliApiUrls, bilibiliUtils, bv2av, Client as default, douyin, douyinAPI, douyinApiUrls, douyinSign, douyinUtils, fetchBilibiliData, fetchDouyinData, fetchKuaishouData, getBilibiliData, getDouyinData, getKuaishouData, kuaishou, kuaishouAPI, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, qtparam, registerBilibiliRoutes, registerDouyinRoutes, registerKuaishouRoutes, wbi_sign };
2583
+ export { BilibiliValidateData, CreateApp, DouyinValidateData, KuaishouAPI, KusiahouValidateData, Networks, amagi, amagiClient, av2bv, bilibili, bilibiliAPI, bilibiliApiUrls, bilibiliErrorCodeMap, bilibiliUtils, bv2av, Client as default, douyin, douyinAPI, douyinApiUrls, douyinSign, douyinUtils, fetchBilibiliData, fetchDouyinData, fetchKuaishouData, getBilibiliData, getDouyinData, getKuaishouData, kuaishou, kuaishouAPI, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, qtparam, registerBilibiliRoutes, registerDouyinRoutes, registerKuaishouRoutes, wbi_sign };
@@ -387,6 +387,147 @@ type NetworksConfigType = {
387
387
  */
388
388
  methodType?: string;
389
389
  };
390
+ /** API标准化HTTP请求错误类型 */
391
+ type ErrorDetail = {
392
+ /**
393
+ * 错误描述信息
394
+ */
395
+ errorDescription: string;
396
+ /**
397
+ * 请求类型
398
+ */
399
+ requestType: string;
400
+ /**
401
+ * 请求URL地址
402
+ */
403
+ requestUrl: string;
404
+ };
405
+ /** 未知错误 */
406
+ declare enum amagiAPIErrorCode {
407
+ /** 未知错误 */
408
+ UNKNOWN = "UNKNOWN_ERROR"
409
+ }
410
+ /** 抖音平台API错误码 */
411
+ declare enum douoyinAPIErrorCode {
412
+ /** Cookie无效或已过期 */
413
+ COOKIE = "INVALID_COOKIE",
414
+ /** 内容被隐藏或下架 */
415
+ FILTER = "CONTENT_FILTERED",
416
+ /** 当前用户未开播 */
417
+ NOT_LIVE = "USER_NOT_LIVE",
418
+ /** 未知错误 */
419
+ UNKNOWN = "UNKNOWN_ERROR"
420
+ }
421
+ /** B站平台API错误码 */
422
+ declare enum bilibiliAPIErrorCode {
423
+ /** 应用程序不存在或已被封禁 */
424
+ APP_NOT_FOUND = "-1",
425
+ /** Access Key 错误 */
426
+ ACCESS_KEY_ERROR = "-2",
427
+ /** API 校验密匙错误 */
428
+ API_KEY_ERROR = "-3",
429
+ /** 调用方对该Method没有权限 */
430
+ METHOD_NOT_PERMITTED = "-4",
431
+ /** 账号未登录 */
432
+ NOT_LOGGED_IN = "-101",
433
+ /** 账号被封停 */
434
+ ACCOUNT_BANNED = "-102",
435
+ /** 积分不足 */
436
+ POINTS_INSUFFICIENT = "-103",
437
+ /** 硬币不足 */
438
+ COINS_INSUFFICIENT = "-104",
439
+ /** 验证码错误 */
440
+ CAPTCHA_ERROR = "-105",
441
+ /** 账号非正式会员或在适应期 */
442
+ MEMBERSHIP_LIMITED = "-106",
443
+ /** 应用不存在或者被封禁 */
444
+ APP_BANNED = "-107",
445
+ /** 未绑定手机 */
446
+ PHONE_NOT_BOUND = "-108",
447
+ /** 未绑定手机 */
448
+ PHONE_NOT_BOUND_2 = "-110",
449
+ /** csrf 校验失败 */
450
+ CSRF_ERROR = "-111",
451
+ /** 系统升级中 */
452
+ SYSTEM_UPDATING = "-112",
453
+ /** 账号尚未实名认证 */
454
+ NOT_REAL_NAME_VERIFIED = "-113",
455
+ /** 请先绑定手机 */
456
+ NEED_BIND_PHONE = "-114",
457
+ /** 请先完成实名认证 */
458
+ NEED_REAL_NAME_VERIFICATION = "-115",
459
+ /** 木有改动 */
460
+ NO_CHANGE = "-304",
461
+ /** 撞车跳转 */
462
+ CONFLICT_REDIRECT = "-307",
463
+ /** 风控校验失败 (UA 或 wbi 参数不合法) */
464
+ RISK_CONTROL_FAILED = "-352",
465
+ /** 请求错误 */
466
+ BAD_REQUEST = "-400",
467
+ /** 未认证 (或非法请求) */
468
+ UNAUTHORIZED = "-401",
469
+ /** 访问权限不足 */
470
+ FORBIDDEN = "-403",
471
+ /** 啥都木有 */
472
+ NOT_FOUND = "-404",
473
+ /** 不支持该方法 */
474
+ METHOD_NOT_ALLOWED = "-405",
475
+ /** 冲突 */
476
+ CONFLICT = "-409",
477
+ /** 请求被拦截 (客户端 ip 被服务端风控) */
478
+ IP_BLOCKED = "-412",
479
+ /** 服务器错误 */
480
+ SERVER_ERROR = "-500",
481
+ /** 过载保护,服务暂不可用 */
482
+ SERVICE_UNAVAILABLE = "-503",
483
+ /** 服务调用超时 */
484
+ GATEWAY_TIMEOUT = "-504",
485
+ /** 超出限制 */
486
+ RATE_LIMITED = "-509",
487
+ /** 上传文件不存在 */
488
+ FILE_NOT_FOUND = "-616",
489
+ /** 上传文件太大 */
490
+ FILE_TOO_LARGE = "-617",
491
+ /** 登录失败次数太多 */
492
+ LOGIN_ATTEMPTS_EXCEEDED = "-625",
493
+ /** 用户不存在 */
494
+ USER_NOT_FOUND = "-626",
495
+ /** 密码太弱 */
496
+ WEAK_PASSWORD = "-628",
497
+ /** 用户名或密码错误 */
498
+ INVALID_CREDENTIALS = "-629",
499
+ /** 操作对象数量限制 */
500
+ OBJECT_LIMIT_EXCEEDED = "-632",
501
+ /** 被锁定 */
502
+ ACCOUNT_LOCKED = "-643",
503
+ /** 用户等级太低 */
504
+ USER_LEVEL_TOO_LOW = "-650",
505
+ /** 重复的用户 */
506
+ DUPLICATE_USER = "-652",
507
+ /** Token 过期 */
508
+ TOKEN_EXPIRED = "-658",
509
+ /** 密码时间戳过期 */
510
+ PASSWORD_TIMESTAMP_EXPIRED = "-662",
511
+ /** 地理区域限制 */
512
+ GEO_RESTRICTED = "-688",
513
+ /** 版权限制 */
514
+ COPYRIGHT_RESTRICTED = "-689",
515
+ /** 扣节操失败 */
516
+ REPUTATION_DEDUCTION_FAILED = "-701",
517
+ /** 请求过于频繁,请稍后再试 */
518
+ TOO_MANY_REQUESTS = "-799",
519
+ /** 服务器开小差了 */
520
+ SERVER_TEMPORARILY_UNAVAILABLE = "-8888",
521
+ /** 未知错误 */
522
+ UNKNOWN = "UNKNOWN"
523
+ }
524
+ /** 快手平台API错误码 */
525
+ declare enum kuaishouAPIErrorCode {
526
+ /** Cookie无效或已过期 */
527
+ COOKIE = "INVALID_COOKIE",
528
+ /** 未知错误 */
529
+ UNKNOWN = "UNKNOWN_ERROR"
530
+ }
390
531
 
391
532
  type DyEmojiList = {
392
533
  emoji_list: EmojiListElement[];
@@ -13243,6 +13384,21 @@ type TypeControl = {
13243
13384
  typeMode?: 'strict' | 'loose';
13244
13385
  };
13245
13386
 
13387
+ /**
13388
+ * API请求错误类型
13389
+ * 该类型是方法 `getXXXData` 封装后请求遇到错误时的返回类型
13390
+ */
13391
+ type APIErrorType<T extends 'douyin' | 'bilibili' | 'kuaishou' | 'default' = 'default'> = {
13392
+ /** 错误码 */
13393
+ code: T extends 'douyin' ? douoyinAPIErrorCode : T extends 'bilibili' ? bilibiliAPIErrorCode : T extends 'kuaishou' ? kuaishouAPIErrorCode : amagiAPIErrorCode;
13394
+ /** 错误时的响应数据 */
13395
+ data: any;
13396
+ /** amagi 错误详情 */
13397
+ amagiError: ErrorDetail;
13398
+ /** 错误信息 */
13399
+ amagiMessage: string;
13400
+ };
13401
+
13246
13402
  /**
13247
13403
  * 快捷获取抖音数据
13248
13404
  * @param type - 请求数据类型
@@ -13589,6 +13745,13 @@ declare function bv2av(bvid: string): number;
13589
13745
  */
13590
13746
  declare function wbi_sign(BASEURL: string | URL, cookie: string): Promise<string>;
13591
13747
 
13748
+ /**
13749
+ * 哔哩哔哩API官方HTTP请求错误码
13750
+ */
13751
+ declare const bilibiliErrorCodeMap: {
13752
+ [key: string]: string;
13753
+ };
13754
+
13592
13755
  declare function qtparam(BASEURL: string, cookie: string): Promise<{
13593
13756
  QUERY: string;
13594
13757
  STATUS: string;
@@ -14055,86 +14218,41 @@ declare class amagiClient {
14055
14218
  type AmagiConstructor = {
14056
14219
  new (options: cookiesOptions): amagiClient;
14057
14220
  (options: cookiesOptions): amagiClient;
14058
- };
14059
- /** After instantiation, it can interact with the specified platform API to quickly obtain data. */
14060
- declare const CreateApp: AmagiConstructor & {
14061
14221
  /** 抖音相关功能模块 (工具集) */
14062
- douyin: {
14063
- sign: typeof douyinSign;
14064
- douyinApiUrls: typeof douyinApiUrls;
14065
- getDouyinData: typeof getDouyinData;
14066
- api: typeof douyin;
14067
- };
14222
+ douyin: typeof douyinUtils;
14068
14223
  /** B站相关功能模块 (工具集) */
14069
- bilibili: {
14070
- sign: {
14071
- wbi_sign: typeof wbi_sign;
14072
- av2bv: typeof av2bv;
14073
- bv2av: typeof bv2av;
14074
- };
14075
- bilibiliApiUrls: typeof bilibiliApiUrls;
14076
- getBilibiliData: typeof getBilibiliData;
14077
- api: typeof bilibili;
14078
- };
14224
+ bilibili: typeof bilibiliUtils;
14079
14225
  /** 快手相关功能模块 (工具集) */
14080
- kuaishou: {
14081
- kuaishouApiUrls: typeof kuaishouApiUrls;
14082
- getKuaishouData: typeof getKuaishouData;
14083
- api: typeof kuaishou;
14084
- };
14226
+ kuaishou: typeof kuaishouUtils;
14227
+ /**
14228
+ * 快捷获取抖音数据
14229
+ * @param type - 请求数据类型
14230
+ * @param cookie - 有效的用户Cookie
14231
+ * @param options - 请求参数,是一个对象
14232
+ * @returns 返回接口的原始数据
14233
+ */
14234
+ getDouyinData: () => typeof douyinUtils.getDouyinData;
14235
+ /**
14236
+ * 快捷获取B站数据
14237
+ * @param type - 请求数据类型
14238
+ * @param cookie - 有效的用户Cookie
14239
+ * @param options - 请求参数,是一个对象
14240
+ * @returns 返回接口的原始数据
14241
+ */
14242
+ getBilibiliData: () => typeof bilibiliUtils.getBilibiliData;
14243
+ /**
14244
+ * 快捷获取快手数据
14245
+ * @param type - 请求数据类型
14246
+ * @param cookie - 有效的用户Cookie
14247
+ * @param options - 请求参数,是一个对象
14248
+ * @returns 返回接口的原始数据
14249
+ */
14250
+ getKuaishouData: () => typeof kuaishouUtils.getKuaishouData;
14085
14251
  };
14086
14252
  /** After instantiation, it can interact with the specified platform API to quickly obtain data. */
14087
- declare const Client: AmagiConstructor & {
14088
- /** 抖音相关功能模块 (工具集) */
14089
- douyin: {
14090
- sign: typeof douyinSign;
14091
- douyinApiUrls: typeof douyinApiUrls;
14092
- getDouyinData: typeof getDouyinData;
14093
- api: typeof douyin;
14094
- };
14095
- /** B站相关功能模块 (工具集) */
14096
- bilibili: {
14097
- sign: {
14098
- wbi_sign: typeof wbi_sign;
14099
- av2bv: typeof av2bv;
14100
- bv2av: typeof bv2av;
14101
- };
14102
- bilibiliApiUrls: typeof bilibiliApiUrls;
14103
- getBilibiliData: typeof getBilibiliData;
14104
- api: typeof bilibili;
14105
- };
14106
- /** 快手相关功能模块 (工具集) */
14107
- kuaishou: {
14108
- kuaishouApiUrls: typeof kuaishouApiUrls;
14109
- getKuaishouData: typeof getKuaishouData;
14110
- api: typeof kuaishou;
14111
- };
14112
- };
14113
- declare const amagi: AmagiConstructor & {
14114
- /** 抖音相关功能模块 (工具集) */
14115
- douyin: {
14116
- sign: typeof douyinSign;
14117
- douyinApiUrls: typeof douyinApiUrls;
14118
- getDouyinData: typeof getDouyinData;
14119
- api: typeof douyin;
14120
- };
14121
- /** B站相关功能模块 (工具集) */
14122
- bilibili: {
14123
- sign: {
14124
- wbi_sign: typeof wbi_sign;
14125
- av2bv: typeof av2bv;
14126
- bv2av: typeof bv2av;
14127
- };
14128
- bilibiliApiUrls: typeof bilibiliApiUrls;
14129
- getBilibiliData: typeof getBilibiliData;
14130
- api: typeof bilibili;
14131
- };
14132
- /** 快手相关功能模块 (工具集) */
14133
- kuaishou: {
14134
- kuaishouApiUrls: typeof kuaishouApiUrls;
14135
- getKuaishouData: typeof getKuaishouData;
14136
- api: typeof kuaishou;
14137
- };
14138
- };
14253
+ declare const CreateApp: AmagiConstructor;
14254
+ /** After instantiation, it can interact with the specified platform API to quickly obtain data. */
14255
+ declare const Client: AmagiConstructor;
14256
+ declare const amagi: AmagiConstructor;
14139
14257
 
14140
- export { type BiliAv2Bv, type BiliBangumiVideoInfo, type BiliBangumiVideoPlayurlIsLogin, type BiliBangumiVideoPlayurlNoLogin, type BiliBiliVideoPlayurlNoLogin, type BiliBv2AV, type BiliCheckQrcode, type BiliDynamicCard, type BiliDynamicInfo, type BiliEmojiList, type BiliLiveRoomDef, type BiliLiveRoomDetail, type BiliNewLoginQrcode, type BiliOneWork, type BiliUserDynamic, type BiliUserFullView, type BiliUserProfile, type BiliVideoPlayurlIsLogin, type BiliWorkComments, type BilibiliDataOptions, type BilibiliDataOptionsMap, type BilibiliMethodOptionsMap, type BilibiliRequest, BilibiliValidateData, CreateApp, type DouyinDataOptions, type DouyinDataOptionsMap, type DouyinMethodOptionsMap, type DouyinRequest, DouyinValidateData, type DyEmojiList, type DyEmojiProList, type DyImageAlbumWork, type DyMusicWork, type DySearchInfo, type DySlidesWork, type DySuggestWords, type DyUserInfo, type DyUserLiveVideos, type DyUserPostVideos, type DyVideoWork, type DyWorkComments, type KsEmojiList, type KsOneWork, type KsWorkComments, KuaishouAPI, type KuaishouDataOptions, type KuaishouDataOptionsMap, type KuaishouMethodOptionsMap, type KusiahouRequest, KusiahouValidateData, Networks, type NetworksConfigType, type OmitMethodType, type TypeControl, amagi, amagiClient, av2bv, bilibili, bilibiliAPI, bilibiliApiUrls, bilibiliUtils, bv2av, type cookiesOptions, Client as default, douyin, douyinAPI, douyinApiUrls, douyinSign, douyinUtils, fetchBilibiliData, fetchDouyinData, fetchKuaishouData, getBilibiliData, getDouyinData, getKuaishouData, kuaishou, kuaishouAPI, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, qtparam, registerBilibiliRoutes, registerDouyinRoutes, registerKuaishouRoutes, wbi_sign };
14258
+ export { type APIErrorType, type BiliAv2Bv, type BiliBangumiVideoInfo, type BiliBangumiVideoPlayurlIsLogin, type BiliBangumiVideoPlayurlNoLogin, type BiliBiliVideoPlayurlNoLogin, type BiliBv2AV, type BiliCheckQrcode, type BiliDynamicCard, type BiliDynamicInfo, type BiliEmojiList, type BiliLiveRoomDef, type BiliLiveRoomDetail, type BiliNewLoginQrcode, type BiliOneWork, type BiliUserDynamic, type BiliUserFullView, type BiliUserProfile, type BiliVideoPlayurlIsLogin, type BiliWorkComments, type BilibiliDataOptions, type BilibiliDataOptionsMap, type BilibiliMethodOptionsMap, type BilibiliRequest, BilibiliValidateData, CreateApp, type DouyinDataOptions, type DouyinDataOptionsMap, type DouyinMethodOptionsMap, type DouyinRequest, DouyinValidateData, type DyEmojiList, type DyEmojiProList, type DyImageAlbumWork, type DyMusicWork, type DySearchInfo, type DySlidesWork, type DySuggestWords, type DyUserInfo, type DyUserLiveVideos, type DyUserPostVideos, type DyVideoWork, type DyWorkComments, type KsEmojiList, type KsOneWork, type KsWorkComments, KuaishouAPI, type KuaishouDataOptions, type KuaishouDataOptionsMap, type KuaishouMethodOptionsMap, type KusiahouRequest, KusiahouValidateData, Networks, type NetworksConfigType, type OmitMethodType, type TypeControl, amagi, amagiClient, av2bv, bilibili, bilibiliAPI, bilibiliApiUrls, bilibiliErrorCodeMap, bilibiliUtils, bv2av, type cookiesOptions, Client as default, douyin, douyinAPI, douyinApiUrls, douyinSign, douyinUtils, fetchBilibiliData, fetchDouyinData, fetchKuaishouData, getBilibiliData, getDouyinData, getKuaishouData, kuaishou, kuaishouAPI, kuaishouApiUrls, kuaishouUtils, logMiddleware, logger, qtparam, registerBilibiliRoutes, registerDouyinRoutes, registerKuaishouRoutes, wbi_sign };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikenxuan/amagi",
3
- "version": "4.4.15",
3
+ "version": "4.4.17",
4
4
  "description": "抖音、B站的 web 端相关数据接口基于 Node.js 的实现",
5
5
  "keywords": [
6
6
  "douyin",
@@ -60,7 +60,7 @@
60
60
  "sort": "npx sort-package-json"
61
61
  },
62
62
  "dependencies": {
63
- "axios": "npm:@karinjs/axios@^1.1.8",
63
+ "axios": "npm:@karinjs/axios@^1.2.0",
64
64
  "chalk": "4.1.2",
65
65
  "express": "npm:@karinjs/express@^1.0.3",
66
66
  "log4js": "npm:@karinjs/log4js@1.1.4",
@@ -69,10 +69,12 @@
69
69
  "devDependencies": {
70
70
  "@eslint/js": "^9.17.0",
71
71
  "@swc/core": "^1.10.12",
72
+ "@types/crypto-js": "^4.2.2",
72
73
  "@types/express": "^4.17.21",
73
74
  "@types/node": "^22.10.2",
74
75
  "@typescript-eslint/eslint-plugin": "^8.18.1",
75
76
  "@typescript-eslint/parser": "^8.18.1",
77
+ "crypto-js": "^4.2.0",
76
78
  "eslint": "^9.17.0",
77
79
  "eslint-plugin-simple-import-sort": "^12.1.1",
78
80
  "globals": "^15.14.0",