@ikenxuan/amagi 1.5.6 → 1.5.8
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/lib/business/bilibili/API.js +1 -1
- package/lib/business/bilibili/getdata.js +1 -1
- package/lib/business/bilibili/index.d.ts +2 -2
- package/lib/business/bilibili/index.js +2 -2
- package/lib/business/bilibili/qtparam.js +1 -1
- package/lib/business/bilibili/result.d.ts +1 -1
- package/lib/business/bilibili/sign/wbi.js +3 -3
- package/lib/business/douyin/API.js +1 -1
- package/lib/business/douyin/getdata.js +2 -2
- package/lib/business/douyin/index.d.ts +2 -2
- package/lib/business/douyin/index.js +2 -2
- package/lib/business/douyin/result.d.ts +1 -1
- package/lib/business/douyin/sign/index.js +1 -1
- package/lib/business/index.d.ts +1 -1
- package/lib/business/index.js +1 -1
- package/lib/index.d.ts +3 -4
- package/lib/index.js +3 -4
- package/lib/model/dir.d.ts +1 -1
- package/lib/model/dir.js +1 -1
- package/lib/model/index.d.ts +1 -1
- package/lib/model/index.js +1 -1
- package/lib/model/logger.js +3 -3
- package/lib/model/networks.d.ts +8 -10
- package/lib/model/networks.js +57 -86
- package/lib/server/client.js +2 -2
- package/lib/types/BilibiliAPIParams.d.ts +4 -2
- package/lib/types/DouyinAPIParams.d.ts +1 -0
- package/lib/types/NetworksConfigType.d.ts +1 -1
- package/lib/types/Request.d.ts +1 -1
- package/lib/types/index.d.ts +7 -7
- package/lib/types/index.js +1 -1
- package/package.json +4 -4
|
@@ -10,7 +10,7 @@ class BiLiBiLiAPI {
|
|
|
10
10
|
}
|
|
11
11
|
/** type参数详见https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/comment/readme.md#评论区类型代码 */
|
|
12
12
|
评论区明细(data) {
|
|
13
|
-
return `https://api.bilibili.com/x/v2/reply?sort=1&ps
|
|
13
|
+
return `https://api.bilibili.com/x/v2/reply?sort=1&ps=${data.number || 20}&type=${data.type}&oid=${data.oid}`;
|
|
14
14
|
}
|
|
15
15
|
表情列表() {
|
|
16
16
|
return 'https://api.bilibili.com/x/emote/user/panel/web?business=reply&web_location=0.0';
|
|
@@ -8,7 +8,7 @@ export default class BilibiliData {
|
|
|
8
8
|
this.type = type;
|
|
9
9
|
this.headers = {};
|
|
10
10
|
this.headers.Referer = 'https://api.bilibili.com/';
|
|
11
|
-
this.headers.Cookie = cookie;
|
|
11
|
+
this.headers.Cookie = cookie.replace(/\s+/g, '');
|
|
12
12
|
this.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0';
|
|
13
13
|
}
|
|
14
14
|
async GetData(data = {}) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BiLiBiLiAPI from './API.js';
|
|
2
2
|
import BilibiliData from './getdata.js';
|
|
3
3
|
import GetBilibiliID from './getid.js';
|
|
4
|
-
import wbi_sign from './sign/wbi.js';
|
|
5
4
|
import qtparam from './qtparam.js';
|
|
6
5
|
import BilibiliResult from './result.js';
|
|
7
|
-
|
|
6
|
+
import wbi_sign from './sign/wbi.js';
|
|
7
|
+
export { BiLiBiLiAPI, BilibiliData, BilibiliResult, GetBilibiliID, qtparam, wbi_sign };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BiLiBiLiAPI from './API.js';
|
|
2
2
|
import BilibiliData from './getdata.js';
|
|
3
3
|
import GetBilibiliID from './getid.js';
|
|
4
|
-
import wbi_sign from './sign/wbi.js';
|
|
5
4
|
import qtparam from './qtparam.js';
|
|
6
5
|
import BilibiliResult from './result.js';
|
|
7
|
-
|
|
6
|
+
import wbi_sign from './sign/wbi.js';
|
|
7
|
+
export { BiLiBiLiAPI, BilibiliData, BilibiliResult, GetBilibiliID, qtparam, wbi_sign };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Networks } from '../../model/index.js';
|
|
2
1
|
import { BiLiBiLiAPI, wbi_sign } from '../../business/bilibili/index.js';
|
|
2
|
+
import { Networks } from '../../model/index.js';
|
|
3
3
|
export default async function qtparam(BASEURL, cookie) {
|
|
4
4
|
if (cookie == '')
|
|
5
5
|
return { QUERY: '&platform=html5', STATUS: '!isLogin' };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BilibiliDataType,
|
|
1
|
+
import { BilibiliDataType, BilibiliOptionsType, GetDataResponseType } from '../../types/index.js';
|
|
2
2
|
export default class BilibiliResult {
|
|
3
3
|
type: BilibiliDataType;
|
|
4
4
|
cookie: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import md5 from 'md5';
|
|
2
|
-
import
|
|
2
|
+
import axios from 'axios';
|
|
3
3
|
const mixinKeyEncTab = [
|
|
4
4
|
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26,
|
|
5
5
|
17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11, 36, 20, 34, 44, 52
|
|
@@ -29,12 +29,12 @@ function encWbi(params, img_key, sub_key) {
|
|
|
29
29
|
}
|
|
30
30
|
// 获取最新的 img_key 和 sub_key
|
|
31
31
|
async function getWbiKeys(cookie) {
|
|
32
|
-
const res = await
|
|
32
|
+
const res = await axios('https://api.bilibili.com/x/web-interface/nav', {
|
|
33
33
|
headers: {
|
|
34
34
|
Cookie: cookie
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
const responseJson =
|
|
37
|
+
const responseJson = res.data;
|
|
38
38
|
const response = responseJson; // 类型断言
|
|
39
39
|
// 确保response是ResponseData类型后再解构
|
|
40
40
|
const { data: { wbi_img: { img_url, sub_url } } } = response;
|
|
@@ -23,7 +23,7 @@ class DouyinAPI {
|
|
|
23
23
|
return `https://www.douyin.com/aweme/v1/web/user/profile/other/?device_platform=webapp&aid=6383&channel=channel_pc_web&publish_video_strategy_type=2&source=channel_pc_web&sec_user_id=${data.sec_uid}&personal_center_strategy=1&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=0&webid=7327957959955580467&msToken=${Sign.Mstoken(116)}&verifyFp=${fp}&fp=${fp}`;
|
|
24
24
|
}
|
|
25
25
|
热点词(data) {
|
|
26
|
-
return `https://www.douyin.com/aweme/v1/web/api/suggest_words/?device_platform=webapp&aid=6383&channel=channel_pc_web&query=${
|
|
26
|
+
return `https://www.douyin.com/aweme/v1/web/api/suggest_words/?device_platform=webapp&aid=6383&channel=channel_pc_web&query=${data.query}&business_id=30088&from_group_id=7129543174929812767&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh - CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7327957959955580467&msToken=${Sign.Mstoken(116)}&verifyFp=${fp}&fp=${fp}`;
|
|
27
27
|
}
|
|
28
28
|
搜索(data) {
|
|
29
29
|
return `https://www.douyin.com/aweme/v1/web/general/search/single/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_general&sort_type=0&publish_time=0&keyword=${data.query}&search_source=normal_search&query_correct_type=1&is_filter_search=0&from_group_id=&offset=0&count=15&pc_client_type=1&version_code=190600&version_name=19.6.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7338423850134226495&msToken=${Sign.Mstoken(116)}&verifyFp=${fp}&fp=${fp}`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DouyinAPI, Sign } from '../../business/douyin/index.js';
|
|
2
2
|
import { Networks } from '../../model/index.js';
|
|
3
3
|
export default class DouyinData {
|
|
4
4
|
type;
|
|
@@ -8,7 +8,7 @@ export default class DouyinData {
|
|
|
8
8
|
this.type = type;
|
|
9
9
|
this.headers = {
|
|
10
10
|
Referer: 'https://www.douyin.com/',
|
|
11
|
-
Cookie: cookie,
|
|
11
|
+
Cookie: cookie.replace(/\s+/g, ''),
|
|
12
12
|
Accept: '*/*',
|
|
13
13
|
'Content-Type': 'application/json',
|
|
14
14
|
'Accpet-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import DouyinData from './getdata.js';
|
|
2
1
|
import DouyinAPI from './API.js';
|
|
2
|
+
import DouyinData from './getdata.js';
|
|
3
3
|
import GetDouyinID from './getid.js';
|
|
4
4
|
import DouyinResult from './result.js';
|
|
5
5
|
import Sign from './sign/index.js';
|
|
6
|
-
export { DouyinAPI, DouyinData,
|
|
6
|
+
export { DouyinAPI, DouyinData, DouyinResult, GetDouyinID, Sign };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import DouyinData from './getdata.js';
|
|
2
1
|
import DouyinAPI from './API.js';
|
|
2
|
+
import DouyinData from './getdata.js';
|
|
3
3
|
import GetDouyinID from './getid.js';
|
|
4
4
|
import DouyinResult from './result.js';
|
|
5
5
|
import Sign from './sign/index.js';
|
|
6
|
-
export { DouyinAPI, DouyinData,
|
|
6
|
+
export { DouyinAPI, DouyinData, DouyinResult, GetDouyinID, Sign };
|
package/lib/business/index.d.ts
CHANGED
package/lib/business/index.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export * from "./model/index.js";
|
|
2
1
|
export * from "./business/index.js";
|
|
3
|
-
export * from "./
|
|
2
|
+
export * from "./model/index.js";
|
|
4
3
|
export * from "./server/index.js";
|
|
4
|
+
export * from "./types/index.js";
|
|
5
|
+
export { amagi as Amagi, amagi as default };
|
|
5
6
|
import { client } from "./server/index.js";
|
|
6
7
|
declare const amagi: typeof client;
|
|
7
|
-
export { amagi as default };
|
|
8
|
-
export { amagi as Amagi };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export * from "./model/index.js";
|
|
2
1
|
export * from "./business/index.js";
|
|
3
|
-
export * from "./
|
|
2
|
+
export * from "./model/index.js";
|
|
4
3
|
export * from "./server/index.js";
|
|
4
|
+
export * from "./types/index.js";
|
|
5
|
+
export { amagi as Amagi, amagi as default };
|
|
5
6
|
import { client } from "./server/index.js";
|
|
6
7
|
const amagi = client;
|
|
7
|
-
export { amagi as default };
|
|
8
|
-
export { amagi as Amagi };
|
package/lib/model/dir.d.ts
CHANGED
package/lib/model/dir.js
CHANGED
package/lib/model/index.d.ts
CHANGED
package/lib/model/index.js
CHANGED
package/lib/model/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
1
2
|
import log from 'loglevel';
|
|
2
3
|
import prefix from 'loglevel-plugin-prefix';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
4
|
const colors = {
|
|
5
5
|
TRACE: chalk.magenta,
|
|
6
6
|
DEBUG: chalk.cyan,
|
|
@@ -11,7 +11,7 @@ const colors = {
|
|
|
11
11
|
prefix.reg(log);
|
|
12
12
|
log.enableAll();
|
|
13
13
|
prefix.apply(log, {
|
|
14
|
-
format(level, name, timestamp) {
|
|
14
|
+
format (level, name, timestamp) {
|
|
15
15
|
const levelKey = level.toUpperCase();
|
|
16
16
|
if (!(levelKey in colors)) {
|
|
17
17
|
throw new Error(`Invalid log level: ${levelKey}`);
|
|
@@ -20,7 +20,7 @@ prefix.apply(log, {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
prefix.apply(log.getLogger('critical'), {
|
|
23
|
-
format(level, name, timestamp) {
|
|
23
|
+
format (level, name, timestamp) {
|
|
24
24
|
return chalk.red.bold(`[${timestamp}] ${level} ${name}:`);
|
|
25
25
|
}
|
|
26
26
|
});
|
package/lib/model/networks.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { NetworksConfigType } from '../types/index.js';
|
|
3
3
|
interface HeadersObject {
|
|
4
4
|
[key: string]: string;
|
|
5
5
|
}
|
|
6
6
|
export default class Networks {
|
|
7
|
-
url: string
|
|
7
|
+
url: string;
|
|
8
8
|
method: string;
|
|
9
|
-
|
|
9
|
+
headers: HeadersObject;
|
|
10
10
|
type: string;
|
|
11
|
-
body?:
|
|
12
|
-
|
|
11
|
+
body?: any;
|
|
12
|
+
axiosInstance: any;
|
|
13
13
|
isGetResult: boolean;
|
|
14
14
|
timeout: number;
|
|
15
15
|
timer: NodeJS.Timeout | undefined;
|
|
16
16
|
data: {};
|
|
17
|
-
redirect: string;
|
|
18
17
|
constructor(data: NetworksConfigType);
|
|
19
|
-
get config():
|
|
20
|
-
getfetch(): Promise<
|
|
21
|
-
returnResult(): Promise<
|
|
18
|
+
get config(): AxiosRequestConfig;
|
|
19
|
+
getfetch(): Promise<AxiosResponse | boolean>;
|
|
20
|
+
returnResult(): Promise<AxiosResponse>;
|
|
22
21
|
/** 最终地址(跟随重定向) */
|
|
23
22
|
getLongLink(): Promise<string>;
|
|
24
23
|
/** 获取首个302 */
|
|
@@ -33,6 +32,5 @@ export default class Networks {
|
|
|
33
32
|
ToText(): Promise<void>;
|
|
34
33
|
ToArrayBuffer(): Promise<void>;
|
|
35
34
|
ToBlob(): Promise<void>;
|
|
36
|
-
timeoutPromise(timeout: number): Promise<Response>;
|
|
37
35
|
}
|
|
38
36
|
export {};
|
package/lib/model/networks.js
CHANGED
|
@@ -1,48 +1,44 @@
|
|
|
1
|
-
import fetch, { Response } from 'node-fetch';
|
|
2
1
|
import { logger } from '../model/index.js';
|
|
3
|
-
|
|
2
|
+
import axios from 'axios';
|
|
4
3
|
export default class Networks {
|
|
5
4
|
url;
|
|
6
5
|
method;
|
|
7
|
-
|
|
6
|
+
headers;
|
|
8
7
|
type;
|
|
9
8
|
body;
|
|
10
|
-
|
|
9
|
+
axiosInstance;
|
|
11
10
|
isGetResult;
|
|
12
11
|
timeout;
|
|
13
12
|
timer;
|
|
14
13
|
data;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.Headers = new Headers();
|
|
18
|
-
if (data.headers && Object.keys(data.headers).length > 0) {
|
|
19
|
-
for (const [key, value] of Object.entries(data.headers)) {
|
|
20
|
-
this.Headers.append(key, value);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
else
|
|
24
|
-
this.Headers = {};
|
|
14
|
+
constructor (data) {
|
|
15
|
+
this.headers = data.headers || {};
|
|
25
16
|
this.url = data.url || '';
|
|
26
17
|
this.type = data.type || 'json';
|
|
27
18
|
this.method = data.method || 'GET';
|
|
28
|
-
this.body = data.body ||
|
|
19
|
+
this.body = data.body || null;
|
|
29
20
|
this.data = {};
|
|
30
|
-
this.timeout = data.timeout ||
|
|
21
|
+
this.timeout = data.timeout || 5000;
|
|
31
22
|
this.isGetResult = false;
|
|
32
23
|
this.timer = undefined;
|
|
33
|
-
|
|
24
|
+
// 创建axios实例
|
|
25
|
+
this.axiosInstance = axios.create({
|
|
26
|
+
timeout: this.timeout,
|
|
27
|
+
headers: this.headers
|
|
28
|
+
});
|
|
34
29
|
}
|
|
35
|
-
get config() {
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
method: this.method
|
|
30
|
+
get config () {
|
|
31
|
+
let config = {
|
|
32
|
+
url: this.url,
|
|
33
|
+
method: this.method,
|
|
34
|
+
headers: this.headers
|
|
39
35
|
};
|
|
40
|
-
if (this.method === 'POST') {
|
|
41
|
-
data =
|
|
36
|
+
if (this.method === 'POST' && this.body) {
|
|
37
|
+
config.data = this.body;
|
|
42
38
|
}
|
|
43
|
-
return
|
|
39
|
+
return config;
|
|
44
40
|
}
|
|
45
|
-
async getfetch() {
|
|
41
|
+
async getfetch () {
|
|
46
42
|
try {
|
|
47
43
|
const result = await this.returnResult();
|
|
48
44
|
if (result.status === 504) {
|
|
@@ -56,14 +52,14 @@ export default class Networks {
|
|
|
56
52
|
return false;
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
|
-
async returnResult() {
|
|
60
|
-
return await
|
|
55
|
+
async returnResult () {
|
|
56
|
+
return await this.axiosInstance(this.config);
|
|
61
57
|
}
|
|
62
58
|
/** 最终地址(跟随重定向) */
|
|
63
|
-
async getLongLink() {
|
|
59
|
+
async getLongLink () {
|
|
64
60
|
try {
|
|
65
61
|
const result = await this.returnResult();
|
|
66
|
-
return result.
|
|
62
|
+
return result.request.res.responseUrl; // axios中获取最终的请求URL
|
|
67
63
|
}
|
|
68
64
|
catch (error) {
|
|
69
65
|
logger.error(error);
|
|
@@ -71,14 +67,15 @@ export default class Networks {
|
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
69
|
/** 获取首个302 */
|
|
74
|
-
async getLocation() {
|
|
70
|
+
async getLocation () {
|
|
75
71
|
try {
|
|
76
|
-
const response = await
|
|
72
|
+
const response = await this.axiosInstance({
|
|
77
73
|
method: 'GET',
|
|
78
|
-
|
|
74
|
+
url: this.url,
|
|
75
|
+
maxRedirects: 0, // 禁止跟随重定向
|
|
76
|
+
validateStatus: (status) => status >= 300 && status < 400 // 仅处理3xx响应
|
|
79
77
|
});
|
|
80
|
-
|
|
81
|
-
return response.headers.get('location');
|
|
78
|
+
return response.headers['location'];
|
|
82
79
|
}
|
|
83
80
|
catch (error) {
|
|
84
81
|
logger.error(error);
|
|
@@ -86,7 +83,7 @@ export default class Networks {
|
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
85
|
/** 获取数据并处理数据的格式化,默认json */
|
|
89
|
-
async getData(new_fetch = '') {
|
|
86
|
+
async getData (new_fetch = '') {
|
|
90
87
|
try {
|
|
91
88
|
if (!new_fetch) {
|
|
92
89
|
const result = await this.returnResult();
|
|
@@ -97,11 +94,11 @@ export default class Networks {
|
|
|
97
94
|
logger.warn('HTTP 响应状态码: 429');
|
|
98
95
|
throw new Error('ratelimit triggered, 触发 https://www.douyin.com/ 的速率限制!!!');
|
|
99
96
|
}
|
|
100
|
-
this.
|
|
97
|
+
this.axiosInstance = result;
|
|
101
98
|
this.isGetResult = true;
|
|
102
99
|
}
|
|
103
100
|
else {
|
|
104
|
-
this.
|
|
101
|
+
this.axiosInstance = new_fetch;
|
|
105
102
|
}
|
|
106
103
|
switch (this.type) {
|
|
107
104
|
case 'json':
|
|
@@ -118,7 +115,7 @@ export default class Networks {
|
|
|
118
115
|
break;
|
|
119
116
|
default:
|
|
120
117
|
}
|
|
121
|
-
return this.
|
|
118
|
+
return this.axiosInstance;
|
|
122
119
|
}
|
|
123
120
|
catch (error) {
|
|
124
121
|
logger.error(error);
|
|
@@ -126,17 +123,12 @@ export default class Networks {
|
|
|
126
123
|
}
|
|
127
124
|
}
|
|
128
125
|
/** 获取响应头 */
|
|
129
|
-
async getHeaders() {
|
|
126
|
+
async getHeaders () {
|
|
130
127
|
try {
|
|
131
|
-
this.
|
|
132
|
-
if (this.
|
|
133
|
-
if (this.
|
|
134
|
-
|
|
135
|
-
const headersObject = {};
|
|
136
|
-
for (const [key, value] of headers.entries()) {
|
|
137
|
-
headersObject[key] = value;
|
|
138
|
-
}
|
|
139
|
-
return headersObject;
|
|
128
|
+
this.axiosInstance = await this.returnResult();
|
|
129
|
+
if (this.axiosInstance) {
|
|
130
|
+
if (this.axiosInstance.headers) {
|
|
131
|
+
return this.axiosInstance.headers;
|
|
140
132
|
}
|
|
141
133
|
else {
|
|
142
134
|
logger.error('未获取到响应头');
|
|
@@ -154,32 +146,19 @@ export default class Networks {
|
|
|
154
146
|
}
|
|
155
147
|
}
|
|
156
148
|
/** 一次性获取响应头和响应体 */
|
|
157
|
-
async getHeadersAndData() {
|
|
149
|
+
async getHeadersAndData () {
|
|
158
150
|
try {
|
|
159
|
-
|
|
160
|
-
this.fetch = await this.returnResult();
|
|
161
|
-
// 初始化响应头和响应数据
|
|
151
|
+
this.axiosInstance = await this.returnResult();
|
|
162
152
|
let headers = null;
|
|
163
153
|
let data = null;
|
|
164
|
-
if (this.
|
|
165
|
-
|
|
166
|
-
if (this.fetch.headers) {
|
|
167
|
-
headers = {};
|
|
168
|
-
const fetchHeaders = this.fetch.headers;
|
|
169
|
-
for (const [key, value] of fetchHeaders.entries()) {
|
|
170
|
-
headers[key] = value;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
logger.error('未获取到响应头');
|
|
175
|
-
}
|
|
176
|
-
// 获取响应数据
|
|
154
|
+
if (this.axiosInstance) {
|
|
155
|
+
headers = this.axiosInstance.headers;
|
|
177
156
|
switch (this.type) {
|
|
178
157
|
case 'json':
|
|
179
|
-
data =
|
|
158
|
+
data = this.axiosInstance.data;
|
|
180
159
|
break;
|
|
181
160
|
case 'text':
|
|
182
|
-
data =
|
|
161
|
+
data = this.axiosInstance.data;
|
|
183
162
|
break;
|
|
184
163
|
case 'arrayBuffer':
|
|
185
164
|
data = await this.ToArrayBuffer();
|
|
@@ -200,31 +179,23 @@ export default class Networks {
|
|
|
200
179
|
return { headers: null, data: null };
|
|
201
180
|
}
|
|
202
181
|
}
|
|
203
|
-
async Tojson() {
|
|
204
|
-
if (this.
|
|
205
|
-
this.
|
|
182
|
+
async Tojson () {
|
|
183
|
+
if (this.axiosInstance.headers['content-type'].includes('json')) {
|
|
184
|
+
this.axiosInstance = this.axiosInstance.data;
|
|
206
185
|
}
|
|
207
186
|
else {
|
|
208
|
-
this.
|
|
187
|
+
this.axiosInstance = this.axiosInstance.data;
|
|
209
188
|
this.type = 'text';
|
|
210
189
|
}
|
|
211
190
|
}
|
|
212
|
-
async ToText() {
|
|
213
|
-
this.
|
|
191
|
+
async ToText () {
|
|
192
|
+
this.axiosInstance = this.axiosInstance.data;
|
|
214
193
|
}
|
|
215
|
-
async ToArrayBuffer() {
|
|
216
|
-
this.
|
|
194
|
+
async ToArrayBuffer () {
|
|
195
|
+
this.axiosInstance = this.axiosInstance.data;
|
|
217
196
|
}
|
|
218
|
-
async ToBlob() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
timeoutPromise(timeout) {
|
|
222
|
-
return new Promise((resolve, reject) => {
|
|
223
|
-
this.timer = setTimeout(() => {
|
|
224
|
-
logger.info('执行力');
|
|
225
|
-
controller.abort();
|
|
226
|
-
resolve(new Response('timeout', { status: 504, statusText: 'timeout' }));
|
|
227
|
-
}, timeout);
|
|
228
|
-
});
|
|
197
|
+
async ToBlob () {
|
|
198
|
+
// axios 没有直接支持blob, 需要使用arraybuffer然后转换
|
|
199
|
+
this.axiosInstance = new Blob([new Uint8Array(this.axiosInstance.data)]);
|
|
229
200
|
}
|
|
230
201
|
}
|
package/lib/server/client.js
CHANGED
|
@@ -8,7 +8,7 @@ export class client {
|
|
|
8
8
|
*
|
|
9
9
|
* @param cookies 包含抖音和B站cookie的参数对象
|
|
10
10
|
*/
|
|
11
|
-
constructor(cookies) {
|
|
11
|
+
constructor (cookies) {
|
|
12
12
|
/** 抖音ck */
|
|
13
13
|
this.douyin = cookies.douyin;
|
|
14
14
|
/** B站ck */
|
|
@@ -19,7 +19,7 @@ export class client {
|
|
|
19
19
|
* @param log 是否启用日志
|
|
20
20
|
* @returns fastify 实例
|
|
21
21
|
*/
|
|
22
|
-
async initServer(log = false) {
|
|
22
|
+
async initServer (log = false) {
|
|
23
23
|
const client = fastify({ logger: log });
|
|
24
24
|
client.get('/api/douyin/aweme', async (request, reply) => {
|
|
25
25
|
const url = request.query.url;
|
|
@@ -12,9 +12,11 @@ type VideoStreamParams = {
|
|
|
12
12
|
};
|
|
13
13
|
type CommentParams = {
|
|
14
14
|
/** 评论区类型,type参数详见https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/comment/readme.md#评论区类型代码 */
|
|
15
|
-
type
|
|
15
|
+
type?: number | string;
|
|
16
16
|
/** 稿件ID,也就是AVID */
|
|
17
|
-
oid
|
|
17
|
+
oid?: number | string;
|
|
18
|
+
/** 获取的评论数量,默认最高20 */
|
|
19
|
+
number?: number;
|
|
18
20
|
};
|
|
19
21
|
type BangumiInfoParams = {
|
|
20
22
|
/** 稿件ID是否为epid */
|
package/lib/types/Request.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyRequest } from 'fastify';
|
|
2
|
-
import {
|
|
2
|
+
import { BilibiliOptionsType, DouyinOptionsType } from './OptionsType.js';
|
|
3
3
|
export interface DouyinRequest extends FastifyRequest {
|
|
4
4
|
Querystring: DouyinOptionsType;
|
|
5
5
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type DouyinOptionsType, type BilibiliOptionsType } from './OptionsType.js';
|
|
3
|
-
import { type GetDataResponseType } from './GetDataResponseType.js';
|
|
1
|
+
import { type BilibiliAPIParams } from './BilibiliAPIParams.js';
|
|
4
2
|
import { type ConfigType } from './ConfigType.js';
|
|
5
|
-
import {
|
|
6
|
-
import { DouyinRequest, BilibiliRequest } from './Request.js';
|
|
3
|
+
import { BilibiliDataType, DouyinDataType } from './DataType.js';
|
|
7
4
|
import { type DouyinAPIParams } from './DouyinAPIParams.js';
|
|
8
|
-
import { type
|
|
9
|
-
|
|
5
|
+
import { type GetDataResponseType } from './GetDataResponseType.js';
|
|
6
|
+
import { type NetworksConfigType } from './NetworksConfigType.js';
|
|
7
|
+
import { type BilibiliOptionsType, type DouyinOptionsType } from './OptionsType.js';
|
|
8
|
+
export * from './Request.js';
|
|
9
|
+
export { BilibiliAPIParams, BilibiliDataType, BilibiliOptionsType, ConfigType, DouyinAPIParams, DouyinDataType, DouyinOptionsType, GetDataResponseType, NetworksConfigType };
|
package/lib/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './Request.js';
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikenxuan/amagi",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"homepage": "https://github.com/ikenxuan/amagi",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"dev": "tsx
|
|
9
|
+
"dev": "tsx watch src/dev.ts",
|
|
10
10
|
"fix": "eslint lib/**/*.js --fix && eslint lib/**/*.d.ts --fix",
|
|
11
11
|
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run fix"
|
|
12
12
|
},
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"registry": "https://registry.npmjs.org"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"axios": "^1.7.3",
|
|
32
33
|
"chalk": "^5.3.0",
|
|
33
34
|
"chokidar": "^3.6.0",
|
|
34
35
|
"fastify": "^4.28.1",
|
|
35
36
|
"lodash": "4.17.21",
|
|
36
37
|
"loglevel": "^1.9.1",
|
|
37
38
|
"loglevel-plugin-prefix": "^0.8.4",
|
|
38
|
-
"md5": "^2.3.0"
|
|
39
|
-
"node-fetch": "^3.3.2"
|
|
39
|
+
"md5": "^2.3.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/lodash": "latest",
|