Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.

Commit 526f0a3

Browse files
authored
Merge pull request #162 from AprilNEA/v3-dev
A panel for real-time backend updates
2 parents 2b949b2 + 6d3a044 commit 526f0a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1267
-1635
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config.yaml
33
prisma/client/
44

55
.env
6+
config.json
67
apps/server/.env
78

89
# IDE

config.example.yaml

Lines changed: 0 additions & 97 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"prettier": "latest",
2828
"ts-node": "latest",
2929
"turbo": "latest",
30-
"typescript": "latest"
30+
"typescript": "latest",
31+
"prisma": "5.5.2"
3132
},
3233
"prisma": {
3334
"schema": "prisma/schema.prisma"

packages/backend/package.json

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
},
2020
"dependencies": {
2121
"@liaoliaots/nestjs-redis": "^9.0.5",
22-
"@nestjs/common": "^10.0.0",
23-
"@nestjs/config": "^3.0.0",
24-
"@nestjs/core": "^10.0.0",
25-
"@nestjs/mapped-types": "*",
26-
"@nestjs/platform-express": "^10.0.0",
27-
"@nestjs/platform-fastify": "^10.2.7",
22+
"@nestjs/common": "^10.2.8",
23+
"@nestjs/config": "^3.1.1",
24+
"@nestjs/core": "^10.2.8",
25+
"@nestjs/platform-fastify": "^10.2.8",
2826
"@prisma/client": "workspace:@nest-http/prisma@*",
2927
"bcrypt": "^5.1.0",
3028
"fastify": "^4.24.3",
@@ -34,7 +32,6 @@
3432
"jose": "^4.14.1",
3533
"js-yaml": "^4.1.0",
3634
"mint-filter": "^4.0.3",
37-
"nest-router": "^1.0.9",
3835
"nestjs-prisma": "^0.22.0",
3936
"openai": "^4.14.0",
4037
"prisma-extension-pagination": "^0.5.0",
@@ -43,11 +40,9 @@
4340
"spark-md5": "^3.0.2"
4441
},
4542
"devDependencies": {
46-
"@nestjs/cli": "^10.0.0",
47-
"@nestjs/schematics": "^10.0.0",
48-
"@nestjs/testing": "^10.0.0",
49-
"@trivago/prettier-plugin-sort-imports": "*",
50-
"@types/express": "^4.17.17",
43+
"@nestjs/cli": "^10.2.1",
44+
"@nestjs/schematics": "^10.0.3",
45+
"@nestjs/testing": "^10.2.8",
5146
"@types/jest": "^29.5.2",
5247
"@types/js-yaml": "^4.0.5",
5348
"@types/mocha": "^10.0.2",
@@ -60,8 +55,7 @@
6055
"eslint-plugin-prettier": "^4.2.1",
6156
"eslint-plugin-simple-import-sort": "^10.0.0",
6257
"jest": "^29.5.0",
63-
"prettier": "*",
64-
"prisma": "^5.1.1",
58+
"prisma": "*",
6559
"shared": "workspace:*",
6660
"source-map-support": "^0.5.21",
6761
"supertest": "^6.3.3",

packages/backend/src/app.module.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { CustomPrismaModule } from 'nestjs-prisma';
22

33
import { RedisModule } from '@liaoliaots/nestjs-redis';
44
import { Module } from '@nestjs/common';
5-
import { ConfigModule } from '@nestjs/config';
65
import { APP_GUARD } from '@nestjs/core';
76

7+
import { ConfigModule } from '@/common/config';
88
import { AuthGuard } from '@/common/guards/auth.guard';
99
import { JwtModule } from '@/libs/jwt/jwt.module';
1010
import { AuthModule } from '@/modules/auth/auth.module';
@@ -17,22 +17,18 @@ import { ExtendedPrismaConfigService } from '@/processors/database/prisma.servic
1717

1818
import { AppController } from './app.controller';
1919
import { AppService } from './app.service';
20-
import configuration from './configuration';
2120

2221
@Module({
2322
imports: [
24-
ConfigModule.forRoot({
25-
load: [configuration],
26-
isGlobal: true,
27-
}),
23+
ConfigModule,
2824
CustomPrismaModule.forRootAsync({
2925
name: 'PrismaService',
3026
useClass: ExtendedPrismaConfigService,
3127
isGlobal: true,
3228
}),
3329
RedisModule.forRoot({
3430
config: {
35-
url: configuration().redis.url,
31+
url: process.env.REDIS_URL,
3632
},
3733
}),
3834
AuthModule,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Global, Module } from '@nestjs/common';
2+
3+
import { ConfigService } from './config.service';
4+
5+
@Global()
6+
@Module({
7+
providers: [ConfigService],
8+
exports: [ConfigService],
9+
})
10+
export class ConfigModule {}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import * as fs from 'fs';
2+
import { join } from 'path';
3+
4+
import { Injectable } from '@nestjs/common';
5+
6+
import { BizException } from '@/common/exceptions/biz.exception';
7+
8+
import { ConfigType, ISettingSchema } from 'shared';
9+
import { ErrorCodeEnum } from 'shared/dist/error-code';
10+
11+
const DEFAULT_CONFIG = {
12+
mode: 'nginx',
13+
title: 'ChatGPT Admin Web',
14+
port: {
15+
frontend: 3000,
16+
backend: 3001,
17+
},
18+
jwt: {
19+
algorithm: 'HS256',
20+
},
21+
};
22+
23+
const CONFIG_SCHEMA: ISettingSchema[] = [
24+
{
25+
key: 'mode',
26+
type: 'select',
27+
label: '运行模式',
28+
selectOptions: ['nginx', 'docker', 'debug'],
29+
},
30+
{
31+
key: 'title',
32+
type: 'input',
33+
label: '网站标题',
34+
},
35+
{
36+
key: 'port',
37+
label: '端口',
38+
items: [
39+
{
40+
key: 'frontend',
41+
type: 'input' as any,
42+
label: '前端端口',
43+
},
44+
{
45+
key: 'backend',
46+
type: 'input' as any,
47+
label: '后端端口',
48+
},
49+
],
50+
},
51+
{
52+
key: 'jwt',
53+
label: 'JWT',
54+
items: [
55+
{
56+
key: 'algorithm',
57+
type: 'select' as any,
58+
label: '算法',
59+
selectOptions: ['HS256', 'RS256'],
60+
},
61+
{
62+
key: 'secret',
63+
type: 'input' as any,
64+
label: '密钥',
65+
},
66+
],
67+
},
68+
{
69+
key: 'email',
70+
label: '邮箱',
71+
items: [
72+
{
73+
key: 'use',
74+
type: 'select' as any,
75+
label: '启用',
76+
selectOptions: ['disable', 'resend'],
77+
},
78+
],
79+
},
80+
];
81+
82+
@Injectable()
83+
export class ConfigService {
84+
private config: ConfigType;
85+
private readonly defaultConfig = DEFAULT_CONFIG;
86+
private readonly configFilePath = join(__dirname, '../../../config.json');
87+
88+
constructor() {
89+
this.loadConfig();
90+
}
91+
92+
private loadConfig(): void {
93+
this.config = fs.existsSync(this.configFilePath)
94+
? JSON.parse(fs.readFileSync(this.configFilePath, 'utf8'))
95+
: this.defaultConfig;
96+
}
97+
98+
/* 结构 */
99+
getConfigSchema(isPublic = false) {
100+
if (isPublic && fs.existsSync(this.configFilePath)) {
101+
throw new BizException(ErrorCodeEnum.ConfigExists);
102+
}
103+
return CONFIG_SCHEMA;
104+
}
105+
106+
/* 获取默认值 */
107+
getDefaultValue() {
108+
return this.defaultConfig;
109+
}
110+
111+
get<K extends keyof ConfigType>(key: K): ConfigType[K] {
112+
return this.config[key];
113+
}
114+
115+
getAll() {
116+
return this.config;
117+
}
118+
119+
updateConfig(updateConfig: Partial<ConfigType>) {
120+
const newConfig = { ...this.config, ...updateConfig };
121+
const jsonData = JSON.stringify(newConfig, null, 2);
122+
fs.writeFileSync(this.configFilePath, jsonData, 'utf8');
123+
this.loadConfig();
124+
}
125+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './config.service';
2+
export * from './config.module';

0 commit comments

Comments
 (0)