mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat: UpdateConfig
This commit is contained in:
parent
55e64395ed
commit
0358fe7620
@ -1,5 +1,6 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
import path from 'node:path';
|
||||
import fs from 'fs/promises';
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
@ -139,4 +140,17 @@ export function migrateConfig(oldConfig: any) {
|
||||
token: oldConfig.token,
|
||||
};
|
||||
return newConfig;
|
||||
}
|
||||
// 升级旧的配置到新的
|
||||
export async function UpdateConfig() {
|
||||
const configFiles = await fs.readdir(path.join(__dirname, 'config'));
|
||||
for (const file of configFiles) {
|
||||
if (file.match(/^onebot11_\d+.json$/)) {
|
||||
let CurrentConfig = JSON.parse(await fs.readFile(path.join(__dirname, 'config', file), 'utf8'));
|
||||
if (isValidOldConfig(CurrentConfig)) {
|
||||
let NewConfig = migrateConfig(CurrentConfig);
|
||||
await fs.writeFile(path.join(__dirname, 'config', file), JSON.stringify(NewConfig, null, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,10 +8,14 @@ import { log, logDebug, logError, LogLevel, setLogLevel } from '@/common/utils/l
|
||||
import { NapCatOnebot11 } from '@/onebot11/main';
|
||||
import { InitWebUi } from './webui/index';
|
||||
import { WebUiDataRuntime } from './webui/src/helper/Data';
|
||||
import { UpdateConfig } from './common/utils/helper';
|
||||
program
|
||||
.option('-q, --qq <type>', 'QQ号')
|
||||
.parse(process.argv);
|
||||
|
||||
// 无缝升级旧的配置到新的
|
||||
UpdateConfig().catch(logError);
|
||||
//
|
||||
InitWebUi();
|
||||
const cmdOptions = program.opts();
|
||||
// console.log(process.argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user