mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: data recv
This commit is contained in:
@@ -32,8 +32,10 @@
|
|||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
"@types/multer": "^1.4.12",
|
"@types/multer": "^1.4.12",
|
||||||
"@types/node": "^22.0.1",
|
"@types/node": "^22.0.1",
|
||||||
|
"@types/on-finished": "^2.3.4",
|
||||||
"@types/qrcode-terminal": "^0.12.2",
|
"@types/qrcode-terminal": "^0.12.2",
|
||||||
"@types/react-color": "^3.0.13",
|
"@types/react-color": "^3.0.13",
|
||||||
|
"@types/type-is": "^1.6.7",
|
||||||
"@types/ws": "^8.5.12",
|
"@types/ws": "^8.5.12",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.3.0",
|
"@typescript-eslint/eslint-plugin": "^8.3.0",
|
||||||
"@typescript-eslint/parser": "^8.3.0",
|
"@typescript-eslint/parser": "^8.3.0",
|
||||||
|
@@ -9,7 +9,8 @@ import { HttpServerConfig } from '@/onebot/config/config';
|
|||||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
import { IOB11NetworkAdapter } from '@/onebot/network/adapter';
|
import { IOB11NetworkAdapter } from '@/onebot/network/adapter';
|
||||||
import json5 from 'json5';
|
import json5 from 'json5';
|
||||||
|
import { isFinished } from 'on-finished';
|
||||||
|
import typeis from 'type-is';
|
||||||
export class OB11HttpServerAdapter extends IOB11NetworkAdapter<HttpServerConfig> {
|
export class OB11HttpServerAdapter extends IOB11NetworkAdapter<HttpServerConfig> {
|
||||||
private app: Express | undefined;
|
private app: Express | undefined;
|
||||||
private server: http.Server | undefined;
|
private server: http.Server | undefined;
|
||||||
@@ -45,13 +46,6 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter<HttpServerConfig>
|
|||||||
this.app = undefined;
|
this.app = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private isFinished(req: Request): boolean {
|
|
||||||
return req.complete;
|
|
||||||
}
|
|
||||||
|
|
||||||
private hasbody(req: Request): boolean {
|
|
||||||
return req.headers['content-length'] !== undefined && req.headers['content-length'] !== '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
private initializeServer() {
|
private initializeServer() {
|
||||||
this.app = express();
|
this.app = express();
|
||||||
@@ -61,13 +55,13 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter<HttpServerConfig>
|
|||||||
this.app.use(express.urlencoded({ extended: true, limit: '5000mb' }));
|
this.app.use(express.urlencoded({ extended: true, limit: '5000mb' }));
|
||||||
|
|
||||||
this.app.use((req, res, next) => {
|
this.app.use((req, res, next) => {
|
||||||
if (this.isFinished(req)) {
|
if (isFinished(req)) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.hasbody(req)) {
|
if (!typeis.hasBody(req)) {
|
||||||
next();
|
next();
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
// 兼容处理没有带content-type的请求
|
// 兼容处理没有带content-type的请求
|
||||||
req.headers['content-type'] = 'application/json';
|
req.headers['content-type'] = 'application/json';
|
||||||
|
Reference in New Issue
Block a user