mirror of
https://github.com/Jerryplusy/AI-powered-switches.git
synced 2025-10-14 17:59:19 +00:00
Compare commits
No commits in common. "ea6e85e250773e81728b283332c0e7a733277b3c" and "1776a6bd2cd07a3c6e5b4fc71ccd133a1181141f" have entirely different histories.
ea6e85e250
...
1776a6bd2c
10
.idea/codeStyles/Project.xml
generated
10
.idea/codeStyles/Project.xml
generated
@ -26,7 +26,7 @@
|
|||||||
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
||||||
</VueCodeStyleSettings>
|
</VueCodeStyleSettings>
|
||||||
<codeStyleSettings language="HTML">
|
<codeStyleSettings language="HTML">
|
||||||
<option name="SOFT_MARGINS" value="80" />
|
<option name="SOFT_MARGINS" value="100" />
|
||||||
<indentOptions>
|
<indentOptions>
|
||||||
<option name="INDENT_SIZE" value="2" />
|
<option name="INDENT_SIZE" value="2" />
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
@ -34,7 +34,7 @@
|
|||||||
</indentOptions>
|
</indentOptions>
|
||||||
</codeStyleSettings>
|
</codeStyleSettings>
|
||||||
<codeStyleSettings language="JavaScript">
|
<codeStyleSettings language="JavaScript">
|
||||||
<option name="SOFT_MARGINS" value="80" />
|
<option name="SOFT_MARGINS" value="100" />
|
||||||
<indentOptions>
|
<indentOptions>
|
||||||
<option name="INDENT_SIZE" value="2" />
|
<option name="INDENT_SIZE" value="2" />
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
@ -42,7 +42,7 @@
|
|||||||
</indentOptions>
|
</indentOptions>
|
||||||
</codeStyleSettings>
|
</codeStyleSettings>
|
||||||
<codeStyleSettings language="TypeScript">
|
<codeStyleSettings language="TypeScript">
|
||||||
<option name="SOFT_MARGINS" value="80" />
|
<option name="SOFT_MARGINS" value="100" />
|
||||||
<indentOptions>
|
<indentOptions>
|
||||||
<option name="INDENT_SIZE" value="2" />
|
<option name="INDENT_SIZE" value="2" />
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
@ -50,10 +50,10 @@
|
|||||||
</indentOptions>
|
</indentOptions>
|
||||||
</codeStyleSettings>
|
</codeStyleSettings>
|
||||||
<codeStyleSettings language="Vue">
|
<codeStyleSettings language="Vue">
|
||||||
<option name="SOFT_MARGINS" value="80" />
|
<option name="SOFT_MARGINS" value="100" />
|
||||||
<indentOptions>
|
<indentOptions>
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
</indentOptions>
|
</indentOptions>
|
||||||
</codeStyleSettings>
|
</codeStyleSettings>
|
||||||
</code_scheme>
|
</code_scheme>
|
||||||
</component>
|
</component>
|
@ -1,12 +1,21 @@
|
|||||||
const scanEffect = {
|
const scanEffect = {
|
||||||
getTestDevices() {
|
getTestDevices() {
|
||||||
return [{ ip: '192.168.43.140', mac: '00:1A:2B:3C:4D:5E', ports: [22] }];
|
return [
|
||||||
|
{ ip: '192.168.1.1', mac: '00:1A:2B:3C:4D:5E', ports: [22, 23, 161] },
|
||||||
|
{ ip: '192.168.1.2', mac: '00:1D:7D:AA:1B:01', ports: [22, 23, 161] },
|
||||||
|
{ ip: '192.168.1.3', mac: '00:0C:29:5A:3B:11', ports: [22, 23, 161, 443] },
|
||||||
|
{ ip: '192.168.1.4', mac: '00:23:CD:FF:10:02', ports: [22, 23] },
|
||||||
|
{ ip: '192.168.1.5', mac: '00:04:4B:AA:BB:CC', ports: [22, 23, 80, 443] },
|
||||||
|
{ ip: '192.168.1.6', mac: '00:11:22:33:44:55', ports: [22, 23, 161] },
|
||||||
|
{ ip: '192.168.1.7', mac: '00:1F:45:67:89:AB', ports: [23] },
|
||||||
|
{ ip: '192.168.1.8', mac: '00:50:56:11:22:33', ports: [22, 443, 8443] },
|
||||||
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
async fetchLocalInfo({ setLocalIp, subnet, setSubnet }) {
|
async fetchLocalInfo({ setLocalIp, subnet, setSubnet }) {
|
||||||
setLocalIp('192.168.43.0');
|
setLocalIp('192.168.1.100');
|
||||||
if (!subnet) {
|
if (!subnet) {
|
||||||
const ipParts = '192.168.43.0'.split('.');
|
const ipParts = '192.168.1.0'.split('.');
|
||||||
setSubnet(`${ipParts[0]}.${ipParts[1]}.${ipParts[2]}.0/24`);
|
setSubnet(`${ipParts[0]}.${ipParts[1]}.${ipParts[2]}.0/24`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -62,6 +62,10 @@ const ConfigPage = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const performParse = async () => {
|
const performParse = async () => {
|
||||||
|
if (testMode) {
|
||||||
|
await Common.sleep(800 + Math.random() * 700);
|
||||||
|
return await configEffect.generateRealisticConfig(inputText, devices);
|
||||||
|
}
|
||||||
return await api.parseCommand(inputText);
|
return await api.parseCommand(inputText);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
56
src/nest-backend/.gitignore
vendored
56
src/nest-backend/.gitignore
vendored
@ -1,56 +0,0 @@
|
|||||||
# compiled output
|
|
||||||
/dist
|
|
||||||
/node_modules
|
|
||||||
/build
|
|
||||||
|
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
pnpm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
|
|
||||||
# OS
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Tests
|
|
||||||
/coverage
|
|
||||||
/.nyc_output
|
|
||||||
|
|
||||||
# IDEs and editors
|
|
||||||
/.idea
|
|
||||||
.project
|
|
||||||
.classpath
|
|
||||||
.c9/
|
|
||||||
*.launch
|
|
||||||
.settings/
|
|
||||||
*.sublime-workspace
|
|
||||||
|
|
||||||
# IDE - VSCode
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
|
|
||||||
# dotenv environment variable files
|
|
||||||
.env
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
.env.local
|
|
||||||
|
|
||||||
# temp directory
|
|
||||||
.temp
|
|
||||||
.tmp
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"singleQuote": true,
|
|
||||||
"trailingComma": "all"
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
## Project setup
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ pnpm install
|
|
||||||
```
|
|
||||||
|
|
||||||
## Compile and run the project
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# development
|
|
||||||
$ pnpm run start
|
|
||||||
|
|
||||||
# watch mode
|
|
||||||
$ pnpm run start:dev
|
|
||||||
|
|
||||||
# production mode
|
|
||||||
$ pnpm run start:prod
|
|
||||||
```
|
|
||||||
|
|
||||||
## Deployment
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ pnpm install -g @nestjs/mau
|
|
||||||
$ mau deploy
|
|
||||||
```
|
|
@ -1,34 +0,0 @@
|
|||||||
// @ts-check
|
|
||||||
import eslint from '@eslint/js';
|
|
||||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
||||||
import globals from 'globals';
|
|
||||||
import tseslint from 'typescript-eslint';
|
|
||||||
|
|
||||||
export default tseslint.config(
|
|
||||||
{
|
|
||||||
ignores: ['eslint.config.mjs'],
|
|
||||||
},
|
|
||||||
eslint.configs.recommended,
|
|
||||||
...tseslint.configs.recommendedTypeChecked,
|
|
||||||
eslintPluginPrettierRecommended,
|
|
||||||
{
|
|
||||||
languageOptions: {
|
|
||||||
globals: {
|
|
||||||
...globals.node,
|
|
||||||
...globals.jest,
|
|
||||||
},
|
|
||||||
sourceType: 'commonjs',
|
|
||||||
parserOptions: {
|
|
||||||
projectService: true,
|
|
||||||
tsconfigRootDir: import.meta.dirname,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rules: {
|
|
||||||
'@typescript-eslint/no-explicit-any': 'off',
|
|
||||||
'@typescript-eslint/no-floating-promises': 'warn',
|
|
||||||
'@typescript-eslint/no-unsafe-argument': 'warn'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://json.schemastore.org/nest-cli",
|
|
||||||
"collection": "@nestjs/schematics",
|
|
||||||
"sourceRoot": "src",
|
|
||||||
"compilerOptions": {
|
|
||||||
"deleteOutDir": true
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "nest-backend",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "",
|
|
||||||
"author": "",
|
|
||||||
"private": true,
|
|
||||||
"license": "UNLICENSED",
|
|
||||||
"scripts": {
|
|
||||||
"build": "nest build",
|
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
||||||
"start": "nest start",
|
|
||||||
"start:dev": "nest start --watch",
|
|
||||||
"start:debug": "nest start --debug --watch",
|
|
||||||
"start:prod": "node dist/main",
|
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@nestjs/axios": "^4.0.1",
|
|
||||||
"@nestjs/common": "^11.0.1",
|
|
||||||
"@nestjs/core": "^11.0.1",
|
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
|
||||||
"@nestjs/swagger": "^11.2.0",
|
|
||||||
"axios": "^1.10.0",
|
|
||||||
"reflect-metadata": "^0.2.2",
|
|
||||||
"rxjs": "^7.8.1",
|
|
||||||
"ssh2": "^1.16.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
|
||||||
"@eslint/js": "^9.18.0",
|
|
||||||
"@nestjs/cli": "^11.0.0",
|
|
||||||
"@nestjs/schematics": "^11.0.0",
|
|
||||||
"@nestjs/testing": "^11.0.1",
|
|
||||||
"@swc/cli": "^0.6.0",
|
|
||||||
"@swc/core": "^1.10.7",
|
|
||||||
"@types/express": "^5.0.0",
|
|
||||||
"@types/jest": "^29.5.14",
|
|
||||||
"@types/node": "^22.16.4",
|
|
||||||
"@types/supertest": "^6.0.2",
|
|
||||||
"eslint": "^9.18.0",
|
|
||||||
"eslint-config-prettier": "^10.0.1",
|
|
||||||
"eslint-plugin-prettier": "^5.2.2",
|
|
||||||
"globals": "^16.0.0",
|
|
||||||
"jest": "^29.7.0",
|
|
||||||
"prettier": "^3.4.2",
|
|
||||||
"source-map-support": "^0.5.21",
|
|
||||||
"supertest": "^7.0.0",
|
|
||||||
"ts-jest": "^29.2.5",
|
|
||||||
"ts-loader": "^9.5.2",
|
|
||||||
"ts-node": "^10.9.2",
|
|
||||||
"tsconfig-paths": "^4.2.0",
|
|
||||||
"typescript": "^5.7.3",
|
|
||||||
"typescript-eslint": "^8.20.0"
|
|
||||||
},
|
|
||||||
"jest": {
|
|
||||||
"moduleFileExtensions": [
|
|
||||||
"js",
|
|
||||||
"json",
|
|
||||||
"ts"
|
|
||||||
],
|
|
||||||
"rootDir": "src",
|
|
||||||
"testRegex": ".*\\.spec\\.ts$",
|
|
||||||
"transform": {
|
|
||||||
"^.+\\.(t|j)s$": "ts-jest"
|
|
||||||
},
|
|
||||||
"collectCoverageFrom": [
|
|
||||||
"**/*.(t|j)s"
|
|
||||||
],
|
|
||||||
"coverageDirectory": "../coverage",
|
|
||||||
"testEnvironment": "node"
|
|
||||||
}
|
|
||||||
}
|
|
7272
src/nest-backend/pnpm-lock.yaml
generated
7272
src/nest-backend/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { RootModule } from './root/root.module';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [RootModule],
|
|
||||||
})
|
|
||||||
export class AppModule {}
|
|
@ -1,28 +0,0 @@
|
|||||||
import {
|
|
||||||
ArgumentsHost,
|
|
||||||
Catch,
|
|
||||||
ExceptionFilter,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
|
|
||||||
@Catch()
|
|
||||||
export class AllExceptionsFilter implements ExceptionFilter {
|
|
||||||
catch(exception: unknown, host: ArgumentsHost) {
|
|
||||||
const ctx = host.switchToHttp();
|
|
||||||
const response = ctx.getResponse();
|
|
||||||
const status =
|
|
||||||
exception instanceof HttpException
|
|
||||||
? exception.getStatus()
|
|
||||||
: HttpStatus.INTERNAL_SERVER_ERROR;
|
|
||||||
|
|
||||||
const message =
|
|
||||||
exception instanceof HttpException ? exception.message : '服务器内部错误';
|
|
||||||
|
|
||||||
response.status(status).json({
|
|
||||||
success: false,
|
|
||||||
data: null,
|
|
||||||
message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
import {
|
|
||||||
Injectable,
|
|
||||||
NestInterceptor,
|
|
||||||
ExecutionContext,
|
|
||||||
CallHandler,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { Observable, map } from 'rxjs';
|
|
||||||
import { ApiResponse } from '../response-format';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ResponseInterceptor<T>
|
|
||||||
implements NestInterceptor<T, ApiResponse<T>>
|
|
||||||
{
|
|
||||||
intercept(
|
|
||||||
context: ExecutionContext,
|
|
||||||
next: CallHandler,
|
|
||||||
): Observable<ApiResponse<T>> {
|
|
||||||
return next.handle().pipe(
|
|
||||||
map((data) => ({
|
|
||||||
success: true,
|
|
||||||
data,
|
|
||||||
message: '操作成功',
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
export interface ApiResponse<T = any> {
|
|
||||||
success: boolean;
|
|
||||||
data: T;
|
|
||||||
message: string;
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
|
||||||
import { AppModule } from './app.module';
|
|
||||||
import { Logger } from '@nestjs/common';
|
|
||||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
||||||
import { ResponseInterceptor } from './common/interceptors/response.interceptor';
|
|
||||||
import { AllExceptionsFilter } from './common/filters/all-exception.filter';
|
|
||||||
|
|
||||||
async function bootstrap() {
|
|
||||||
const app = await NestFactory.create(AppModule);
|
|
||||||
app.setGlobalPrefix('api');
|
|
||||||
app.useGlobalInterceptors(new ResponseInterceptor());
|
|
||||||
app.useGlobalFilters(new AllExceptionsFilter());
|
|
||||||
const config = new DocumentBuilder()
|
|
||||||
.setTitle('交换机API平台')
|
|
||||||
.setDescription('自动化交换机配置和流量监控接口')
|
|
||||||
.setVersion('1.0')
|
|
||||||
.build();
|
|
||||||
const document = () => SwaggerModule.createDocument(app, config);
|
|
||||||
SwaggerModule.setup('', app, document);
|
|
||||||
await app.listen(8000);
|
|
||||||
}
|
|
||||||
bootstrap().then(() => {
|
|
||||||
Logger.log(`API服务已启动:http://localhost:8000`);
|
|
||||||
Logger.log(`API文档: http://localhost:8000/api`);
|
|
||||||
});
|
|
@ -1,11 +0,0 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Controller()
|
|
||||||
export class RootController {
|
|
||||||
@Get()
|
|
||||||
getWelcome() {
|
|
||||||
return {
|
|
||||||
message: '欢迎使用交换机管理平台 API',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { RootController } from './root.controller';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
controllers: [RootController],
|
|
||||||
})
|
|
||||||
export class RootModule {}
|
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"declaration": true,
|
|
||||||
"removeComments": true,
|
|
||||||
"emitDecoratorMetadata": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"target": "ES2023",
|
|
||||||
"sourceMap": true,
|
|
||||||
"outDir": "./dist",
|
|
||||||
"baseUrl": "./",
|
|
||||||
"incremental": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"strictNullChecks": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"noImplicitAny": false,
|
|
||||||
"strictBindCallApply": false,
|
|
||||||
"noFallthroughCasesInSwitch": false
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user