@oxiaom/adoremix 1.0.4 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxiaom/adoremix",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "AdoreMix broadcast server - cross-platform installer, runner and service manager",
5
5
  "bin": {
6
6
  "adoremix": "./bin/adoremix.js"
package/src/cli.js CHANGED
@@ -132,6 +132,40 @@ function buildProgram() {
132
132
  process.exitCode = code || 0;
133
133
  });
134
134
 
135
+ config
136
+ .command('preurl')
137
+ .description('配置设备拉资源用的 URL(默认 http://IP:12080/,CDN 加速改成域名)')
138
+ .option('--workdir <path>')
139
+ .option('--url <url>', '直接指定 URL(如 http://cdn.your.com/)')
140
+ .option('--no-interactive', '用本机 IP 自动生成')
141
+ .action(async (opts) => {
142
+ const net = require('./config/network');
143
+ const code = await net.setupPreurl(resolveWorkdir(opts.workdir), {
144
+ url: opts.url,
145
+ interactive: opts.interactive !== false
146
+ });
147
+ process.exitCode = code || 0;
148
+ });
149
+
150
+ config
151
+ .command('log')
152
+ .description('日志开关 isopenrizhi(开启会保存播放日志 + mp3,长期会占存储)')
153
+ .option('--workdir <path>')
154
+ .option('--enable', '开启日志')
155
+ .option('--disable', '关闭日志(默认)')
156
+ .option('--no-interactive', '不询问')
157
+ .action(async (opts) => {
158
+ const net = require('./config/network');
159
+ let enable;
160
+ if (opts.enable) enable = true;
161
+ else if (opts.disable) enable = false;
162
+ const code = await net.setupLog(resolveWorkdir(opts.workdir), {
163
+ enable,
164
+ interactive: opts.interactive !== false
165
+ });
166
+ process.exitCode = code || 0;
167
+ });
168
+
135
169
  const runner = require('./runner');
136
170
  const nativeRef = () => {
137
171
  try { return paths.loadNative(); }
@@ -4,7 +4,7 @@ module.exports = {
4
4
  Settings: {
5
5
  ISLOCALHOST: false,
6
6
  wbport: 6082,
7
- isopenrizhi: true,
7
+ isopenrizhi: false,
8
8
  exename: '',
9
9
  Meida_port: 6002,
10
10
  Meida_ip: '127.0.0.1',
@@ -10,6 +10,23 @@ const NET_KEYS = [
10
10
  'Settings.Fip'
11
11
  ];
12
12
 
13
+ const PREURL_KEY = 'Settings.preurl';
14
+ const HTTP_PORT_KEY = 'listener.port';
15
+
16
+ // 默认 preurl 格式:http://<IP>:<port>/
17
+ // 如果用户改成 CDN 域名(如 http://cdn.xxx.com/),改 IP 时不应该覆盖
18
+ function extractPreurlHost(preurl) {
19
+ if (!preurl) return null;
20
+ const m = String(preurl).match(/^https?:\/\/([^:/]+)/);
21
+ return m ? m[1] : null;
22
+ }
23
+
24
+ function isPreurlCdn(preurl) {
25
+ const host = extractPreurlHost(preurl);
26
+ if (!host) return false;
27
+ return !isValidIPv4(host); // 域名 = CDN,IP = 直连
28
+ }
29
+
13
30
  function listInterfaces() {
14
31
  const ifaces = os.networkInterfaces();
15
32
  const list = [];
@@ -109,6 +126,19 @@ async function setupNetwork(workdir, opts) {
109
126
  }
110
127
  logger.ok(`已设置 ${NET_KEYS.map(k => k.split('.')[1]).join(' / ')} = ${ip}`);
111
128
 
129
+ // 智能更新 preurl:如果是 IP 格式(直连),同步改;CDN 域名不动
130
+ const currentPreurl = cfg.getConfigValue(workdir, PREURL_KEY);
131
+ const port = cfg.getConfigValue(workdir, HTTP_PORT_KEY) || 12080;
132
+ if (currentPreurl && isPreurlCdn(currentPreurl)) {
133
+ logger.log('');
134
+ logger.log(`preurl 当前是 CDN/域名:${currentPreurl}(保留不覆盖)`);
135
+ logger.log(' 改 CDN 用:adoremix config preurl http://cdn.your.com/');
136
+ } else {
137
+ const newPreurl = `http://${ip}:${port}/`;
138
+ cfg.setConfigValue(workdir, PREURL_KEY, newPreurl);
139
+ logger.ok(`已同步更新 preurl = ${newPreurl}`);
140
+ }
141
+
112
142
  // 顺便显示当前端口配置,方便检查
113
143
  const ports = [
114
144
  ['listener.port', 'HTTP 网页'],
@@ -128,4 +158,101 @@ async function setupNetwork(workdir, opts) {
128
158
  return 0;
129
159
  }
130
160
 
131
- module.exports = { setupNetwork, listInterfaces, isValidIPv4, NET_KEYS };
161
+ async function setupLog(workdir, opts) {
162
+ opts = opts || {};
163
+ const cfg = require('./index');
164
+ const KEY = 'Settings.isopenrizhi';
165
+ let val;
166
+ if (opts.enable !== undefined) {
167
+ val = !!opts.enable;
168
+ } else if (opts.interactive === false) {
169
+ val = false;
170
+ } else {
171
+ const cur = cfg.getConfigValue(workdir, KEY);
172
+ logger.log('');
173
+ logger.log('=== 日志开关 (isopenrizhi) ===');
174
+ logger.log('开启后:');
175
+ logger.log(' • 记录所有播放日志');
176
+ logger.log(' • 实时喊话推流的语音/音频自动保存为 mp3');
177
+ logger.log('注意:长期开启会占用大量磁盘空间');
178
+ logger.log(`当前:${cur ? '开启' : '关闭'}`);
179
+ logger.log('');
180
+ const resp = await prompts({
181
+ type: 'toggle',
182
+ name: 'val',
183
+ message: '是否开启日志',
184
+ initial: !!cur,
185
+ active: '开启',
186
+ inactive: '关闭'
187
+ });
188
+ val = resp.val;
189
+ }
190
+ cfg.setConfigValue(workdir, KEY, val);
191
+ logger.ok(`isopenrizhi = ${val}`);
192
+ if (val) {
193
+ logger.warn('日志已开启,长期运行会占用磁盘,建议定期清理 tty/ 和 logs/');
194
+ }
195
+ logger.log('改完后记得:adoremix restart');
196
+ return 0;
197
+ }
198
+
199
+ async function setupPreurl(workdir, opts) {
200
+ opts = opts || {};
201
+ const cfg = require('./index');
202
+ const current = cfg.getConfigValue(workdir, PREURL_KEY);
203
+ const port = cfg.getConfigValue(workdir, HTTP_PORT_KEY) || 12080;
204
+ const ip = cfg.getConfigValue(workdir, 'Settings.LocalIP') || '127.0.0.1';
205
+
206
+ let url;
207
+ if (opts.url) {
208
+ url = opts.url;
209
+ } else if (opts.interactive === false) {
210
+ url = `http://${ip}:${port}/`;
211
+ } else {
212
+ logger.log('');
213
+ logger.log('=== preurl 配置(设备拉资源用的 URL)===');
214
+ logger.log('说明:');
215
+ logger.log(' • 直连:http://<本机IP>:<端口>/(默认)');
216
+ logger.log(' • CDN 加速:http://cdn.your.com/(设备从 CDN 拉资源)');
217
+ logger.log(` • 当前值:${current}`);
218
+ logger.log('');
219
+ const resp = await prompts({
220
+ type: 'select',
221
+ name: 'choice',
222
+ message: '选择 preurl 来源',
223
+ choices: [
224
+ { title: `用本机直连:http://${ip}:${port}/`, value: 'direct' },
225
+ { title: '🌐 手动输入 CDN/外网地址', value: 'custom' }
226
+ ]
227
+ });
228
+ if (resp.choice === 'direct') {
229
+ url = `http://${ip}:${port}/`;
230
+ } else if (resp.choice === 'custom') {
231
+ const r2 = await prompts({
232
+ type: 'text',
233
+ name: 'url',
234
+ message: '输入完整 URL(含 http(s):// 和末尾 /)',
235
+ initial: 'http://cdn.example.com/',
236
+ validate: v => /^https?:\/\/[^/]+\//.test(v) ? true : '格式:http(s)://域名或IP/'
237
+ });
238
+ url = r2.url;
239
+ } else {
240
+ return 1;
241
+ }
242
+ }
243
+ cfg.setConfigValue(workdir, PREURL_KEY, url);
244
+ logger.ok(`preurl = ${url}`);
245
+ logger.log('改完后记得:adoremix restart');
246
+ return 0;
247
+ }
248
+
249
+ module.exports = {
250
+ setupNetwork,
251
+ setupPreurl,
252
+ setupLog,
253
+ listInterfaces,
254
+ isValidIPv4,
255
+ isPreurlCdn,
256
+ NET_KEYS,
257
+ PREURL_KEY
258
+ };