diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index caebf6e..0000000 --- a/eslint.config.mjs +++ /dev/null @@ -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' - }, - }, -); \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index a032f3a..a717606 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,9 +6,24 @@ import { ResponseInterceptor } from './common/interceptors/response.interceptor' import { AllExceptionsFilter } from './common/filters/all-exception.filter'; import { SystemService } from './core/system/system.service'; import { WsAdapter } from '@nestjs/platform-ws'; +import * as fs from 'fs'; +import * as path from 'path'; async function bootstrap() { - Logger.log('晶灵核心初始化..'); + Logger.log('晶灵核心初始化..', '', 'Core'); + const envPath = path.join(__dirname, '../.env'); + const envExamplePath = path.join(__dirname, '../.envExample'); + if (!fs.existsSync(envPath)) { + if (fs.existsSync(envExamplePath)) { + fs.copyFileSync(envExamplePath, envPath); + Logger.warn(`.env 文件已自动生成,请修改配置后重启核心..`, '', 'ENV'); + process.exit(1); + } else { + Logger.error('配置模块初始化出错,请重新拉取应用!', '', 'ENV'); + process.exit(1); + } + } + const app = await NestFactory.create(AppModule); app.setGlobalPrefix('api', { exclude: [ @@ -18,12 +33,13 @@ async function bootstrap() { { path: 'public/(.*)', method: RequestMethod.ALL }, ], }); + app.useGlobalInterceptors(new ResponseInterceptor()); app.useGlobalFilters(new AllExceptionsFilter()); const systemService = app.get(SystemService); const restartDuration = systemService.checkRestartTime(); if (restartDuration) { - new Logger('System').warn(`重启完成!耗时 ${restartDuration} 秒`); + Logger.warn(`重启完成!耗时 ${restartDuration} 秒`, '', 'System'); } const config = new DocumentBuilder() .setTitle('晶灵核心') @@ -38,7 +54,8 @@ async function bootstrap() { Logger.error(`自动更新失败: ${err?.message}`, '', 'System'); }); } + bootstrap().then(() => { - Logger.log(`API服务已启动:http://localhost:6868/api`); - Logger.log(`API文档: http://localhost:6868/docs`); + Logger.log(`API服务已启动:http://localhost:6868/api`, '', 'Core'); + Logger.log(`API文档: http://localhost:6868/docs`, '', 'Core'); }); diff --git a/src/modules/system/systemWeb.controller.ts b/src/modules/system/systemWeb.controller.ts index a0f8edb..39a45fb 100644 --- a/src/modules/system/systemWeb.controller.ts +++ b/src/modules/system/systemWeb.controller.ts @@ -1,7 +1,6 @@ import { Controller, Post, Inject, UseGuards, Param } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiBody, ApiProperty } from '@nestjs/swagger'; import { SystemWebService } from './systemWeb.service'; -import { ToolsService } from '../../core/tools/tools.service'; import { TokenAuthGuard } from '../../core/tools/token-auth.guard'; class WebServerDto { @@ -18,8 +17,6 @@ export class SystemWebController { constructor( @Inject(SystemWebService) private readonly systemService: SystemWebService, - @Inject(ToolsService) - private readonly toolService: ToolsService, ) {} /** diff --git a/src/modules/system/systemWeb.module.ts b/src/modules/system/systemWeb.module.ts index 47f9d18..87a6455 100644 --- a/src/modules/system/systemWeb.module.ts +++ b/src/modules/system/systemWeb.module.ts @@ -1,12 +1,12 @@ import { Module } from '@nestjs/common'; import { SystemWebController } from './systemWeb.controller'; import { SystemWebService } from './systemWeb.service'; -import { ToolsModule } from '../../core/tools/tools.module'; import { PathModule } from '../../core/path/path.module'; import { SystemModule } from '../../core/system/system.module'; +import { ToolsModule } from '../../core/tools/tools.module'; @Module({ - imports: [ToolsModule, SystemModule, PathModule], + imports: [SystemModule, PathModule, ToolsModule], controllers: [SystemWebController], providers: [SystemWebService], })