mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: log config
This commit is contained in:
parent
033a7bffb3
commit
6f2be3ed30
@ -1,7 +1,7 @@
|
|||||||
import express, { Express, Request, Response } from 'express';
|
import express, { Express, Request, Response } from 'express';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import { log } from '../utils/log';
|
import { log, logDebug, logError } from '../utils/log';
|
||||||
import { ob11Config } from '@/onebot11/config';
|
import { ob11Config } from '@/onebot11/config';
|
||||||
|
|
||||||
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
||||||
@ -23,7 +23,7 @@ export abstract class HttpServerBase {
|
|||||||
// 调用原始的express.json()处理器
|
// 调用原始的express.json()处理器
|
||||||
originalJson(req, res, (err) => {
|
originalJson(req, res, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log('Error parsing JSON:', err);
|
logError('Error parsing JSON:', err);
|
||||||
return res.status(400).send('Invalid JSON');
|
return res.status(400).send('Invalid JSON');
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
@ -37,14 +37,14 @@ export abstract class HttpServerBase {
|
|||||||
const authHeader = req.get('authorization');
|
const authHeader = req.get('authorization');
|
||||||
if (authHeader) {
|
if (authHeader) {
|
||||||
clientToken = authHeader.split('Bearer ').pop() || '';
|
clientToken = authHeader.split('Bearer ').pop() || '';
|
||||||
log('receive http header token', clientToken);
|
logDebug('receive http header token', clientToken);
|
||||||
} else if (req.query.access_token) {
|
} else if (req.query.access_token) {
|
||||||
if (Array.isArray(req.query.access_token)) {
|
if (Array.isArray(req.query.access_token)) {
|
||||||
clientToken = req.query.access_token[0].toString();
|
clientToken = req.query.access_token[0].toString();
|
||||||
} else {
|
} else {
|
||||||
clientToken = req.query.access_token.toString();
|
clientToken = req.query.access_token.toString();
|
||||||
}
|
}
|
||||||
log('receive http url token', clientToken);
|
logDebug('receive http url token', clientToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverToken && clientToken != serverToken) {
|
if (serverToken && clientToken != serverToken) {
|
||||||
@ -60,7 +60,7 @@ export abstract class HttpServerBase {
|
|||||||
});
|
});
|
||||||
this.listen(port);
|
this.listen(port);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
log('HTTP服务启动失败', e.toString());
|
logError('HTTP服务启动失败', e.toString());
|
||||||
// llonebotError.httpServerError = "HTTP服务启动失败, " + e.toString()
|
// llonebotError.httpServerError = "HTTP服务启动失败, " + e.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ export abstract class HttpServerBase {
|
|||||||
// @ts-expect-error wait fix
|
// @ts-expect-error wait fix
|
||||||
if (!this.expressAPP[method]) {
|
if (!this.expressAPP[method]) {
|
||||||
const err = `${this.name} register router failed,${method} not exist`;
|
const err = `${this.name} register router failed,${method} not exist`;
|
||||||
log(err);
|
logError(err);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// @ts-expect-error wait fix
|
// @ts-expect-error wait fix
|
||||||
@ -99,7 +99,7 @@ export abstract class HttpServerBase {
|
|||||||
} else if (req.query) {
|
} else if (req.query) {
|
||||||
payload = { ...req.query, ...req.body };
|
payload = { ...req.query, ...req.body };
|
||||||
}
|
}
|
||||||
log('收到http请求', url, payload);
|
logDebug('收到http请求', url, payload);
|
||||||
try {
|
try {
|
||||||
res.send(await handler(res, payload));
|
res.send(await handler(res, payload));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -11,6 +11,11 @@ export class ConfigBase<T>{
|
|||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getConfigDir(){
|
||||||
|
const configDir = path.resolve(__dirname, 'config');
|
||||||
|
fs.mkdirSync(configDir, { recursive: true });
|
||||||
|
return configDir;
|
||||||
|
}
|
||||||
getConfigPath(): string {
|
getConfigPath(): string {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import fs from 'fs/promises';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { postLoginStatus } from '@/common/utils/umami';
|
import { postLoginStatus } from '@/common/utils/umami';
|
||||||
import { checkVersion } from '@/common/utils/version';
|
import { checkVersion } from '@/common/utils/version';
|
||||||
import { log, logError, LogLevel, setLogLevel } from '@/common/utils/log';
|
import { log, logDebug, logError, LogLevel, setLogLevel } from '@/common/utils/log';
|
||||||
import { NapCatOnebot11 } from '@/onebot11/main';
|
import { NapCatOnebot11 } from '@/onebot11/main';
|
||||||
|
|
||||||
program
|
program
|
||||||
@ -28,7 +28,7 @@ checkVersion().then((remoteVersion: string) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log('[NapCat] 当前已是最新版本');
|
logDebug('[NapCat] 当前已是最新版本');
|
||||||
return;
|
return;
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logError('[NapCat] 检测更新失败');
|
logError('[NapCat] 检测更新失败');
|
||||||
@ -40,13 +40,12 @@ napCatCore.onLoginSuccess(() => {
|
|||||||
});
|
});
|
||||||
const showQRCode = (qrCodeData: { url: string, base64: string, buffer: Buffer }) => {
|
const showQRCode = (qrCodeData: { url: string, base64: string, buffer: Buffer }) => {
|
||||||
log('请扫描下面的二维码,然后在手Q上授权登录:');
|
log('请扫描下面的二维码,然后在手Q上授权登录:');
|
||||||
log('二维码解码URL:', qrCodeData.url);
|
|
||||||
const qrcodePath = path.join(__dirname, 'qrcode.png');
|
const qrcodePath = path.join(__dirname, 'qrcode.png');
|
||||||
|
qrcode.generate(qrCodeData.url, { small: true }, (res) => {
|
||||||
|
log(`${res}\n二维码解码URL: ${qrCodeData.url}\n如果控制台二维码无法扫码,可以复制解码url到二维码生成网站生成二维码再扫码,也可以打开下方的二维码路径图片进行扫码`);
|
||||||
fs.writeFile(qrcodePath, qrCodeData.buffer).then(() => {
|
fs.writeFile(qrcodePath, qrCodeData.buffer).then(() => {
|
||||||
log('二维码已保存到', qrcodePath);
|
log('二维码已保存到', qrcodePath);
|
||||||
});
|
});
|
||||||
qrcode.generate(qrCodeData.url, { small: true }, (res) => {
|
|
||||||
log('\n' + res);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const quickLoginQQ = cmdOptions.qq;
|
const quickLoginQQ = cmdOptions.qq;
|
||||||
|
@ -27,8 +27,6 @@ export interface OB11Config {
|
|||||||
save(config: OB11Config): void;
|
save(config: OB11Config): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ob11ConfigDir = path.resolve(__dirname, 'config');
|
|
||||||
fs.mkdirSync(ob11ConfigDir, { recursive: true });
|
|
||||||
|
|
||||||
class Config extends ConfigBase<OB11Config> implements OB11Config {
|
class Config extends ConfigBase<OB11Config> implements OB11Config {
|
||||||
httpPort: number = 3000;
|
httpPort: number = 3000;
|
||||||
@ -49,7 +47,7 @@ class Config extends ConfigBase<OB11Config> implements OB11Config {
|
|||||||
token = '';
|
token = '';
|
||||||
|
|
||||||
getConfigPath() {
|
getConfigPath() {
|
||||||
return path.join(ob11ConfigDir, `onebot11_${selfInfo.uin}.json`);
|
return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ export class NapCatOnebot11 {
|
|||||||
WebSocket反向服务 ${ob11Config.enableWsReverse ? '已启动' : '未启动'}, 反向地址: ${ob11Config.wsReverseUrls}
|
WebSocket反向服务 ${ob11Config.enableWsReverse ? '已启动' : '未启动'}, 反向地址: ${ob11Config.wsReverseUrls}
|
||||||
`;
|
`;
|
||||||
log(serviceInfo);
|
log(serviceInfo);
|
||||||
NTQQUserApi.getUserDetailInfo(selfInfo.uin).then(user => {
|
NTQQUserApi.getUserDetailInfo(selfInfo.uid).then(user => {
|
||||||
selfInfo.nick = user.nick;
|
selfInfo.nick = user.nick;
|
||||||
}).catch(logError);
|
}).catch(logError);
|
||||||
if (ob11Config.enableHttp) {
|
if (ob11Config.enableHttp) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user