This commit is contained in:
手瓜一十雪
2025-02-08 17:34:31 +08:00
parent 404bfdd5e6
commit 93f78f4db5
3 changed files with 21 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ export const NapcatConfigSchema = Type.Object({
fileLogLevel: Type.String({ default: 'debug' }),
consoleLogLevel: Type.String({ default: 'info' }),
packetBackend: Type.String({ default: 'auto' }),
packetServer: Type.String({ default: '' })
packetServer: Type.String({ default: '' }),
});
export type NapcatConfig = Static<typeof NapcatConfigSchema>;

View File

@@ -28,6 +28,7 @@ export let WebUiConfig: WebUiConfigWrapper;
export let webUiPathWrapper: NapCatPathWrapper;
const MAX_PORT_TRY = 100;
import * as net from 'node:net';
import { WebUiDataRuntime } from './src/helper/Data';
export async function InitPort(parsedConfig: WebUiConfigType): Promise<[string, number, string]> {
try {
@@ -48,7 +49,20 @@ export async function InitWebUi(logger: LogWrapper, pathWrapper: NapCatPathWrapp
logger.log('[NapCat] [WebUi] Current WebUi is not run.');
return;
}
setTimeout(async () => {
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
if (autoLoginAccount) {
try {
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
if (!result) {
throw new Error(message);
}
console.log(`[NapCat] [WebUi] Auto login account: ${autoLoginAccount}`);
} catch (error) {
console.log(`[NapCat] [WebUi] Auto login account failed.` + error);
}
}
}, 30000);
// ------------注册中间件------------
// 使用express的json中间件
app.use(express.json());

View File

@@ -13,6 +13,7 @@ const WebUiConfigSchema = Type.Object({
port: Type.Number({ default: 6099 }),
token: Type.String({ default: 'napcat' }),
loginRate: Type.Number({ default: 10 }),
autoLoginAccount: Type.String({ default: '' }),
});
export type WebUiConfigType = Static<typeof WebUiConfigSchema>;
@@ -125,4 +126,8 @@ export class WebUiConfigWrapper {
public static GetWebUIFontPath(): string {
return resolve(webUiPathWrapper.configPath, './fonts/webui.woff');
}
public getAutoLoginAccount(): string | undefined {
return this.WebUiConfigData?.autoLoginAccount;
}
}