xiongzhu 2 жил өмнө
parent
commit
81698ab4c0

+ 3 - 3
src/sys-config/entities/sys-config.entity.ts

@@ -17,13 +17,13 @@ export class SysConfig {
     @Column({ unique: true, length: 50 })
     @Column({ unique: true, length: 50 })
     name: string
     name: string
 
 
-    @Column({ length: 50 })
-    type: string
+    @Column({ type: 'enum', enum: SysConfigType })
+    type: SysConfigType
 
 
     @Column({ type: 'longtext' })
     @Column({ type: 'longtext' })
     value: string
     value: string
 
 
-    @Column({ length: 255 })
+    @Column({ length: 255, nullable: true })
     remark: string
     remark: string
 
 
     @CreateDateColumn()
     @CreateDateColumn()

+ 6 - 2
src/sys-config/sys-config.controller.ts

@@ -2,7 +2,7 @@ import { Body, Controller, Get, Param, Post } from '@nestjs/common'
 import { ApiTags } from '@nestjs/swagger'
 import { ApiTags } from '@nestjs/swagger'
 import { Public } from '../auth/public.decorator'
 import { Public } from '../auth/public.decorator'
 import { SysConfigService } from './sys-config.service'
 import { SysConfigService } from './sys-config.service'
-import { SysConfig } from './entities/sys-config.entity'
+import { SysConfig, SysConfigType } from './entities/sys-config.entity'
 import { PageRequest } from 'src/common/dto/page-request'
 import { PageRequest } from 'src/common/dto/page-request'
 
 
 @ApiTags('sys-config')
 @ApiTags('sys-config')
@@ -18,6 +18,10 @@ export class SysConfigController {
 
 
     @Get('/:name')
     @Get('/:name')
     async getSysConfigByName(@Param('name') name: string) {
     async getSysConfigByName(@Param('name') name: string) {
-        return await this.sysConfigService.findByName(name)
+        const res = await this.sysConfigService.findByName(name)
+        if (res.type === SysConfigType.Object) {
+            res.value = JSON.parse(res.value)
+        }
+        return res
     }
     }
 }
 }

+ 4 - 14
src/sys-config/sys-config.service.ts

@@ -11,20 +11,7 @@ export class SysConfigService {
         @InjectRepository(SysConfig)
         @InjectRepository(SysConfig)
         private readonly sysConfigRepository: Repository<SysConfig>
         private readonly sysConfigRepository: Repository<SysConfig>
     ) {
     ) {
-        ;(async function init() {
-            if (
-                !(await sysConfigRepository.findOneBy({
-                    name: 'system_message'
-                }))
-            ) {
-                sysConfigRepository.save({
-                    name: 'system_message',
-                    type: 'string',
-                    value: '你是ChillGPT赤耳人工智能机器人,由绿洲AI设计并开发,用于回答各种问题、提供帮助和解决问题,除了与中国政治和中国领导人相关的话题。\n可以通过关注“CHILLGPT赤耳人工智能”微信公众号与你取得联系。',
-                    remark: '系统预设'
-                })
-            }
-        })()
+        ;(async function init() {})()
     }
     }
 
 
     async findAll(req: PageRequest<SysConfig>) {
     async findAll(req: PageRequest<SysConfig>) {
@@ -46,6 +33,9 @@ export class SysConfigService {
 
 
     async save(sysConfig: Partial<SysConfig>) {
     async save(sysConfig: Partial<SysConfig>) {
         try {
         try {
+            if (typeof sysConfig.value === 'object') {
+                sysConfig.value = JSON.stringify(sysConfig.value)
+            }
             return await this.sysConfigRepository.save(sysConfig)
             return await this.sysConfigRepository.save(sysConfig)
         } catch (error) {
         } catch (error) {
             throw new InternalServerErrorException(error.message)
             throw new InternalServerErrorException(error.message)