@ikenxuan/amagi 1.4.3 → 1.4.6
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 +15 -56
- package/lib/business/bilibili/API.d.ts +16 -34
- package/lib/business/bilibili/API.js +20 -8
- package/lib/business/bilibili/getdata.d.ts +1 -1
- package/lib/business/bilibili/getdata.js +15 -15
- package/lib/business/bilibili/qtparam.d.ts +1 -1
- package/lib/business/bilibili/qtparam.js +5 -5
- package/lib/business/bilibili/result.d.ts +2 -1
- package/lib/business/bilibili/result.js +7 -3
- package/lib/business/bilibili/sign/wbi.d.ts +1 -1
- package/lib/business/bilibili/sign/wbi.js +4 -5
- package/lib/business/douyin/API.d.ts +11 -31
- package/lib/business/douyin/API.js +1 -2
- package/lib/business/douyin/getdata.d.ts +1 -1
- package/lib/business/douyin/getdata.js +3 -3
- package/lib/business/douyin/result.d.ts +2 -1
- package/lib/business/douyin/result.js +5 -3
- package/lib/business/douyin/sign/a_bougs.d.ts +3 -0
- package/lib/business/douyin/sign/a_bougs.js +1 -1
- package/lib/business/douyin/sign/index.js +2 -2
- package/lib/business/index.d.ts +2 -0
- package/lib/business/index.js +2 -0
- package/lib/index.d.ts +7 -30
- package/lib/index.js +7 -113
- package/lib/model/index.d.ts +1 -2
- package/lib/model/index.js +1 -2
- package/lib/model/logger.d.ts +1 -2
- package/lib/model/logger.js +3 -27
- package/lib/model/networks.js +2 -2
- package/lib/server/client.d.ts +15 -0
- package/lib/server/client.js +105 -0
- package/lib/server/index.d.ts +2 -0
- package/lib/server/index.js +2 -0
- package/lib/server/listen.d.ts +14 -0
- package/lib/server/listen.js +9 -0
- package/lib/types/BilibiliAPIParams.d.ts +59 -0
- package/lib/types/DataType.d.ts +3 -1
- package/lib/types/DouyinAPIParams.d.ts +37 -0
- package/lib/types/DouyinAPIParams.js +1 -0
- package/lib/types/OptionsType.d.ts +4 -0
- package/lib/types/Request.d.ts +8 -0
- package/lib/types/Request.js +1 -0
- package/lib/types/index.d.ts +4 -1
- package/package.json +16 -12
- package/config/config.yaml +0 -5
- package/config/default_config.yaml +0 -5
- package/lib/app.js +0 -2
- package/lib/model/config.d.ts +0 -70
- package/lib/model/config.js +0 -173
- /package/lib/{app.d.ts → types/BilibiliAPIParams.js} +0 -0
package/lib/model/config.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
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();
|
|
File without changes
|