@ikenxuan/amagi 5.0.1 → 5.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/default/cjs/index.cjs +61 -15
- package/dist/default/esm/index.mjs +60 -14
- package/dist/default/index.d.ts +9 -28
- package/package.json +1 -1
|
@@ -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.13.3_tsx@4.20.3_typescript@5.
|
|
30
|
+
// node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.3_tsx@4.20.3_typescript@5.9.2/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 = () => {
|
|
@@ -167,9 +167,16 @@ var logMiddleware = (pathsToLog) => {
|
|
|
167
167
|
next();
|
|
168
168
|
};
|
|
169
169
|
};
|
|
170
|
+
var cleanUserAgent = (userAgent) => {
|
|
171
|
+
return userAgent.replace(/\s+Edg\/[\d\.]+/g, "");
|
|
172
|
+
};
|
|
170
173
|
var fetchData = async (config) => {
|
|
171
174
|
try {
|
|
172
|
-
const
|
|
175
|
+
const cleanedConfig = { ...config };
|
|
176
|
+
if (cleanedConfig.headers && cleanedConfig.headers["User-Agent"]) {
|
|
177
|
+
cleanedConfig.headers["User-Agent"] = cleanUserAgent(cleanedConfig.headers["User-Agent"]);
|
|
178
|
+
}
|
|
179
|
+
const response = await axios__default.default(cleanedConfig);
|
|
173
180
|
if (response.status === 429) {
|
|
174
181
|
logger.error("HTTP \u54CD\u5E94\u72B6\u6001\u7801: 429");
|
|
175
182
|
throw new Error("ratelimit triggered, \u89E6\u53D1\u901F\u7387\u9650\u5236\uFF01");
|
|
@@ -185,7 +192,11 @@ var fetchData = async (config) => {
|
|
|
185
192
|
};
|
|
186
193
|
var fetchResponse = async (config) => {
|
|
187
194
|
try {
|
|
188
|
-
|
|
195
|
+
const cleanedConfig = { ...config };
|
|
196
|
+
if (cleanedConfig.headers && cleanedConfig.headers["User-Agent"]) {
|
|
197
|
+
cleanedConfig.headers["User-Agent"] = cleanUserAgent(cleanedConfig.headers["User-Agent"]);
|
|
198
|
+
}
|
|
199
|
+
return await axios__default.default(cleanedConfig);
|
|
189
200
|
} catch (error) {
|
|
190
201
|
if (error instanceof axios.AxiosError) {
|
|
191
202
|
throw error;
|
|
@@ -444,7 +455,8 @@ var generateSecChUa = (userAgent) => {
|
|
|
444
455
|
};
|
|
445
456
|
var getDouyinDefaultConfig = (cookie, requestConfig) => {
|
|
446
457
|
var _a;
|
|
447
|
-
|
|
458
|
+
let finalUserAgent = ((_a = void 0 ) == null ? void 0 : _a["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";
|
|
459
|
+
finalUserAgent = finalUserAgent.replace(/\s+Edg\/[\d\.]+/g, "");
|
|
448
460
|
const defHeaders = {
|
|
449
461
|
Accept: "application/json, text/plain, */*",
|
|
450
462
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
@@ -723,11 +735,46 @@ var fetchBilibili = async (data2, cookie, requestConfig) => {
|
|
|
723
735
|
return result;
|
|
724
736
|
}
|
|
725
737
|
case "\u4E8C\u7EF4\u7801\u72B6\u6001": {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
738
|
+
try {
|
|
739
|
+
const result = await getHeadersAndData({
|
|
740
|
+
...baseRequestConfig,
|
|
741
|
+
url: bilibiliApiUrls.\u4E8C\u7EF4\u7801\u72B6\u6001({ qrcode_key: data2.qrcode_key })
|
|
742
|
+
});
|
|
743
|
+
if (result.data.code !== 0) {
|
|
744
|
+
const errorMessage = bilibiliErrorCodeMap[String(result.data.code)] || result.data.message || "\u672A\u77E5\u9519\u8BEF";
|
|
745
|
+
const Err = {
|
|
746
|
+
errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${errorMessage}\uFF01`,
|
|
747
|
+
requestType: data2.methodType,
|
|
748
|
+
requestUrl: bilibiliApiUrls.\u4E8C\u7EF4\u7801\u72B6\u6001({ qrcode_key: data2.qrcode_key })
|
|
749
|
+
};
|
|
750
|
+
return {
|
|
751
|
+
code: result.data.code,
|
|
752
|
+
data: result.data,
|
|
753
|
+
amagiError: Err
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
return {
|
|
757
|
+
code: 0,
|
|
758
|
+
data: {
|
|
759
|
+
data: result.data.data,
|
|
760
|
+
headers: result.headers
|
|
761
|
+
},
|
|
762
|
+
message: "0"
|
|
763
|
+
};
|
|
764
|
+
} catch (error) {
|
|
765
|
+
if (error && typeof error === "object") {
|
|
766
|
+
return error;
|
|
767
|
+
}
|
|
768
|
+
return {
|
|
769
|
+
code: "UNKNOWN_ERROR" /* UNKNOWN */,
|
|
770
|
+
data: error.data,
|
|
771
|
+
amagiError: {
|
|
772
|
+
errorDescription: "\u672A\u77E5\u9519\u8BEF",
|
|
773
|
+
requestType: data2.methodType,
|
|
774
|
+
requestUrl: bilibiliApiUrls.\u4E8C\u7EF4\u7801\u72B6\u6001({ qrcode_key: data2.qrcode_key })
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
}
|
|
731
778
|
}
|
|
732
779
|
case "\u767B\u5F55\u57FA\u672C\u4FE1\u606F": {
|
|
733
780
|
const result = await GlobalGetData(data2.methodType, {
|
|
@@ -1229,8 +1276,12 @@ function generate_random_str() {
|
|
|
1229
1276
|
random_str_list = random_str_list.concat(gener_random(Math.random() * 1e4, [1, 5]));
|
|
1230
1277
|
return String.fromCharCode.apply(null, random_str_list);
|
|
1231
1278
|
}
|
|
1279
|
+
var cleanUserAgentForSigning = (userAgent) => {
|
|
1280
|
+
return userAgent.replace(/\s+Edg\/[\d\.]+/g, "");
|
|
1281
|
+
};
|
|
1232
1282
|
var a_bogus_default = (url, user_agent) => {
|
|
1233
|
-
|
|
1283
|
+
const cleanedUserAgent = cleanUserAgentForSigning(user_agent);
|
|
1284
|
+
let result_str = generate_random_str() + generate_rc4_bb_str(new URLSearchParams(new URL(url).search).toString(), cleanedUserAgent, "1536|747|1536|834|0|30|0|0|1536|834|1536|864|1525|747|24|24|Win32");
|
|
1234
1285
|
return result_encrypt(result_str, "s4") + "=";
|
|
1235
1286
|
};
|
|
1236
1287
|
|
|
@@ -3345,9 +3396,6 @@ var createAmagiClient = (options) => {
|
|
|
3345
3396
|
});
|
|
3346
3397
|
return app;
|
|
3347
3398
|
};
|
|
3348
|
-
const startClient = (port = 4567) => {
|
|
3349
|
-
return startServer(port);
|
|
3350
|
-
};
|
|
3351
3399
|
const getDouyinDataWithCookie = async (methodType, options2) => {
|
|
3352
3400
|
return await getDouyinData(methodType, options2, douyinCookie, requestConfig);
|
|
3353
3401
|
};
|
|
@@ -3360,8 +3408,6 @@ var createAmagiClient = (options) => {
|
|
|
3360
3408
|
return {
|
|
3361
3409
|
/** 启动本地HTTP服务 */
|
|
3362
3410
|
startServer,
|
|
3363
|
-
/** @deprecated 此方法已废弃,请使用 startServer 方法代替 */
|
|
3364
|
-
startClient,
|
|
3365
3411
|
getDouyinData: getDouyinDataWithCookie,
|
|
3366
3412
|
getBilibiliData: getBilibiliDataWithCookie,
|
|
3367
3413
|
getKuaishouData: getKuaishouDataWithCookie,
|
|
@@ -151,9 +151,16 @@ var logMiddleware = (pathsToLog) => {
|
|
|
151
151
|
next();
|
|
152
152
|
};
|
|
153
153
|
};
|
|
154
|
+
var cleanUserAgent = (userAgent) => {
|
|
155
|
+
return userAgent.replace(/\s+Edg\/[\d\.]+/g, "");
|
|
156
|
+
};
|
|
154
157
|
var fetchData = async (config) => {
|
|
155
158
|
try {
|
|
156
|
-
const
|
|
159
|
+
const cleanedConfig = { ...config };
|
|
160
|
+
if (cleanedConfig.headers && cleanedConfig.headers["User-Agent"]) {
|
|
161
|
+
cleanedConfig.headers["User-Agent"] = cleanUserAgent(cleanedConfig.headers["User-Agent"]);
|
|
162
|
+
}
|
|
163
|
+
const response = await axios(cleanedConfig);
|
|
157
164
|
if (response.status === 429) {
|
|
158
165
|
logger.error("HTTP \u54CD\u5E94\u72B6\u6001\u7801: 429");
|
|
159
166
|
throw new Error("ratelimit triggered, \u89E6\u53D1\u901F\u7387\u9650\u5236\uFF01");
|
|
@@ -169,7 +176,11 @@ var fetchData = async (config) => {
|
|
|
169
176
|
};
|
|
170
177
|
var fetchResponse = async (config) => {
|
|
171
178
|
try {
|
|
172
|
-
|
|
179
|
+
const cleanedConfig = { ...config };
|
|
180
|
+
if (cleanedConfig.headers && cleanedConfig.headers["User-Agent"]) {
|
|
181
|
+
cleanedConfig.headers["User-Agent"] = cleanUserAgent(cleanedConfig.headers["User-Agent"]);
|
|
182
|
+
}
|
|
183
|
+
return await axios(cleanedConfig);
|
|
173
184
|
} catch (error) {
|
|
174
185
|
if (error instanceof AxiosError) {
|
|
175
186
|
throw error;
|
|
@@ -428,7 +439,8 @@ var generateSecChUa = (userAgent) => {
|
|
|
428
439
|
};
|
|
429
440
|
var getDouyinDefaultConfig = (cookie, requestConfig) => {
|
|
430
441
|
var _a;
|
|
431
|
-
|
|
442
|
+
let finalUserAgent = ((_a = void 0 ) == null ? void 0 : _a["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";
|
|
443
|
+
finalUserAgent = finalUserAgent.replace(/\s+Edg\/[\d\.]+/g, "");
|
|
432
444
|
const defHeaders = {
|
|
433
445
|
Accept: "application/json, text/plain, */*",
|
|
434
446
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
@@ -707,11 +719,46 @@ var fetchBilibili = async (data2, cookie, requestConfig) => {
|
|
|
707
719
|
return result;
|
|
708
720
|
}
|
|
709
721
|
case "\u4E8C\u7EF4\u7801\u72B6\u6001": {
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
722
|
+
try {
|
|
723
|
+
const result = await getHeadersAndData({
|
|
724
|
+
...baseRequestConfig,
|
|
725
|
+
url: bilibiliApiUrls.\u4E8C\u7EF4\u7801\u72B6\u6001({ qrcode_key: data2.qrcode_key })
|
|
726
|
+
});
|
|
727
|
+
if (result.data.code !== 0) {
|
|
728
|
+
const errorMessage = bilibiliErrorCodeMap[String(result.data.code)] || result.data.message || "\u672A\u77E5\u9519\u8BEF";
|
|
729
|
+
const Err = {
|
|
730
|
+
errorDescription: `\u83B7\u53D6\u54CD\u5E94\u6570\u636E\u5931\u8D25\uFF01\u539F\u56E0\uFF1A${errorMessage}\uFF01`,
|
|
731
|
+
requestType: data2.methodType,
|
|
732
|
+
requestUrl: bilibiliApiUrls.\u4E8C\u7EF4\u7801\u72B6\u6001({ qrcode_key: data2.qrcode_key })
|
|
733
|
+
};
|
|
734
|
+
return {
|
|
735
|
+
code: result.data.code,
|
|
736
|
+
data: result.data,
|
|
737
|
+
amagiError: Err
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
return {
|
|
741
|
+
code: 0,
|
|
742
|
+
data: {
|
|
743
|
+
data: result.data.data,
|
|
744
|
+
headers: result.headers
|
|
745
|
+
},
|
|
746
|
+
message: "0"
|
|
747
|
+
};
|
|
748
|
+
} catch (error) {
|
|
749
|
+
if (error && typeof error === "object") {
|
|
750
|
+
return error;
|
|
751
|
+
}
|
|
752
|
+
return {
|
|
753
|
+
code: "UNKNOWN_ERROR" /* UNKNOWN */,
|
|
754
|
+
data: error.data,
|
|
755
|
+
amagiError: {
|
|
756
|
+
errorDescription: "\u672A\u77E5\u9519\u8BEF",
|
|
757
|
+
requestType: data2.methodType,
|
|
758
|
+
requestUrl: bilibiliApiUrls.\u4E8C\u7EF4\u7801\u72B6\u6001({ qrcode_key: data2.qrcode_key })
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
}
|
|
715
762
|
}
|
|
716
763
|
case "\u767B\u5F55\u57FA\u672C\u4FE1\u606F": {
|
|
717
764
|
const result = await GlobalGetData(data2.methodType, {
|
|
@@ -1213,8 +1260,12 @@ function generate_random_str() {
|
|
|
1213
1260
|
random_str_list = random_str_list.concat(gener_random(Math.random() * 1e4, [1, 5]));
|
|
1214
1261
|
return String.fromCharCode.apply(null, random_str_list);
|
|
1215
1262
|
}
|
|
1263
|
+
var cleanUserAgentForSigning = (userAgent) => {
|
|
1264
|
+
return userAgent.replace(/\s+Edg\/[\d\.]+/g, "");
|
|
1265
|
+
};
|
|
1216
1266
|
var a_bogus_default = (url, user_agent) => {
|
|
1217
|
-
|
|
1267
|
+
const cleanedUserAgent = cleanUserAgentForSigning(user_agent);
|
|
1268
|
+
let result_str = generate_random_str() + generate_rc4_bb_str(new URLSearchParams(new URL(url).search).toString(), cleanedUserAgent, "1536|747|1536|834|0|30|0|0|1536|834|1536|864|1525|747|24|24|Win32");
|
|
1218
1269
|
return result_encrypt(result_str, "s4") + "=";
|
|
1219
1270
|
};
|
|
1220
1271
|
|
|
@@ -3329,9 +3380,6 @@ var createAmagiClient = (options) => {
|
|
|
3329
3380
|
});
|
|
3330
3381
|
return app;
|
|
3331
3382
|
};
|
|
3332
|
-
const startClient = (port = 4567) => {
|
|
3333
|
-
return startServer(port);
|
|
3334
|
-
};
|
|
3335
3383
|
const getDouyinDataWithCookie = async (methodType, options2) => {
|
|
3336
3384
|
return await getDouyinData(methodType, options2, douyinCookie, requestConfig);
|
|
3337
3385
|
};
|
|
@@ -3344,8 +3392,6 @@ var createAmagiClient = (options) => {
|
|
|
3344
3392
|
return {
|
|
3345
3393
|
/** 启动本地HTTP服务 */
|
|
3346
3394
|
startServer,
|
|
3347
|
-
/** @deprecated 此方法已废弃,请使用 startServer 方法代替 */
|
|
3348
|
-
startClient,
|
|
3349
3395
|
getDouyinData: getDouyinDataWithCookie,
|
|
3350
3396
|
getBilibiliData: getBilibiliDataWithCookie,
|
|
3351
3397
|
getKuaishouData: getKuaishouDataWithCookie,
|
package/dist/default/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { AxiosResponse, AxiosRequestConfig } from 'axios';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import * as express from 'express';
|
|
3
4
|
import express__default, { Router, RequestHandler } from 'express';
|
|
4
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
5
5
|
import { ChalkInstance } from 'chalk';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -9709,18 +9709,17 @@ type StudioInfo = {
|
|
|
9709
9709
|
};
|
|
9710
9710
|
|
|
9711
9711
|
type BiliCheckQrcode = {
|
|
9712
|
-
data: CheckQrcodeData;
|
|
9713
|
-
headers: Headers;
|
|
9714
|
-
[property: string]: any;
|
|
9715
|
-
};
|
|
9716
|
-
type CheckQrcodeData = {
|
|
9717
9712
|
code: number;
|
|
9718
|
-
data:
|
|
9713
|
+
data: PurpleData;
|
|
9719
9714
|
message: string;
|
|
9720
|
-
ttl: number;
|
|
9721
9715
|
[property: string]: any;
|
|
9722
9716
|
};
|
|
9723
|
-
type
|
|
9717
|
+
type PurpleData = {
|
|
9718
|
+
data: FluffyData;
|
|
9719
|
+
headers: AxiosResponse['headers'];
|
|
9720
|
+
[property: string]: any;
|
|
9721
|
+
};
|
|
9722
|
+
type FluffyData = {
|
|
9724
9723
|
code: number;
|
|
9725
9724
|
message: string;
|
|
9726
9725
|
refresh_token: string;
|
|
@@ -9728,21 +9727,6 @@ type DataData$1 = {
|
|
|
9728
9727
|
url: string;
|
|
9729
9728
|
[property: string]: any;
|
|
9730
9729
|
};
|
|
9731
|
-
type Headers = {
|
|
9732
|
-
'bili-status-code': string;
|
|
9733
|
-
'bili-trace-id': string;
|
|
9734
|
-
'cache-control': string;
|
|
9735
|
-
connection: string;
|
|
9736
|
-
'content-type': string;
|
|
9737
|
-
cpu_usage: string;
|
|
9738
|
-
date: string;
|
|
9739
|
-
expires: string;
|
|
9740
|
-
'transfer-encoding': string;
|
|
9741
|
-
'x-bili-trace-id': string;
|
|
9742
|
-
'x-cache-webcdn': string;
|
|
9743
|
-
'x-ticket-status': string;
|
|
9744
|
-
[property: string]: any;
|
|
9745
|
-
};
|
|
9746
9730
|
|
|
9747
9731
|
type BiliNewLoginQrcode = {
|
|
9748
9732
|
code: number;
|
|
@@ -14291,8 +14275,6 @@ type Options = {
|
|
|
14291
14275
|
declare const createAmagiClient: (options?: Options) => {
|
|
14292
14276
|
/** 启动本地HTTP服务 */
|
|
14293
14277
|
startServer: (port?: number) => express__default.Application;
|
|
14294
|
-
/** @deprecated 此方法已废弃,请使用 startServer 方法代替 */
|
|
14295
|
-
startClient: (port?: number) => express__default.Application;
|
|
14296
14278
|
getDouyinData: <T extends DouyinMethodType, M extends TypeMode>(methodType: T, options?: ExtendedDouyinOptions<T> & {
|
|
14297
14279
|
typeMode?: M;
|
|
14298
14280
|
}) => Promise<ApiResponse<ConditionalReturnType<DouyinDataOptionsMap[T]["data"], M>>>;
|
|
@@ -16180,7 +16162,7 @@ declare const fetchResponse: <T = unknown>(config: AxiosRequestConfig) => Promis
|
|
|
16180
16162
|
* @returns 包含headers和data的对象
|
|
16181
16163
|
*/
|
|
16182
16164
|
declare const getHeadersAndData: <T = any>(config: AxiosRequestConfig) => Promise<{
|
|
16183
|
-
headers:
|
|
16165
|
+
headers: AxiosResponse<T>["headers"];
|
|
16184
16166
|
data: T;
|
|
16185
16167
|
}>;
|
|
16186
16168
|
|
|
@@ -16248,7 +16230,6 @@ declare const handleError: (error: unknown, requestPath?: string) => {
|
|
|
16248
16230
|
*/
|
|
16249
16231
|
declare const amagiClient: (options?: Options) => {
|
|
16250
16232
|
startServer: (port?: number) => express.Application;
|
|
16251
|
-
startClient: (port?: number) => express.Application;
|
|
16252
16233
|
getDouyinData: <T extends DouyinMethodType, M extends TypeMode>(methodType: T, options?: ExtendedDouyinOptions<T> & {
|
|
16253
16234
|
typeMode?: M;
|
|
16254
16235
|
}) => Promise<ApiResponse<ConditionalReturnType<DouyinDataOptionsMap[T]["data"], M>>>;
|