jsir 2.6.2 → 2.6.4
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/cmd/oaa.js +108 -43
- package/deps/room.js +41 -35
- package/deps/setting.js +1 -0
- package/deps/util.js +15 -11
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -173,6 +173,7 @@ async function start() {
|
|
|
173
173
|
checkWorkspaces()
|
|
174
174
|
initWorkspace()
|
|
175
175
|
|
|
176
|
+
await Room.initNodes();
|
|
176
177
|
await Room.syncSetting();
|
|
177
178
|
|
|
178
179
|
lastFilterArg = getConfig("lastFilterArg");
|
|
@@ -377,14 +378,23 @@ function closeRl() {
|
|
|
377
378
|
function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
378
379
|
if (!setting.enableNextLine) {
|
|
379
380
|
console.$log(warnStr("[warn]"), "NextLine Disabled");
|
|
380
|
-
|
|
381
|
+
resolve(null);
|
|
382
|
+
return;
|
|
381
383
|
}
|
|
382
|
-
end = trim(end)
|
|
383
384
|
if (!_haveWrapperInput) {
|
|
384
|
-
|
|
385
|
+
console.$error(errorStr("[error]"), "NextLine Blocked");
|
|
386
|
+
resolve(null);
|
|
387
|
+
return;
|
|
385
388
|
}
|
|
386
389
|
initRl(callback, promptStr, hidden);
|
|
387
|
-
|
|
390
|
+
let isJsirNext = !callback || callback === wrapperInput
|
|
391
|
+
if (!isJsirNext) {
|
|
392
|
+
_haveWrapperInput = false
|
|
393
|
+
}
|
|
394
|
+
if (isJsirNext) {
|
|
395
|
+
global.$newInput = true;
|
|
396
|
+
}
|
|
397
|
+
end = trim(end)
|
|
388
398
|
let inputStr = ''
|
|
389
399
|
let lineHandler = async line => {
|
|
390
400
|
let textLine = line
|
|
@@ -410,7 +420,7 @@ function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
|
410
420
|
inputStr = '.e ' + inputStr;
|
|
411
421
|
}
|
|
412
422
|
let pro = (callback || wrapperInput)(inputStr);
|
|
413
|
-
resolve
|
|
423
|
+
resolve(inputStr);
|
|
414
424
|
try {
|
|
415
425
|
await pro;
|
|
416
426
|
} finally {
|
|
@@ -476,6 +486,24 @@ function resetCmdMap(cmdMap = {}) {
|
|
|
476
486
|
_cmdMap = cmdMap;
|
|
477
487
|
}
|
|
478
488
|
|
|
489
|
+
function moveConfig(old, _new) {
|
|
490
|
+
let configDir = getConfigDir();
|
|
491
|
+
let uniqueOld = toUniqueName(old);
|
|
492
|
+
let uniqueNew = toUniqueName(_new);
|
|
493
|
+
|
|
494
|
+
let configFileOld = configDir + '/' + md5(uniqueOld) + '.json';
|
|
495
|
+
let configFileNew = configDir + '/' + md5(uniqueNew) + '.json';
|
|
496
|
+
if (fs.existsSync(configFileOld) && !fs.existsSync(configFileNew)) {
|
|
497
|
+
fs.renameSync(configFileOld, configFileNew)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
let configFileOldTest = configDir + '/' + md5(uniqueOld + '.test') + '.json';
|
|
501
|
+
let configFileNewTest = configDir + '/' + md5(uniqueNew + '.test') + '.json';
|
|
502
|
+
if (fs.existsSync(configFileOldTest) && !fs.existsSync(configFileNewTest)) {
|
|
503
|
+
fs.renameSync(configFileOldTest, configFileNewTest)
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
479
507
|
function rename(dir, oldName, newName) {
|
|
480
508
|
let old = dir + '/' + oldName;
|
|
481
509
|
let _new = dir + '/' + newName;
|
|
@@ -484,15 +512,7 @@ function rename(dir, oldName, newName) {
|
|
|
484
512
|
} else {
|
|
485
513
|
fs.renameSync(old, _new)
|
|
486
514
|
console.info(`${_new} renamed`)
|
|
487
|
-
|
|
488
|
-
let configDir = getConfigDir();
|
|
489
|
-
let uniqueOld = toUniqueName(old);
|
|
490
|
-
let uniqueNew = toUniqueName(_new);
|
|
491
|
-
let configFileOld = configDir + '/' + md5(uniqueOld) + '.json';
|
|
492
|
-
let configFileNew = configDir + '/' + md5(uniqueNew) + '.json';
|
|
493
|
-
if (fs.existsSync(configFileOld) && !fs.existsSync(configFileNew)) {
|
|
494
|
-
fs.renameSync(configFileOld, configFileNew)
|
|
495
|
-
}
|
|
515
|
+
moveConfig(old, _new);
|
|
496
516
|
}
|
|
497
517
|
resetCmdMap({
|
|
498
518
|
1: toUniqueName(_new)
|
|
@@ -578,12 +598,7 @@ async function wrapperInput(str) {
|
|
|
578
598
|
}
|
|
579
599
|
|
|
580
600
|
function wrapperAlias(str) {
|
|
581
|
-
let aliasMap =
|
|
582
|
-
try {
|
|
583
|
-
aliasMap = getConfig("alias");
|
|
584
|
-
} catch (e) {
|
|
585
|
-
console.$error("getAlias failed ", e);
|
|
586
|
-
}
|
|
601
|
+
let aliasMap = getConfig("alias");
|
|
587
602
|
if (!aliasMap || Object.keys(aliasMap).length <= 0) {
|
|
588
603
|
return str;
|
|
589
604
|
}
|
|
@@ -593,7 +608,6 @@ function wrapperAlias(str) {
|
|
|
593
608
|
|
|
594
609
|
async function _wrapperInput(str) {
|
|
595
610
|
_haveWrapperInput = true;
|
|
596
|
-
global.$newInput = true;
|
|
597
611
|
str = trim(str)
|
|
598
612
|
if (!str) {
|
|
599
613
|
return;
|
|
@@ -645,7 +659,7 @@ async function _wrapperInput(str) {
|
|
|
645
659
|
} else if (firstName === setting.exeKey) {
|
|
646
660
|
await runCmd(str)
|
|
647
661
|
} else if (firstName === setting.initKey) {
|
|
648
|
-
await runInit(uniqueName,
|
|
662
|
+
await runInit(uniqueName, enrichArgs(str).slice(1))
|
|
649
663
|
} else {
|
|
650
664
|
console.log(String(fs.readFileSync(path)));
|
|
651
665
|
}
|
|
@@ -655,20 +669,44 @@ async function _wrapperInput(str) {
|
|
|
655
669
|
}
|
|
656
670
|
}
|
|
657
671
|
|
|
658
|
-
async function runInit(uniqueName,
|
|
672
|
+
async function runInit(uniqueName, args) {
|
|
673
|
+
let arg = args[0]
|
|
659
674
|
if (arg === '-') {
|
|
660
675
|
await offServer(uniqueName)
|
|
661
676
|
} else {
|
|
662
|
-
await
|
|
677
|
+
let exportLib = await _requireSource(setting.defaultSpace, uniqueName, true);
|
|
678
|
+
if (typeof exportLib === "function") {
|
|
679
|
+
await execLibFn(exportLib, args)
|
|
680
|
+
} else if (exportLib && exportLib[arg]) {
|
|
681
|
+
await execLibFn(exportLib[arg], args.slice(1))
|
|
682
|
+
} else if (!arg || arg === '+') {
|
|
683
|
+
await joinServer(uniqueName, arg === '+', exportLib)
|
|
684
|
+
} else {
|
|
685
|
+
console.warn("no items")
|
|
686
|
+
}
|
|
663
687
|
}
|
|
664
688
|
}
|
|
665
689
|
|
|
666
|
-
async function
|
|
690
|
+
async function execLibFn(fn, fnArgs) {
|
|
691
|
+
for (let i = 0; i < fnArgs.length; i++) {
|
|
692
|
+
let item = fnArgs[i]
|
|
693
|
+
if (item.endsWith(' ')) {
|
|
694
|
+
fnArgs[i] = await evalText('return ' + item.trim())
|
|
695
|
+
} else {
|
|
696
|
+
fnArgs[i] = item.trim()
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
let result = await fn(...fnArgs);
|
|
700
|
+
if (vl(result)) {
|
|
701
|
+
console.log(result)
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
async function joinServer(uniqueName, isApi, exportLib) {
|
|
667
706
|
Room.onRoom();
|
|
668
707
|
if (!setting.serviceReg.test(uniqueName)) {
|
|
669
708
|
throw 'invalid service name';
|
|
670
709
|
}
|
|
671
|
-
let exportLib = await _requireSource(setting.defaultSpace, uniqueName, true);
|
|
672
710
|
let asyncFnSize = 0
|
|
673
711
|
for (let key of Object.keys(exportLib)) {
|
|
674
712
|
let val = exportLib[key];
|
|
@@ -1222,7 +1260,7 @@ const keywordDef = {
|
|
|
1222
1260
|
console.msg("config service offline")
|
|
1223
1261
|
} else if (_cmdMap[args[0]]){
|
|
1224
1262
|
let uniqueName = _cmdMap[args[0]];
|
|
1225
|
-
await eia(getEditor(), [`${getConfigDir()}/${md5(uniqueName)}.json`])
|
|
1263
|
+
await eia(getEditor(), [`${getConfigDir()}/${md5(uniqueName + (global.$TEST ? '.test':''))}.json`])
|
|
1226
1264
|
} else {
|
|
1227
1265
|
console.warn('invalid args')
|
|
1228
1266
|
}
|
|
@@ -1314,7 +1352,7 @@ const keywordDef = {
|
|
|
1314
1352
|
for (let un of [uniqueName, ...cmds]) {
|
|
1315
1353
|
let path = getFullPath(un);
|
|
1316
1354
|
let text = removeComment(String(fs.readFileSync(path)))
|
|
1317
|
-
let [space] = parseUniqueName(
|
|
1355
|
+
let [space] = parseUniqueName(un)
|
|
1318
1356
|
|
|
1319
1357
|
text = wrapperJsirText(text)
|
|
1320
1358
|
|
|
@@ -1448,7 +1486,7 @@ const keywordDef = {
|
|
|
1448
1486
|
} else {
|
|
1449
1487
|
let typeKey = getJsirTypeKey(parseUniqueName(cmds[0])[1]);
|
|
1450
1488
|
if (setting.initKey === typeKey) {
|
|
1451
|
-
await runInit(cmds[0], args
|
|
1489
|
+
await runInit(cmds[0], args.slice(1))
|
|
1452
1490
|
} else if (setting.exeKey === typeKey) {
|
|
1453
1491
|
await runScript(cmds[0], args.slice(1))
|
|
1454
1492
|
}
|
|
@@ -1540,15 +1578,49 @@ const keywordDef = {
|
|
|
1540
1578
|
debug: {
|
|
1541
1579
|
comment: 'debug mode',
|
|
1542
1580
|
exeFn: (args) => {
|
|
1543
|
-
if (
|
|
1544
|
-
|
|
1581
|
+
if ('+' === args[0]) {
|
|
1582
|
+
if (!global.$DEBUG) {
|
|
1583
|
+
global.$DEBUG = true;
|
|
1584
|
+
setTips("DEBUG", "DEBUG", () => delete global.$DEBUG);
|
|
1585
|
+
}
|
|
1586
|
+
} else if ('-' === args[0]) {
|
|
1587
|
+
if (global.$DEBUG) {
|
|
1588
|
+
delTips("DEBUG")
|
|
1589
|
+
}
|
|
1545
1590
|
} else {
|
|
1546
|
-
global.$DEBUG
|
|
1547
|
-
|
|
1591
|
+
if (global.$DEBUG) {
|
|
1592
|
+
delTips("DEBUG")
|
|
1593
|
+
} else {
|
|
1594
|
+
global.$DEBUG = true;
|
|
1595
|
+
setTips("DEBUG", "DEBUG", () => delete global.$DEBUG);
|
|
1596
|
+
}
|
|
1548
1597
|
}
|
|
1549
1598
|
},
|
|
1550
1599
|
short: 'D'
|
|
1551
1600
|
},
|
|
1601
|
+
test: {
|
|
1602
|
+
comment: 'test mode',
|
|
1603
|
+
exeFn: (args) => {
|
|
1604
|
+
if ('+' === args[0]) {
|
|
1605
|
+
if (!global.$TEST) {
|
|
1606
|
+
global.$TEST = true;
|
|
1607
|
+
setTips("TEST", "TEST", () => delete global.$TEST);
|
|
1608
|
+
}
|
|
1609
|
+
} else if ('-' === args[0]) {
|
|
1610
|
+
if (global.$TEST) {
|
|
1611
|
+
delTips("TEST")
|
|
1612
|
+
}
|
|
1613
|
+
} else {
|
|
1614
|
+
if (global.$TEST) {
|
|
1615
|
+
delTips("TEST")
|
|
1616
|
+
} else {
|
|
1617
|
+
global.$TEST = true;
|
|
1618
|
+
setTips("TEST", "TEST", () => delete global.$TEST);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
},
|
|
1622
|
+
short: 'T'
|
|
1623
|
+
},
|
|
1552
1624
|
room: {
|
|
1553
1625
|
comment: 'manage room ([node])',
|
|
1554
1626
|
exeFn: async (args) => {
|
|
@@ -1605,15 +1677,8 @@ function getQuickRunCmds(input, matchStr) {
|
|
|
1605
1677
|
} else if (input.startsWith("/")) {
|
|
1606
1678
|
matchStr = '/' + matchStr;
|
|
1607
1679
|
}
|
|
1608
|
-
return filterCmd(matchStr).filter(i =>
|
|
1609
|
-
|
|
1610
|
-
if (setting.serviceReg.test(i)) {
|
|
1611
|
-
types = [setting.exeKey, setting.initKey];
|
|
1612
|
-
} else {
|
|
1613
|
-
types = [setting.exeKey]
|
|
1614
|
-
}
|
|
1615
|
-
return types.includes(getJsirTypeKey(parseUniqueName(i)[1]))
|
|
1616
|
-
})
|
|
1680
|
+
return filterCmd(matchStr).filter(i =>
|
|
1681
|
+
[setting.exeKey, setting.initKey].includes(getJsirTypeKey(parseUniqueName(i)[1])))
|
|
1617
1682
|
}
|
|
1618
1683
|
|
|
1619
1684
|
async function preLoad(text, fnNameMatch, fn, packages = [], space) {
|
|
@@ -2207,7 +2272,7 @@ async function _requireSource(currSpace, cmdMatchStr, force = false) {
|
|
|
2207
2272
|
let typeKey = getJsirTypeKey(pair[1]);
|
|
2208
2273
|
if (typeKey === setting.initKey) {
|
|
2209
2274
|
let pair = parseUniqueName(uniqueName)
|
|
2210
|
-
if (
|
|
2275
|
+
if (global.$TEST || force) {
|
|
2211
2276
|
result = await evalText(text, uniqueName)
|
|
2212
2277
|
} else {
|
|
2213
2278
|
if (setting.serviceReg.test(uniqueName)) {
|
package/deps/room.js
CHANGED
|
@@ -8,10 +8,7 @@ const {setRoute, createSign} = require('../deps/server')
|
|
|
8
8
|
const roomDataFile = "jsirRoom.json"
|
|
9
9
|
const jsirNodesFile = "jsirNodes.json"
|
|
10
10
|
const roomTasksFile = "roomTasks.json"
|
|
11
|
-
const roomTasksLockKey = "LOCK_roomTasks.json"
|
|
12
11
|
const roomsDirLockKey = "RW_" + getRoomsDir();
|
|
13
|
-
const syncRoomsLockKey = "SyncRooms_" + getRoomsDir();
|
|
14
|
-
const syncConfigsLockKey = "SyncConfigs_" + getConfigDir();
|
|
15
12
|
const updateRoomInfoLockKey = "UPDATE_" + roomDataFile
|
|
16
13
|
const console = createConsole();
|
|
17
14
|
const setting = require('../deps/setting')
|
|
@@ -118,26 +115,36 @@ function getSelfIP(nodes) {
|
|
|
118
115
|
return ips[0] || '127.0.0.1'
|
|
119
116
|
}
|
|
120
117
|
|
|
121
|
-
async function
|
|
122
|
-
let resp = await e(`${tailscalePath} status`);
|
|
118
|
+
async function initNodes() {
|
|
123
119
|
let nodes = {}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
nodes[ss[
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
let configNodes = getConfig("nodes", []).map(trim).filter(i => i)
|
|
121
|
+
if (configNodes.length > 0) {
|
|
122
|
+
for (const node of configNodes) {
|
|
123
|
+
let ss = node.split("@").map(trim).filter(i => i);
|
|
124
|
+
nodes[ss[1]] = {}
|
|
125
|
+
if (ss.length > 1) {
|
|
126
|
+
nodes[ss[1]].account = ss[0]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
let resp = await e(`${tailscalePath} status`);
|
|
131
|
+
for (let line of resp.split("\n").map(trim)) {
|
|
132
|
+
let offline = line.indexOf('offline') !== -1
|
|
133
|
+
let ss = line.split(/\s+/);
|
|
134
|
+
if (/^\d+\.\d+\.\d+\.\d+$/.test(ss[0])) {
|
|
135
|
+
nodes[ss[0]] = {
|
|
136
|
+
name: ss[1],
|
|
137
|
+
offline,
|
|
138
|
+
account: ss[2]
|
|
139
|
+
}
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
|
-
|
|
143
|
+
setting.nodeMap = await fileJson("jsirNodes.json", obj => nodes);
|
|
136
144
|
}
|
|
137
145
|
|
|
138
146
|
async function updateRoomInfo() {
|
|
139
|
-
|
|
140
|
-
await fileJson("jsirNodes.json", obj => setting.nodeMap);
|
|
147
|
+
await initNodes();
|
|
141
148
|
let nodes = Object.keys(setting.nodeMap)
|
|
142
149
|
let ip = getSelfIP(nodes)
|
|
143
150
|
await fileJson(roomDataFile, async room => {
|
|
@@ -145,13 +152,9 @@ async function updateRoomInfo() {
|
|
|
145
152
|
jsirs: room.jsirs
|
|
146
153
|
}
|
|
147
154
|
// 设置roomName
|
|
148
|
-
|
|
149
|
-
if (!vl(room.name) || room.name !== name) {
|
|
150
|
-
room.name = name;
|
|
151
|
-
debug("set roomName", name)
|
|
152
|
-
}
|
|
155
|
+
room.name = setting.nodeMap[ip]?.name || os.hostname();
|
|
153
156
|
room.selfNode = ip;
|
|
154
|
-
room.lastUpdateTime =
|
|
157
|
+
room.lastUpdateTime = setting.roomTime
|
|
155
158
|
debug("init room", room.name)
|
|
156
159
|
|
|
157
160
|
await cleanRoom(room)
|
|
@@ -224,7 +227,6 @@ async function syncRooms() {
|
|
|
224
227
|
}
|
|
225
228
|
|
|
226
229
|
async function syncSetting() {
|
|
227
|
-
setting.nodeMap = await getTailscaleNodes();
|
|
228
230
|
let room = await fileJson(roomDataFile)
|
|
229
231
|
await fileLock(roomsDirLockKey, async () => await _syncSetting(room));
|
|
230
232
|
}
|
|
@@ -321,6 +323,7 @@ async function processTasks() {
|
|
|
321
323
|
}
|
|
322
324
|
|
|
323
325
|
async function initRoom() {
|
|
326
|
+
setting.roomTime = Date.now();
|
|
324
327
|
setting.nodeMap = await fileJson(jsirNodesFile);
|
|
325
328
|
let roomUpdateTouchTime = false;
|
|
326
329
|
await fileJson(roomDataFile, async room => {
|
|
@@ -329,18 +332,20 @@ async function initRoom() {
|
|
|
329
332
|
roomUpdateTouchTime = true;
|
|
330
333
|
}
|
|
331
334
|
})
|
|
332
|
-
if (defTasks) {
|
|
333
|
-
fileLock(roomTasksLockKey, processTasks, false)
|
|
334
|
-
}
|
|
335
|
-
|
|
336
335
|
if (roomUpdateTouchTime) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
336
|
+
fileLock(updateRoomInfoLockKey, async () => {
|
|
337
|
+
await updateRoomInfo()
|
|
338
|
+
let pros = []
|
|
339
|
+
pros.push(syncRooms())
|
|
340
|
+
if (setting.serviceFns[setting.configMainFnKey] && !getConfig("configMain")) {
|
|
341
|
+
pros.push(syncConfigs())
|
|
342
|
+
}
|
|
343
|
+
await Promise.all(pros);
|
|
344
|
+
}, false)
|
|
345
|
+
}
|
|
346
|
+
if (defTasks) {
|
|
347
|
+
await processTasks();
|
|
342
348
|
}
|
|
343
|
-
|
|
344
349
|
await syncSetting();
|
|
345
350
|
}
|
|
346
351
|
|
|
@@ -436,7 +441,7 @@ async function initRoomJsir(room) {
|
|
|
436
441
|
}, {}),
|
|
437
442
|
busy: await getEventLoopDelay() || (lastJsir ? lastJsir.busy:0),
|
|
438
443
|
back: isRunningInBackground(),
|
|
439
|
-
lastUpdateTime:
|
|
444
|
+
lastUpdateTime: setting.roomTime,
|
|
440
445
|
port: setting.server ? setting.server.address()?.port:null,
|
|
441
446
|
services: services,
|
|
442
447
|
newError: global.$newError,
|
|
@@ -595,5 +600,6 @@ module.exports = {
|
|
|
595
600
|
syncSetting,
|
|
596
601
|
reqNode,
|
|
597
602
|
reqFn,
|
|
598
|
-
localConfigs
|
|
603
|
+
localConfigs,
|
|
604
|
+
initNodes
|
|
599
605
|
}
|
package/deps/setting.js
CHANGED
package/deps/util.js
CHANGED
|
@@ -233,7 +233,12 @@ function createConfig(uniqueName) {
|
|
|
233
233
|
}
|
|
234
234
|
if (uniqueName) {
|
|
235
235
|
result.local = (key, defaultVal) => {
|
|
236
|
-
|
|
236
|
+
try {
|
|
237
|
+
return _getConfig(key, defaultVal, uniqueName);
|
|
238
|
+
} catch (e) {
|
|
239
|
+
console.$error(`getConfig [${uniqueName}] "${key}" failed`, e)
|
|
240
|
+
}
|
|
241
|
+
return defaultVal;
|
|
237
242
|
}
|
|
238
243
|
}
|
|
239
244
|
return result;
|
|
@@ -580,14 +585,8 @@ function trimEmptyLine(text) {
|
|
|
580
585
|
return lines.slice(start, end + 1).join('\n');
|
|
581
586
|
}
|
|
582
587
|
|
|
583
|
-
let defaultEditor = "vi";
|
|
584
588
|
function getEditor() {
|
|
585
|
-
|
|
586
|
-
defaultEditor = getConfig("defaultEditor", "vi");
|
|
587
|
-
} catch (e) {
|
|
588
|
-
console.$error('getEditor failed', e);
|
|
589
|
-
}
|
|
590
|
-
return defaultEditor
|
|
589
|
+
return getConfig("defaultEditor", "vi")
|
|
591
590
|
}
|
|
592
591
|
|
|
593
592
|
function timeStr(fmt, date) {
|
|
@@ -722,7 +721,7 @@ function createDirs(filePath) {
|
|
|
722
721
|
}
|
|
723
722
|
|
|
724
723
|
function createLimitLogger(fileName, {
|
|
725
|
-
maxChars =
|
|
724
|
+
maxChars = 128 * 1024 * 1024,
|
|
726
725
|
logInfo = true,
|
|
727
726
|
time = true,
|
|
728
727
|
error = false,
|
|
@@ -985,7 +984,12 @@ function aesDecipher(str, key){
|
|
|
985
984
|
}
|
|
986
985
|
|
|
987
986
|
function getConfig(key, defaultVal) {
|
|
988
|
-
|
|
987
|
+
try {
|
|
988
|
+
return _getConfig(key, defaultVal)
|
|
989
|
+
} catch (e) {
|
|
990
|
+
console.$error(`getConfig "${key}" failed`, e)
|
|
991
|
+
}
|
|
992
|
+
return defaultVal;
|
|
989
993
|
}
|
|
990
994
|
|
|
991
995
|
function getConfigDir() {
|
|
@@ -1030,7 +1034,7 @@ function _getConfig(key, defaultVal, uniqueName) {
|
|
|
1030
1034
|
let configInit = {}
|
|
1031
1035
|
let configFile = getLibDataDir() + '/config.json';
|
|
1032
1036
|
if (uniqueName) {
|
|
1033
|
-
configFile = getConfigDir() + "/" + md5(uniqueName) + ".json"
|
|
1037
|
+
configFile = getConfigDir() + "/" + md5(uniqueName + (global.$TEST ? ".test":"")) + ".json"
|
|
1034
1038
|
}
|
|
1035
1039
|
if (!fs.existsSync(configFile)) {
|
|
1036
1040
|
fs.writeFileSync(configFile, JSON.stringify(configInit, null, 2));
|