@ikenxuan/amagi 1.5.8 → 1.5.9
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 +5 -6
- package/lib/business/bilibili/getdata.js +2 -2
- package/lib/model/index.d.ts +1 -2
- package/lib/model/index.js +1 -2
- package/lib/model/networks.js +10 -11
- package/lib/server/client.js +19 -1
- package/lib/server/listen.js +2 -3
- package/package.json +3 -4
- package/lib/model/logger.d.ts +0 -3
- package/lib/model/logger.js +0 -28
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
1
|
# amagi(泥干嘛哈哈
|
|
2
|
+
|
|
4
3
|
* 热门平台视频解析 API 基于 Node.js 的实现,支持最低node版本为 v16
|
|
5
4
|
* 抖音、B站
|
|
6
5
|
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
7
10
|
## 使用
|
|
8
11
|
```
|
|
9
12
|
pnpm add @ikenxuan/amagi
|
|
@@ -24,10 +27,6 @@ await StartClient(client, { port: 4567 })
|
|
|
24
27
|
## 开发构建
|
|
25
28
|
> Node.js版本 <= v18.20.4
|
|
26
29
|
|
|
27
|
-
* 克隆仓库
|
|
28
|
-
```
|
|
29
|
-
git clone git@github.com:ikenxuan/amagi.git
|
|
30
|
-
```
|
|
31
30
|
* 安装依赖
|
|
32
31
|
```
|
|
33
32
|
pnpm install
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BiLiBiLiAPI, qtparam, wbi_sign } from '../../business/bilibili/index.js';
|
|
2
|
-
import { Networks
|
|
2
|
+
import { Networks } from '../../model/index.js';
|
|
3
3
|
export default class BilibiliData {
|
|
4
4
|
type;
|
|
5
5
|
headers;
|
|
@@ -102,7 +102,7 @@ export default class BilibiliData {
|
|
|
102
102
|
const result = await new Networks(options).getData();
|
|
103
103
|
if (result && result.code !== 0) {
|
|
104
104
|
const errorMessage = errorMap[result.code] || '未知错误';
|
|
105
|
-
|
|
105
|
+
console.error(`响应数据失败!\n请求接口类型:${this.type}\n请求URL:${options.url}\n错误代码:${result.code},\n含义:${errorMessage}`);
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
108
108
|
else {
|
package/lib/model/index.d.ts
CHANGED
package/lib/model/index.js
CHANGED
package/lib/model/networks.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '../model/index.js';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
export default class Networks {
|
|
4
3
|
url;
|
|
@@ -48,7 +47,7 @@ export default class Networks {
|
|
|
48
47
|
return result;
|
|
49
48
|
}
|
|
50
49
|
catch (error) {
|
|
51
|
-
|
|
50
|
+
console.info(error);
|
|
52
51
|
return false;
|
|
53
52
|
}
|
|
54
53
|
}
|
|
@@ -62,7 +61,7 @@ export default class Networks {
|
|
|
62
61
|
return result.request.res.responseUrl; // axios中获取最终的请求URL
|
|
63
62
|
}
|
|
64
63
|
catch (error) {
|
|
65
|
-
|
|
64
|
+
console.error(error);
|
|
66
65
|
return '';
|
|
67
66
|
}
|
|
68
67
|
}
|
|
@@ -78,7 +77,7 @@ export default class Networks {
|
|
|
78
77
|
return response.headers['location'];
|
|
79
78
|
}
|
|
80
79
|
catch (error) {
|
|
81
|
-
|
|
80
|
+
console.error(error);
|
|
82
81
|
return '';
|
|
83
82
|
}
|
|
84
83
|
}
|
|
@@ -91,7 +90,7 @@ export default class Networks {
|
|
|
91
90
|
return result;
|
|
92
91
|
}
|
|
93
92
|
if (result.status === 429) {
|
|
94
|
-
|
|
93
|
+
console.warn('HTTP 响应状态码: 429');
|
|
95
94
|
throw new Error('ratelimit triggered, 触发 https://www.douyin.com/ 的速率限制!!!');
|
|
96
95
|
}
|
|
97
96
|
this.axiosInstance = result;
|
|
@@ -118,7 +117,7 @@ export default class Networks {
|
|
|
118
117
|
return this.axiosInstance;
|
|
119
118
|
}
|
|
120
119
|
catch (error) {
|
|
121
|
-
|
|
120
|
+
console.error(error);
|
|
122
121
|
return false;
|
|
123
122
|
}
|
|
124
123
|
}
|
|
@@ -131,17 +130,17 @@ export default class Networks {
|
|
|
131
130
|
return this.axiosInstance.headers;
|
|
132
131
|
}
|
|
133
132
|
else {
|
|
134
|
-
|
|
133
|
+
console.error('未获取到响应头');
|
|
135
134
|
return null;
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
else {
|
|
139
|
-
|
|
138
|
+
console.error('未获取到响应对象');
|
|
140
139
|
return null;
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
catch (error) {
|
|
144
|
-
|
|
143
|
+
console.error('获取响应头失败:', error);
|
|
145
144
|
return null;
|
|
146
145
|
}
|
|
147
146
|
}
|
|
@@ -170,12 +169,12 @@ export default class Networks {
|
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
else {
|
|
173
|
-
|
|
172
|
+
console.error('未获取到响应对象');
|
|
174
173
|
}
|
|
175
174
|
return { headers, data };
|
|
176
175
|
}
|
|
177
176
|
catch (error) {
|
|
178
|
-
|
|
177
|
+
console.error('获取响应头和数据失败:', error);
|
|
179
178
|
return { headers: null, data: null };
|
|
180
179
|
}
|
|
181
180
|
}
|
package/lib/server/client.js
CHANGED
|
@@ -20,7 +20,25 @@ export class client {
|
|
|
20
20
|
* @returns fastify 实例
|
|
21
21
|
*/
|
|
22
22
|
async initServer (log = false) {
|
|
23
|
-
const client = fastify({
|
|
23
|
+
const client = fastify({
|
|
24
|
+
logger: log && {
|
|
25
|
+
transport: {
|
|
26
|
+
target: 'pino-pretty',
|
|
27
|
+
options: {
|
|
28
|
+
colorize: true,
|
|
29
|
+
translateTime: 'yyyy-MM-dd HH:mm:ss',
|
|
30
|
+
ignore: 'pid,hostname,reqId,res,responseTime,req.hostname,req.method,req.remotePort',
|
|
31
|
+
messageFormat: '{msg}'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
client.get('/', async (_request, reply) => {
|
|
37
|
+
reply.redirect('https://amagi.apifox.cn', 301);
|
|
38
|
+
});
|
|
39
|
+
client.get('/docs', async (_request, reply) => {
|
|
40
|
+
reply.redirect('https://amagi.apifox.cn', 301);
|
|
41
|
+
});
|
|
24
42
|
client.get('/api/douyin/aweme', async (request, reply) => {
|
|
25
43
|
const url = request.query.url;
|
|
26
44
|
reply.type('application/json').send(await new DouyinResult("VideoData" /* DouyinDataType['单个视频作品数据'] */, this.douyin).result({ url }));
|
package/lib/server/listen.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '../model/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* 启动 fastify 实例
|
|
4
3
|
* @param client fastify 实例
|
|
@@ -8,7 +7,7 @@ import { logger } from '../model/index.js';
|
|
|
8
7
|
export const StartClient = async (client, options) => {
|
|
9
8
|
return client.listen({ port: options.port, host: '::' }, (_err, _address) => {
|
|
10
9
|
if (_err)
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
client.log.error(_err);
|
|
11
|
+
console.log(`amagi server listening on ${options.port} port. API docs: https://amagi.apifox.cn`);
|
|
13
12
|
});
|
|
14
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikenxuan/amagi",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -34,9 +34,8 @@
|
|
|
34
34
|
"chokidar": "^3.6.0",
|
|
35
35
|
"fastify": "^4.28.1",
|
|
36
36
|
"lodash": "4.17.21",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"md5": "^2.3.0"
|
|
37
|
+
"md5": "^2.3.0",
|
|
38
|
+
"pino-pretty": "^11.2.2"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@types/lodash": "latest",
|
package/lib/model/logger.d.ts
DELETED
package/lib/model/logger.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import log from 'loglevel';
|
|
3
|
-
import prefix from 'loglevel-plugin-prefix';
|
|
4
|
-
const colors = {
|
|
5
|
-
TRACE: chalk.magenta,
|
|
6
|
-
DEBUG: chalk.cyan,
|
|
7
|
-
INFO: chalk.blue,
|
|
8
|
-
WARN: chalk.yellow,
|
|
9
|
-
ERROR: chalk.red
|
|
10
|
-
};
|
|
11
|
-
prefix.reg(log);
|
|
12
|
-
log.enableAll();
|
|
13
|
-
prefix.apply(log, {
|
|
14
|
-
format (level, name, timestamp) {
|
|
15
|
-
const levelKey = level.toUpperCase();
|
|
16
|
-
if (!(levelKey in colors)) {
|
|
17
|
-
throw new Error(`Invalid log level: ${levelKey}`);
|
|
18
|
-
}
|
|
19
|
-
return `${chalk.gray(`[${timestamp}]`)} ${colors[levelKey](level)} ${chalk.green(`${name}:`)}`;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
prefix.apply(log.getLogger('critical'), {
|
|
23
|
-
format (level, name, timestamp) {
|
|
24
|
-
return chalk.red.bold(`[${timestamp}] ${level} ${name}:`);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const logger = log;
|
|
28
|
-
export default logger;
|