@ikenxuan/amagi 2.1.1 → 2.1.2
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/getdata.js +1 -2
- package/lib/business/bilibili/getid.js +5 -4
- package/lib/business/bilibili/result.d.ts +2 -2
- package/lib/business/douyin/getdata.js +3 -0
- package/lib/business/douyin/getid.js +2 -1
- package/lib/business/douyin/result.d.ts +3 -3
- package/lib/business/douyin/result.js +9 -3
- package/lib/index.js +2 -2
- package/lib/model/index.d.ts +2 -1
- package/lib/model/index.js +2 -1
- package/lib/model/logger.d.ts +3 -0
- package/lib/model/logger.js +44 -0
- package/lib/model/networks.js +3 -2
- package/lib/server/listen.js +2 -1
- package/package.json +2 -1
|
@@ -102,8 +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
|
-
|
|
106
|
-
return null;
|
|
105
|
+
throw new Error(`响应数据失败!\n请求接口类型:${this.type}\n请求URL:${options.url}\n错误代码:${result.code},\n含义:${errorMessage}`);
|
|
107
106
|
}
|
|
108
107
|
else {
|
|
109
108
|
return result;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Networks } from '../../model/index.js';
|
|
1
|
+
import { Networks, logger } from '../../model/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* return aweme_id
|
|
4
4
|
* @param {string} url 分享连接
|
|
@@ -11,7 +11,7 @@ export default async function GetBilibiliID(url) {
|
|
|
11
11
|
case /video\/([A-Za-z0-9]+)/.test(longLink): {
|
|
12
12
|
const bvideoMatch = longLink.match(/video\/([A-Za-z0-9]+)/);
|
|
13
13
|
result = {
|
|
14
|
-
type: "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* BilibiliDataType
|
|
14
|
+
type: "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* BilibiliDataType.单个视频作品数据 */,
|
|
15
15
|
id: bvideoMatch ? bvideoMatch[1] : ''
|
|
16
16
|
};
|
|
17
17
|
break;
|
|
@@ -19,7 +19,7 @@ export default async function GetBilibiliID(url) {
|
|
|
19
19
|
case /play\/(\S+?)\??/.test(longLink): {
|
|
20
20
|
const playMatch = longLink.match(/play\/(\w+)/);
|
|
21
21
|
result = {
|
|
22
|
-
type: "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E" /* BilibiliDataType
|
|
22
|
+
type: "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E" /* BilibiliDataType.番剧基本信息数据 */,
|
|
23
23
|
id: playMatch ? playMatch[1] : ''
|
|
24
24
|
};
|
|
25
25
|
break;
|
|
@@ -29,7 +29,7 @@ export default async function GetBilibiliID(url) {
|
|
|
29
29
|
const opusMatch = longLink.match(/^https:\/\/www\.bilibili\.com\/opus\/(\d+)/);
|
|
30
30
|
const dynamic_id = tMatch || opusMatch;
|
|
31
31
|
result = {
|
|
32
|
-
type: "\u52A8\u6001\u8BE6\u60C5\u6570\u636E" /* BilibiliDataType
|
|
32
|
+
type: "\u52A8\u6001\u8BE6\u60C5\u6570\u636E" /* BilibiliDataType.动态详情数据 */,
|
|
33
33
|
dynamic_id: dynamic_id ? dynamic_id[1] : ''
|
|
34
34
|
};
|
|
35
35
|
break;
|
|
@@ -37,5 +37,6 @@ export default async function GetBilibiliID(url) {
|
|
|
37
37
|
default:
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
|
+
logger.mark(result);
|
|
40
41
|
return result;
|
|
41
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BilibiliDataType, BilibiliOptionsType, GetDataResponseType } from '../../types/index.js';
|
|
2
|
-
interface
|
|
2
|
+
interface configParams {
|
|
3
3
|
/** 请求数据的类型 */
|
|
4
4
|
type: keyof typeof BilibiliDataType;
|
|
5
5
|
/** B站用户ck */
|
|
@@ -11,5 +11,5 @@ interface resultParams {
|
|
|
11
11
|
* @param config
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
export default function BilibiliResult(config:
|
|
14
|
+
export default function BilibiliResult(config: configParams | undefined, options: BilibiliOptionsType): Promise<GetDataResponseType | any>;
|
|
15
15
|
export {};
|
|
@@ -125,6 +125,9 @@ export default class DouyinData {
|
|
|
125
125
|
}
|
|
126
126
|
async GlobalGetData(options) {
|
|
127
127
|
const ResponseData = await new Networks(options).getData();
|
|
128
|
+
if (ResponseData === '') {
|
|
129
|
+
throw new Error('获取响应数据失败!抖音ck可能已经失效!\n请求类型:' + this.type + '\n请求URL:' + options.url);
|
|
130
|
+
}
|
|
128
131
|
return ResponseData;
|
|
129
132
|
}
|
|
130
133
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Networks } from '../../model/index.js';
|
|
1
|
+
import { logger, Networks } from '../../model/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* return aweme_id
|
|
4
4
|
* @param {string} url 视频分享连接
|
|
@@ -32,5 +32,6 @@ export default async function GetDouyinID(url) {
|
|
|
32
32
|
default:
|
|
33
33
|
break;
|
|
34
34
|
}
|
|
35
|
+
logger.mark(result);
|
|
35
36
|
return result;
|
|
36
37
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DouyinDataType, DouyinOptionsType, GetDataResponseType } from '../../types/index.js';
|
|
2
|
-
interface
|
|
2
|
+
interface configParams {
|
|
3
3
|
/** 请求数据的类型 */
|
|
4
4
|
type: keyof typeof DouyinDataType;
|
|
5
|
-
/**
|
|
5
|
+
/** 抖音用户ck */
|
|
6
6
|
cookie: string;
|
|
7
7
|
}
|
|
8
|
-
export default function DouyinResult(config?:
|
|
8
|
+
export default function DouyinResult(config?: configParams, options?: DouyinOptionsType): Promise<GetDataResponseType>;
|
|
9
9
|
export {};
|
|
@@ -16,9 +16,15 @@ export default async function DouyinResult(config = { cookie: '' }, options = {}
|
|
|
16
16
|
case "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* DouyinDataType.单个视频作品数据 */:
|
|
17
17
|
case "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E" /* DouyinDataType.图集作品数据 */:
|
|
18
18
|
case "\u8BC4\u8BBA\u6570\u636E" /* DouyinDataType.评论数据 */: {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const hasaweme_id = options.aweme_id || null;
|
|
20
|
+
if (hasaweme_id) {
|
|
21
|
+
result = await new DouyinData(config.type, config.cookie).GetData({ aweme_id: options.aweme_id });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const defurl = options.url?.toString().match(/(http|https):\/\/.*\.(douyin|iesdouyin)\.com\/[^ ]+/g);
|
|
25
|
+
const iddata = await GetDouyinID(String(defurl));
|
|
26
|
+
result = await new DouyinData(config.type, config.cookie).GetData(iddata);
|
|
27
|
+
}
|
|
22
28
|
break;
|
|
23
29
|
}
|
|
24
30
|
default:
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@ const amagi = client;
|
|
|
15
15
|
*/
|
|
16
16
|
export const GetDouyinData = async (type, cookie = '', options = {}) => {
|
|
17
17
|
const data = await DouyinResult({ type, cookie }, options);
|
|
18
|
-
return data;
|
|
18
|
+
return data.data;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
*
|
|
@@ -26,5 +26,5 @@ export const GetDouyinData = async (type, cookie = '', options = {}) => {
|
|
|
26
26
|
*/
|
|
27
27
|
export const GetBilibiliData = async (type, cookie = '', options = {}) => {
|
|
28
28
|
const data = await BilibiliResult({ type, cookie }, options);
|
|
29
|
-
return data;
|
|
29
|
+
return data.data;
|
|
30
30
|
};
|
package/lib/model/index.d.ts
CHANGED
package/lib/model/index.js
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
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',
|
|
13
|
+
filename: 'logs/command',
|
|
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
|
+
pluginConsole: {
|
|
23
|
+
type: 'stdout',
|
|
24
|
+
layout: {
|
|
25
|
+
type: 'pattern',
|
|
26
|
+
pattern: '%[[%d{hh:mm:ss.SSS}][%4.4p][plugin]%] %m'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
pluginCommand: {
|
|
30
|
+
type: 'dateFile',
|
|
31
|
+
filename: 'logs/pluginCommand',
|
|
32
|
+
pattern: 'yyyy-MM-dd.log',
|
|
33
|
+
numBackups: 15,
|
|
34
|
+
alwaysIncludePattern: true,
|
|
35
|
+
layout: { type: 'pattern', pattern: '[%d{hh:mm:ss.SSS}][%4.4p] %m' }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
categories: {
|
|
39
|
+
default: { appenders: [ 'console', 'command' ], level: 'info' } // 添加default类别
|
|
40
|
+
},
|
|
41
|
+
pm2: true
|
|
42
|
+
})
|
|
43
|
+
const logger = log4js.getLogger()
|
|
44
|
+
export default logger
|
package/lib/model/networks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosError } from 'axios'
|
|
2
|
+
import logger from './logger.js'
|
|
2
3
|
export default class Networks {
|
|
3
4
|
url
|
|
4
5
|
method
|
|
@@ -47,7 +48,7 @@ export default class Networks {
|
|
|
47
48
|
return result
|
|
48
49
|
}
|
|
49
50
|
catch (error) {
|
|
50
|
-
|
|
51
|
+
logger.info(error)
|
|
51
52
|
return false
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -94,7 +95,7 @@ export default class Networks {
|
|
|
94
95
|
return result
|
|
95
96
|
}
|
|
96
97
|
if (result.status === 429) {
|
|
97
|
-
|
|
98
|
+
logger.error('HTTP 响应状态码: 429')
|
|
98
99
|
throw new Error('ratelimit triggered, 触发 https://www.douyin.com/ 的速率限制!!!')
|
|
99
100
|
}
|
|
100
101
|
this.axiosInstance = result
|
package/lib/server/listen.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logger } from '../model/index.js'
|
|
1
2
|
/**
|
|
2
3
|
* 启动本地 http 服务
|
|
3
4
|
* @param client Fastify 实例
|
|
@@ -8,6 +9,6 @@ export const StartClient = async (client, port) => {
|
|
|
8
9
|
return client.listen({ port: port, host: '::' }, (_err, _address) => {
|
|
9
10
|
if (_err)
|
|
10
11
|
client.log.error(_err)
|
|
11
|
-
|
|
12
|
+
logger.mark(`amagi server listening on ${port} port. API docs: https://amagi.apifox.cn`)
|
|
12
13
|
})
|
|
13
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikenxuan/amagi",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"axios": "^1.7.3",
|
|
33
33
|
"fastify": "^4.28.1",
|
|
34
|
+
"log4js": "6.9.0",
|
|
34
35
|
"md5": "^2.3.0",
|
|
35
36
|
"pino-pretty": "^11.2.2"
|
|
36
37
|
},
|