@ikenxuan/amagi 1.4.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/LICENSE +674 -0
- package/README.md +82 -0
- package/config/config.yaml +5 -0
- package/config/default_config.yaml +5 -0
- package/lib/app.d.ts +1 -0
- package/lib/app.js +2 -0
- package/lib/business/bilibili/API.d.ts +39 -0
- package/lib/business/bilibili/API.js +37 -0
- package/lib/business/bilibili/getdata.d.ts +9 -0
- package/lib/business/bilibili/getdata.js +169 -0
- package/lib/business/bilibili/getid.d.ts +26 -0
- package/lib/business/bilibili/getid.js +41 -0
- package/lib/business/bilibili/index.d.ts +7 -0
- package/lib/business/bilibili/index.js +7 -0
- package/lib/business/bilibili/qtparam.d.ts +13 -0
- package/lib/business/bilibili/qtparam.js +16 -0
- package/lib/business/bilibili/result.d.ts +6 -0
- package/lib/business/bilibili/result.js +36 -0
- package/lib/business/bilibili/sign/CorrespondPath.d.ts +1 -0
- package/lib/business/bilibili/sign/CorrespondPath.js +11 -0
- package/lib/business/bilibili/sign/wbi.d.ts +1 -0
- package/lib/business/bilibili/sign/wbi.js +56 -0
- package/lib/business/douyin/API.d.ts +37 -0
- package/lib/business/douyin/API.js +42 -0
- package/lib/business/douyin/getdata.d.ts +9 -0
- package/lib/business/douyin/getdata.js +119 -0
- package/lib/business/douyin/getid.d.ts +13 -0
- package/lib/business/douyin/getid.js +36 -0
- package/lib/business/douyin/index.d.ts +6 -0
- package/lib/business/douyin/index.js +6 -0
- package/lib/business/douyin/result.d.ts +6 -0
- package/lib/business/douyin/result.js +39 -0
- package/lib/business/douyin/sign/a_bougs.js +487 -0
- package/lib/business/douyin/sign/index.d.ts +8 -0
- package/lib/business/douyin/sign/index.js +29 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +113 -0
- package/lib/model/config.d.ts +70 -0
- package/lib/model/config.js +173 -0
- package/lib/model/index.d.ts +4 -0
- package/lib/model/index.js +4 -0
- package/lib/model/logger.d.ts +3 -0
- package/lib/model/logger.js +28 -0
- package/lib/model/networks.d.ts +38 -0
- package/lib/model/networks.js +224 -0
- package/lib/types/ConfigType.d.ts +10 -0
- package/lib/types/ConfigType.js +1 -0
- package/lib/types/DataType.d.ts +32 -0
- package/lib/types/DataType.js +1 -0
- package/lib/types/GetDataResponseType.d.ts +17 -0
- package/lib/types/GetDataResponseType.js +1 -0
- package/lib/types/NetworksConfigType.d.ts +30 -0
- package/lib/types/NetworksConfigType.js +1 -0
- package/lib/types/OptionsType.d.ts +66 -0
- package/lib/types/OptionsType.js +1 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
declare class Config {
|
|
3
|
+
config: any;
|
|
4
|
+
watcher: any;
|
|
5
|
+
constructor();
|
|
6
|
+
/** 初始化配置 */
|
|
7
|
+
initCfg(): void;
|
|
8
|
+
get douyin(): any;
|
|
9
|
+
get bilibili(): any;
|
|
10
|
+
/** 默认配置和用户配置 */
|
|
11
|
+
getDefOrConfig(name: string): any;
|
|
12
|
+
/** 默认配置 */
|
|
13
|
+
getdefSet(name: any): any;
|
|
14
|
+
/** 用户配置 */
|
|
15
|
+
getConfig(name: any): any;
|
|
16
|
+
/**
|
|
17
|
+
* 获取配置yaml
|
|
18
|
+
* @param type 默认跑配置-defSet,用户配置-config
|
|
19
|
+
* @param name 名称
|
|
20
|
+
*/
|
|
21
|
+
getYaml(type: string | undefined, name: any): any;
|
|
22
|
+
/** 监听配置文件 */
|
|
23
|
+
watch(file: string, name: string, type?: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* 修改设置
|
|
26
|
+
* @param {'douoyin','bilibili'} name 文件名
|
|
27
|
+
* @param {String} key 修改的key值
|
|
28
|
+
* @param {String|Number} value 修改的value值
|
|
29
|
+
* @param {'config'|'default_config'} type 配置文件或默认
|
|
30
|
+
*/
|
|
31
|
+
modify(name: string, key: string, value: any, type?: string): void;
|
|
32
|
+
mergeObjectsWithPriority(objA: any, objB: any): {
|
|
33
|
+
differences: boolean;
|
|
34
|
+
result: any;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* YamlReader类提供了对YAML文件的动态读写功能
|
|
39
|
+
*/
|
|
40
|
+
export declare class YamlReader {
|
|
41
|
+
filePath: string;
|
|
42
|
+
document: any;
|
|
43
|
+
/**
|
|
44
|
+
* 创建一个YamlReader实例。
|
|
45
|
+
* @param {string} filePath - 文件路径
|
|
46
|
+
*/
|
|
47
|
+
constructor(filePath: string);
|
|
48
|
+
/**
|
|
49
|
+
* 解析YAML文件并返回Document对象,保留注释。
|
|
50
|
+
* @returns {Document} 包含YAML数据和注释的Document对象
|
|
51
|
+
*/
|
|
52
|
+
parseDocument(): YAML.Document.Parsed<YAML.Alias.Parsed, true> | YAML.Document.Parsed<YAML.Scalar.Parsed, true> | YAML.Document.Parsed<YAML.YAMLMap.Parsed<YAML.ParsedNode, YAML.ParsedNode | null>, true> | YAML.Document.Parsed<YAML.YAMLSeq.Parsed<YAML.ParsedNode>, true>;
|
|
53
|
+
/**
|
|
54
|
+
* 修改指定参数的值。
|
|
55
|
+
* @param {string} key - 参数键名
|
|
56
|
+
* @param {any} value - 新的参数值
|
|
57
|
+
*/
|
|
58
|
+
set(key: any, value: any): void;
|
|
59
|
+
/**
|
|
60
|
+
* 从YAML文件中删除指定参数。
|
|
61
|
+
* @param {string} key - 要删除的参数键名
|
|
62
|
+
*/
|
|
63
|
+
rm(key: any): void;
|
|
64
|
+
/**
|
|
65
|
+
* 将更新后的Document对象写入YAML文件中。
|
|
66
|
+
*/
|
|
67
|
+
write(): void;
|
|
68
|
+
}
|
|
69
|
+
declare const _default: Config;
|
|
70
|
+
export default _default;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import YAML from 'yaml';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { logger } from '../model/index.js';
|
|
5
|
+
import chokidar from 'chokidar';
|
|
6
|
+
class Config {
|
|
7
|
+
config;
|
|
8
|
+
watcher;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.config = {};
|
|
11
|
+
/** 监听文件 */
|
|
12
|
+
this.watcher = { config: {}, defSet: {} };
|
|
13
|
+
this.initCfg();
|
|
14
|
+
}
|
|
15
|
+
/** 初始化配置 */
|
|
16
|
+
initCfg() {
|
|
17
|
+
const path = `${process.cwd()}/config/`;
|
|
18
|
+
if (!fs.existsSync(path))
|
|
19
|
+
fs.mkdirSync(path);
|
|
20
|
+
const pathDef = `${process.cwd()}/config/`;
|
|
21
|
+
const files = fs.readdirSync(pathDef).filter(file => file.endsWith('.yaml'));
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
if (!fs.existsSync(`${path}config.yaml`)) {
|
|
24
|
+
fs.copyFileSync(`${pathDef}${file}`, `${pathDef}config.yaml`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const config = YAML.parse(fs.readFileSync(`${path}${file}`, 'utf8'));
|
|
28
|
+
const defConfig = YAML.parse(fs.readFileSync(`${pathDef}${file}`, 'utf8'));
|
|
29
|
+
const { differences, result } = this.mergeObjectsWithPriority(config, defConfig);
|
|
30
|
+
if (differences) {
|
|
31
|
+
fs.copyFileSync(`${pathDef}${file}`, `${path}${file}`);
|
|
32
|
+
for (const key in result) {
|
|
33
|
+
this.modify(file.replace('.yaml', ''), key, result[key]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// 检查是否在 PM2 环境中运行
|
|
38
|
+
if (process.env.pm_id) {
|
|
39
|
+
// 如果是 PM2 运行,则执行 watch 方法
|
|
40
|
+
this.watch(`${path}${file}`, file.replace('.yaml', ''), 'config');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
get douyin() {
|
|
45
|
+
const cfg = this.getDefOrConfig('config');
|
|
46
|
+
return cfg.douyin;
|
|
47
|
+
}
|
|
48
|
+
get bilibili() {
|
|
49
|
+
const cfg = this.getDefOrConfig('config');
|
|
50
|
+
return cfg.bilibili;
|
|
51
|
+
}
|
|
52
|
+
/** 默认配置和用户配置 */
|
|
53
|
+
getDefOrConfig(name) {
|
|
54
|
+
const config = this.getConfig(name);
|
|
55
|
+
return config;
|
|
56
|
+
}
|
|
57
|
+
/** 默认配置 */
|
|
58
|
+
getdefSet(name) {
|
|
59
|
+
return this.getYaml('default_config', name);
|
|
60
|
+
}
|
|
61
|
+
/** 用户配置 */
|
|
62
|
+
getConfig(name) {
|
|
63
|
+
return this.getYaml('config', name);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 获取配置yaml
|
|
67
|
+
* @param type 默认跑配置-defSet,用户配置-config
|
|
68
|
+
* @param name 名称
|
|
69
|
+
*/
|
|
70
|
+
getYaml(type, name) {
|
|
71
|
+
const file = `${process.cwd()}/${type}/${name}.yaml`;
|
|
72
|
+
const key = `${type}.${name}`;
|
|
73
|
+
if (this.config['config.config'])
|
|
74
|
+
return this.config[key];
|
|
75
|
+
const cfg = YAML.parse(fs.readFileSync(file, 'utf8'));
|
|
76
|
+
this.watch(file, name, type);
|
|
77
|
+
return cfg;
|
|
78
|
+
}
|
|
79
|
+
/** 监听配置文件 */
|
|
80
|
+
watch(file, name, type = 'default_config') {
|
|
81
|
+
const key = `${type}.${name}`;
|
|
82
|
+
if (this.watcher[key])
|
|
83
|
+
return;
|
|
84
|
+
const watcher = chokidar.watch(file);
|
|
85
|
+
watcher.on('change', async (path) => {
|
|
86
|
+
delete this.config[key];
|
|
87
|
+
logger.mark(`[${process.cwd()}][修改配置文件][${type}][${name}]`);
|
|
88
|
+
});
|
|
89
|
+
this.watcher[key] = watcher;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 修改设置
|
|
93
|
+
* @param {'douoyin','bilibili'} name 文件名
|
|
94
|
+
* @param {String} key 修改的key值
|
|
95
|
+
* @param {String|Number} value 修改的value值
|
|
96
|
+
* @param {'config'|'default_config'} type 配置文件或默认
|
|
97
|
+
*/
|
|
98
|
+
modify(name, key, value, type = 'config') {
|
|
99
|
+
const path = `${process.cwd()}/config/${name}.yaml`;
|
|
100
|
+
new YamlReader(path).set(key, value);
|
|
101
|
+
delete this.config[`${type}.${name}`];
|
|
102
|
+
}
|
|
103
|
+
mergeObjectsWithPriority(objA, objB) {
|
|
104
|
+
let differences = false;
|
|
105
|
+
function customizer(objValue, srcValue, key, object, source, stack) {
|
|
106
|
+
if (_.isArray(objValue) && _.isArray(srcValue)) {
|
|
107
|
+
return objValue;
|
|
108
|
+
}
|
|
109
|
+
else if (_.isPlainObject(objValue) && _.isPlainObject(srcValue)) {
|
|
110
|
+
if (!_.isEqual(objValue, srcValue)) {
|
|
111
|
+
return _.mergeWith({}, objValue, srcValue, customizer);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (!_.isEqual(objValue, srcValue)) {
|
|
115
|
+
differences = true;
|
|
116
|
+
return objValue !== undefined ? objValue : srcValue;
|
|
117
|
+
}
|
|
118
|
+
return objValue !== undefined ? objValue : srcValue;
|
|
119
|
+
}
|
|
120
|
+
const result = _.mergeWith({}, objA, objB, customizer);
|
|
121
|
+
return {
|
|
122
|
+
differences,
|
|
123
|
+
result,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* YamlReader类提供了对YAML文件的动态读写功能
|
|
129
|
+
*/
|
|
130
|
+
export class YamlReader {
|
|
131
|
+
filePath;
|
|
132
|
+
document;
|
|
133
|
+
/**
|
|
134
|
+
* 创建一个YamlReader实例。
|
|
135
|
+
* @param {string} filePath - 文件路径
|
|
136
|
+
*/
|
|
137
|
+
constructor(filePath) {
|
|
138
|
+
this.filePath = filePath;
|
|
139
|
+
this.document = this.parseDocument();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 解析YAML文件并返回Document对象,保留注释。
|
|
143
|
+
* @returns {Document} 包含YAML数据和注释的Document对象
|
|
144
|
+
*/
|
|
145
|
+
parseDocument() {
|
|
146
|
+
const fileContent = fs.readFileSync(this.filePath, 'utf8');
|
|
147
|
+
return YAML.parseDocument(fileContent);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 修改指定参数的值。
|
|
151
|
+
* @param {string} key - 参数键名
|
|
152
|
+
* @param {any} value - 新的参数值
|
|
153
|
+
*/
|
|
154
|
+
set(key, value) {
|
|
155
|
+
this.document.set(key, value);
|
|
156
|
+
this.write();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 从YAML文件中删除指定参数。
|
|
160
|
+
* @param {string} key - 要删除的参数键名
|
|
161
|
+
*/
|
|
162
|
+
rm(key) {
|
|
163
|
+
this.document.delete(key);
|
|
164
|
+
this.write();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 将更新后的Document对象写入YAML文件中。
|
|
168
|
+
*/
|
|
169
|
+
write() {
|
|
170
|
+
fs.writeFileSync(this.filePath, this.document.toString(), 'utf8');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export default new Config();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import log4js from 'log4js';
|
|
2
|
+
log4js.configure({
|
|
3
|
+
appenders: {
|
|
4
|
+
console: {
|
|
5
|
+
type: 'stdout',
|
|
6
|
+
layout: {
|
|
7
|
+
type: 'pattern',
|
|
8
|
+
pattern: '%[[amagi][%d{hh:mm:ss.SSS}][%4.4p]%] %m',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
command: {
|
|
12
|
+
type: 'dateFile', // 可以是console,dateFile,file,Logstash等
|
|
13
|
+
filename: 'logs/command', // 将会按照filename和pattern拼接文件名
|
|
14
|
+
pattern: 'yyyy-MM-dd.log',
|
|
15
|
+
numBackups: 15,
|
|
16
|
+
alwaysIncludePattern: true,
|
|
17
|
+
layout: {
|
|
18
|
+
type: 'pattern',
|
|
19
|
+
pattern: '[%d{hh:mm:ss.SSS}][%4.4p] %m',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
categories: {
|
|
24
|
+
default: { appenders: ['console'], level: 'debug' },
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const logger = log4js.getLogger();
|
|
28
|
+
export default logger;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Response } from 'node-fetch';
|
|
2
|
+
import { NetworksConfigType } from '../types/index.js';
|
|
3
|
+
interface HeadersObject {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}
|
|
6
|
+
export default class Networks {
|
|
7
|
+
url: string | URL;
|
|
8
|
+
method: string;
|
|
9
|
+
Headers: any;
|
|
10
|
+
type: string;
|
|
11
|
+
body?: string;
|
|
12
|
+
fetch: any;
|
|
13
|
+
isGetResult: boolean;
|
|
14
|
+
timeout: number;
|
|
15
|
+
timer: NodeJS.Timeout | undefined;
|
|
16
|
+
data: {};
|
|
17
|
+
redirect: string;
|
|
18
|
+
constructor(data: NetworksConfigType);
|
|
19
|
+
get config(): NetworksConfigType;
|
|
20
|
+
getfetch(): Promise<Response | boolean>;
|
|
21
|
+
returnResult(): Promise<Response>;
|
|
22
|
+
/** 最终地址(跟随重定向) */
|
|
23
|
+
getLongLink(): Promise<string>;
|
|
24
|
+
/** 获取首个302 */
|
|
25
|
+
getLocation(): Promise<string>;
|
|
26
|
+
/** 获取数据并处理数据的格式化,默认json */
|
|
27
|
+
getData(new_fetch?: string): Promise<any | boolean>;
|
|
28
|
+
/** 获取响应头 */
|
|
29
|
+
getHeaders(): Promise<HeadersObject | null>;
|
|
30
|
+
/** 一次性获取响应头和响应体 */
|
|
31
|
+
getHeadersAndData(): Promise<object>;
|
|
32
|
+
Tojson(): Promise<any>;
|
|
33
|
+
ToText(): Promise<void>;
|
|
34
|
+
ToArrayBuffer(): Promise<void>;
|
|
35
|
+
ToBlob(): Promise<void>;
|
|
36
|
+
timeoutPromise(timeout: number): Promise<Response>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import fetch, { Response } from 'node-fetch';
|
|
2
|
+
import { logger } from '../model/index.js';
|
|
3
|
+
export default class Networks {
|
|
4
|
+
url;
|
|
5
|
+
method;
|
|
6
|
+
Headers;
|
|
7
|
+
type;
|
|
8
|
+
body;
|
|
9
|
+
fetch;
|
|
10
|
+
isGetResult;
|
|
11
|
+
timeout;
|
|
12
|
+
timer;
|
|
13
|
+
data;
|
|
14
|
+
redirect;
|
|
15
|
+
constructor(data) {
|
|
16
|
+
this.Headers = new Headers();
|
|
17
|
+
if (data.headers && Object.keys(data.headers).length > 0) {
|
|
18
|
+
for (const [key, value] of Object.entries(data.headers)) {
|
|
19
|
+
this.Headers.append(key, value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
this.Headers = {};
|
|
24
|
+
this.url = data.url || '';
|
|
25
|
+
this.type = data.type || 'json';
|
|
26
|
+
this.method = data.method || 'GET';
|
|
27
|
+
this.body = data.body || ''; // 用于POST请求
|
|
28
|
+
this.data = {};
|
|
29
|
+
this.timeout = data.timeout || 15000;
|
|
30
|
+
this.isGetResult = false;
|
|
31
|
+
this.timer = undefined;
|
|
32
|
+
this.redirect = 'follow'; // 默认跟随重定向
|
|
33
|
+
}
|
|
34
|
+
get config() {
|
|
35
|
+
let data = {
|
|
36
|
+
headers: this.Headers,
|
|
37
|
+
method: this.method,
|
|
38
|
+
};
|
|
39
|
+
if (this.method === 'POST') {
|
|
40
|
+
data = { ...data, body: JSON.stringify(this.body) || '' };
|
|
41
|
+
}
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
async getfetch() {
|
|
45
|
+
try {
|
|
46
|
+
const result = await this.returnResult();
|
|
47
|
+
if (result.status === 504) {
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
this.isGetResult = true;
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
logger.warn(error);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async returnResult() {
|
|
59
|
+
return await fetch(this.url, this.config);
|
|
60
|
+
}
|
|
61
|
+
/** 最终地址(跟随重定向) */
|
|
62
|
+
async getLongLink() {
|
|
63
|
+
try {
|
|
64
|
+
const result = await this.returnResult();
|
|
65
|
+
return result.url;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
logger.error(error);
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** 获取首个302 */
|
|
73
|
+
async getLocation() {
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(this.url, {
|
|
76
|
+
method: 'GET',
|
|
77
|
+
redirect: 'manual', // 不跟随重定向
|
|
78
|
+
});
|
|
79
|
+
// 取location返回
|
|
80
|
+
return response.headers.get('location');
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
logger.error(error);
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** 获取数据并处理数据的格式化,默认json */
|
|
88
|
+
async getData(new_fetch = '') {
|
|
89
|
+
try {
|
|
90
|
+
if (!new_fetch) {
|
|
91
|
+
const result = await this.returnResult();
|
|
92
|
+
if (result.status === 504) {
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
this.fetch = result;
|
|
96
|
+
this.isGetResult = true;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.fetch = new_fetch;
|
|
100
|
+
}
|
|
101
|
+
switch (this.type) {
|
|
102
|
+
case 'json':
|
|
103
|
+
await this.Tojson();
|
|
104
|
+
break;
|
|
105
|
+
case 'text':
|
|
106
|
+
await this.ToText();
|
|
107
|
+
break;
|
|
108
|
+
case 'arrayBuffer':
|
|
109
|
+
await this.ToArrayBuffer();
|
|
110
|
+
break;
|
|
111
|
+
case 'blob':
|
|
112
|
+
await this.ToBlob();
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
return this.fetch;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
logger.error(error);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** 获取响应头 */
|
|
123
|
+
async getHeaders() {
|
|
124
|
+
try {
|
|
125
|
+
this.fetch = await this.returnResult();
|
|
126
|
+
if (this.fetch) {
|
|
127
|
+
if (this.fetch.headers) {
|
|
128
|
+
const headers = this.fetch.headers;
|
|
129
|
+
const headersObject = {};
|
|
130
|
+
for (const [key, value] of headers.entries()) {
|
|
131
|
+
headersObject[key] = value;
|
|
132
|
+
}
|
|
133
|
+
return headersObject;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
logger.error('未获取到响应头');
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
logger.error('未获取到响应对象');
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
logger.error('获取响应头失败:', error);
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** 一次性获取响应头和响应体 */
|
|
151
|
+
async getHeadersAndData() {
|
|
152
|
+
try {
|
|
153
|
+
// 发起网络请求获取响应对象
|
|
154
|
+
this.fetch = await this.returnResult();
|
|
155
|
+
// 初始化响应头和响应数据
|
|
156
|
+
let headers = null;
|
|
157
|
+
let data = null;
|
|
158
|
+
if (this.fetch) {
|
|
159
|
+
// 获取响应头
|
|
160
|
+
if (this.fetch.headers) {
|
|
161
|
+
headers = {};
|
|
162
|
+
const fetchHeaders = this.fetch.headers;
|
|
163
|
+
for (const [key, value] of fetchHeaders.entries()) {
|
|
164
|
+
headers[key] = value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
logger.error('未获取到响应头');
|
|
169
|
+
}
|
|
170
|
+
// 获取响应数据
|
|
171
|
+
switch (this.type) {
|
|
172
|
+
case 'json':
|
|
173
|
+
data = await this.fetch.json();
|
|
174
|
+
break;
|
|
175
|
+
case 'text':
|
|
176
|
+
data = await this.fetch.text();
|
|
177
|
+
break;
|
|
178
|
+
case 'arrayBuffer':
|
|
179
|
+
data = await this.ToArrayBuffer();
|
|
180
|
+
break;
|
|
181
|
+
case 'blob':
|
|
182
|
+
data = await this.ToBlob();
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
logger.error('未获取到响应对象');
|
|
188
|
+
}
|
|
189
|
+
return { headers, data };
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
logger.error('获取响应头和数据失败:', error);
|
|
193
|
+
return { headers: null, data: null };
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async Tojson() {
|
|
197
|
+
if (this.fetch.headers.get('content-type').includes('json')) {
|
|
198
|
+
this.fetch = await this.fetch.json();
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.fetch = await this.fetch.text();
|
|
202
|
+
this.type = 'text';
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async ToText() {
|
|
206
|
+
this.fetch = await this.fetch.text();
|
|
207
|
+
}
|
|
208
|
+
async ToArrayBuffer() {
|
|
209
|
+
this.fetch = await this.fetch.arrayBuffer();
|
|
210
|
+
}
|
|
211
|
+
async ToBlob() {
|
|
212
|
+
this.fetch = await this.fetch.blob();
|
|
213
|
+
}
|
|
214
|
+
timeoutPromise(timeout) {
|
|
215
|
+
const controller = new AbortController();
|
|
216
|
+
return new Promise((resolve, reject) => {
|
|
217
|
+
this.timer = setTimeout(() => {
|
|
218
|
+
logger.mark('执行力');
|
|
219
|
+
controller.abort();
|
|
220
|
+
resolve(new Response('timeout', { status: 504, statusText: 'timeout' }));
|
|
221
|
+
}, timeout);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 抖音接口类型
|
|
3
|
+
*/
|
|
4
|
+
export declare const enum DouyinDataType {
|
|
5
|
+
二级评论数据 = "CommentReplyData",
|
|
6
|
+
用户主页数据 = "UserInfoData",
|
|
7
|
+
单个视频作品数据 = "VideoData",
|
|
8
|
+
评论数据 = "CommentData",
|
|
9
|
+
用户主页视频列表数据 = "UserVideosListData",
|
|
10
|
+
热点词数据 = "SuggestWordsData",
|
|
11
|
+
搜索数据 = "SearchData",
|
|
12
|
+
官方emoji数据 = "EmojiData",
|
|
13
|
+
动态表情数据 = "ExpressionPlusData",
|
|
14
|
+
音乐数据 = "MusicData",
|
|
15
|
+
图集作品数据 = "NoteData",
|
|
16
|
+
实况图片图集数据 = "LiveImageData"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* B站接口类型
|
|
20
|
+
*/
|
|
21
|
+
export declare const enum BilibiliDataType {
|
|
22
|
+
单个视频作品数据 = "VideoData",
|
|
23
|
+
评论数据 = "CommentData",
|
|
24
|
+
用户主页数据 = "UserInfoData",
|
|
25
|
+
用户主页动态列表数据 = "UserDynamicListData",
|
|
26
|
+
搜索数据 = "SearchData",
|
|
27
|
+
emoji数据 = "EmojiData",
|
|
28
|
+
番剧基本信息数据 = "BangumiVideoData",
|
|
29
|
+
番剧下载信息数据 = "BangumiVideoDownloadLinkData",
|
|
30
|
+
动态详情数据 = "DynamicInfoData",
|
|
31
|
+
动态卡片数据 = "DynamicCardData"
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type NetworksConfigType = {
|
|
2
|
+
/**
|
|
3
|
+
* 请求地址
|
|
4
|
+
*/
|
|
5
|
+
url?: string | URL;
|
|
6
|
+
/**
|
|
7
|
+
* 请求方法
|
|
8
|
+
*/
|
|
9
|
+
method?: string;
|
|
10
|
+
/**
|
|
11
|
+
* 请求头
|
|
12
|
+
*/
|
|
13
|
+
headers?: any;
|
|
14
|
+
/**
|
|
15
|
+
* 返回数据类型,默认json
|
|
16
|
+
*/
|
|
17
|
+
type?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 请求体
|
|
20
|
+
*/
|
|
21
|
+
body?: string;
|
|
22
|
+
/**
|
|
23
|
+
* 超时时间,单位毫秒
|
|
24
|
+
*/
|
|
25
|
+
timeout?: number;
|
|
26
|
+
/**
|
|
27
|
+
* 默认跟随重定向到: 'follow',不跟随: manual
|
|
28
|
+
*/
|
|
29
|
+
redirect?: RequestRedirect;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|