-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from hqwuzhaoyi/setting
feat: Setting page
- whisper@0.7.0
- whisper@0.6.0
- whisper@0.5.0
- whisper@0.4.0
- web@1.10.0
- web@1.9.1
- web@1.9.0
- web@1.8.1
- web@1.8.0
- web@1.7.0
- web@1.6.0
- web@1.5.0
- web@1.4.0
- utils@0.5.0
- utils@0.4.1
- utils@0.4.0
- utils@0.3.0
- ui@0.5.0
- ui@0.4.1
- ui@0.4.0
- ui@0.3.0
- tsconfig@0.3.0
- tsconfig@0.2.0
- translator@0.6.0
- translator@0.5.0
- translator@0.4.0
- translator@0.3.0
- shared-types@2.5.0
- shared-types@2.4.0
- shared-types@2.3.0
- shared-types@2.2.0
- server@1.10.0
- server@1.9.0
- server@1.8.1
- server@1.8.0
- server@1.7.0
- server@1.6.0
- server@1.5.0
- server@1.4.0
- nfo-parser@0.3.0
- nfo-parser@0.2.1
- nfo-parser@0.2.0
- nfo-parser@0.1.0
- nfo-parser@0.0.2
- nfo-parser@0.0.1
- logger@0.5.0
- logger@0.4.1
- logger@0.4.0
- logger@0.3.0
- jest-presets@0.4.0
- jest-presets@0.3.0
- eslint-config-custom-server@0.3.0
- eslint-config-custom-server@0.2.0
- eslint-config-custom@1.2.0
- eslint-config-custom@1.1.0
Showing
46 changed files
with
1,235 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Put, | ||
Param, | ||
Delete, | ||
} from "@nestjs/common"; | ||
|
||
import { CustomConfigService } from "./custom-config.service"; | ||
import { Public } from "@/auth/decorators/public.decorator"; | ||
|
||
@Controller("config") | ||
export class ConfigController { | ||
constructor(private readonly configService: CustomConfigService) {} | ||
|
||
@Public() | ||
@Get() | ||
findAll() { | ||
return this.configService.getAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; | ||
|
||
@Entity() | ||
export class Config { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
key: string; | ||
|
||
@Column() | ||
value: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Global, Module } from "@nestjs/common"; | ||
import { CustomConfigService } from "./custom-config.service"; | ||
import { Config } from "./config.entity"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { DatabaseConfigService } from "./config.service"; | ||
import { ConfigModule } from "@nestjs/config"; | ||
import { ConfigController } from "./config.controller"; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Config]), ConfigModule], | ||
providers: [DatabaseConfigService, CustomConfigService], | ||
exports: [CustomConfigService], | ||
controllers: [ConfigController], | ||
}) | ||
export class CustomConfigModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { DatabaseConfigService } from "./config.service"; | ||
import { Config } from "./config.entity"; | ||
import { getRepositoryToken } from "@nestjs/typeorm"; | ||
|
||
describe("ConfigService", () => { | ||
let service: DatabaseConfigService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
DatabaseConfigService, | ||
{ | ||
provide: getRepositoryToken(Config), | ||
useValue: {}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<DatabaseConfigService>(DatabaseConfigService); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// config.service.ts | ||
import { Injectable } from "@nestjs/common"; | ||
import { InjectRepository } from "@nestjs/typeorm"; | ||
import { Repository } from "typeorm"; | ||
import { Config } from "./config.entity"; | ||
|
||
@Injectable() | ||
export class DatabaseConfigService { | ||
constructor( | ||
@InjectRepository(Config) | ||
private configRepository: Repository<Config> | ||
) {} | ||
|
||
async get(key: string): Promise<Config> { | ||
return this.configRepository.findOne({ where: { key } }); | ||
} | ||
|
||
async set(key: string, value: string): Promise<Config> { | ||
let config = await this.configRepository.findOne({ where: { key } }); | ||
if (config) { | ||
config.value = value; | ||
} else { | ||
config = this.configRepository.create({ key, value }); | ||
} | ||
return this.configRepository.save(config); | ||
} | ||
|
||
async getAll(): Promise<Record<string, string>> { | ||
const configs = await this.configRepository.find(); | ||
return configs.reduce((acc, config) => { | ||
acc[config.key] = config.value; | ||
return acc; | ||
}, {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { ConfigService as NextConfigService } from "@nestjs/config"; | ||
import { DatabaseConfigService } from "./config.service"; | ||
|
||
@Injectable() | ||
export class CustomConfigService { | ||
constructor( | ||
private readonly configService: DatabaseConfigService, | ||
private readonly nextConfigService: NextConfigService | ||
) {} | ||
|
||
getStatic(key: string): string { | ||
return this.nextConfigService.get<string>(key); | ||
} | ||
|
||
async getDynamic(key: string): Promise<string> { | ||
const config = await this.configService.get(key); | ||
return config?.value; | ||
} | ||
|
||
async get(key: string): Promise<string> { | ||
return (await this.getDynamic(key)) || this.getStatic(key); | ||
} | ||
|
||
async set(key: string, value: string): Promise<void> { | ||
if (!key || !value) return; | ||
await this.configService.set(key, value); | ||
} | ||
|
||
async getAll(): Promise<Record<string, string>> { | ||
return this.configService.getAll(); | ||
} | ||
} |
Oops, something went wrong.