Skip to content

Commit

Permalink
feat: UpdateConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed May 17, 2024
1 parent 55e6439 commit 0358fe7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/common/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -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));
}
Expand Down Expand Up @@ -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));
}
}
}
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0358fe7

Please sign in to comment.