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

Commit 6d3a044

Browse files
committed
feat: make config json work
1 parent 7f48a90 commit 6d3a044

File tree

8 files changed

+49
-121
lines changed

8 files changed

+49
-121
lines changed

config.example.yaml

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

packages/backend/src/common/config/config.service.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,17 @@ export class ConfigService {
9595
: this.defaultConfig;
9696
}
9797

98-
getConfigSchema() {
99-
// if (fs.existsSync(this.configFilePath)) {
100-
// throw new BizException(ErrorCodeEnum.ConfigExists);
101-
// }
98+
/* 结构 */
99+
getConfigSchema(isPublic = false) {
100+
if (isPublic && fs.existsSync(this.configFilePath)) {
101+
throw new BizException(ErrorCodeEnum.ConfigExists);
102+
}
102103
return CONFIG_SCHEMA;
103104
}
104105

105-
getConfigSchemaValue() {
106-
return {};
106+
/* 获取默认值 */
107+
getDefaultValue() {
108+
return this.defaultConfig;
107109
}
108110

109111
get<K extends keyof ConfigType>(key: K): ConfigType[K] {

packages/backend/src/modules/chat/chat.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class ChatService {
2525
constructor(
2626
@Inject('PrismaService')
2727
private prisma: CustomPrismaService<ExtendedPrismaClient>,
28-
) // config: ConfigService,
29-
{
30-
// this.openaiConfig = config.get('openai');
28+
configService: ConfigService,
29+
) {
30+
this.openaiConfig = configService.get('openai');
3131
}
3232

3333
/* 获取指定用户最近时间内消息的总计,用于limit */

packages/backend/src/modules/dashboard/dashboard.controller.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,24 @@ export class DashboardController {
9494
@Public()
9595
@Get('install')
9696
install() {
97-
return this.configService.getConfigSchema();
97+
return {
98+
success: true,
99+
data: {
100+
schema: this.configService.getConfigSchema(true),
101+
value: this.configService.getDefaultValue(),
102+
},
103+
};
98104
}
99105

100106
@Get('config')
101107
getAllConfig() {
102-
return this.configService.getAll();
108+
return {
109+
success: true,
110+
data: {
111+
schema: this.configService.getConfigSchema(),
112+
value: this.configService.getAll(),
113+
},
114+
};
103115
}
104116

105117
@Put('config')

packages/frontend/src/app/dashboard/setting/page.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ import useSWR from 'swr';
55
import { Loading } from '@/components/loading';
66
import { OptionListRoot, OptionNode } from '@/components/radix-ui-lib';
77
import { useStore } from '@/store';
8+
import useInstallStore from '@/store/install';
89

910
export default function AdminSettingPage() {
1011
const { fetcher } = useStore();
11-
const { data } = useSWR('/dashboard/install', (url) =>
12+
const { updateSettingItem } = useInstallStore();
13+
const { data, isLoading } = useSWR('/dashboard/config', (url) =>
1214
fetcher(url)
1315
.then((res) => res.json())
1416
.then((res) => {
15-
console.log(res);
16-
return res;
17+
updateSettingItem([], res.data.value);
18+
return res.data;
1719
}),
1820
);
19-
if (!data) return <Loading />;
21+
if (isLoading || !data) return <Loading />;
22+
2023
return (
2124
<OptionListRoot>
22-
{data.map((item: any) => (
25+
{data.schema.map((item: any) => (
2326
<OptionNode key={item.key} schema={item} />
2427
))}
2528
</OptionListRoot>

packages/frontend/src/components/radix-ui-lib.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ function SwitchItem(props: {
4040
/* 输入选项 */
4141
function InputItem(props: {
4242
schema: TypeSettingSchema;
43+
value: string;
4344
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
4445
}) {
4546
return (
4647
<TextField.Input
4748
width={160}
49+
value={props.value ?? props.schema.value ?? ''}
4850
onChange={(e) => {
4951
console.log(e.target.value);
5052
props.onChange(e);
@@ -56,10 +58,14 @@ function InputItem(props: {
5658
/* 选择 */
5759
function SelectItem(props: {
5860
schema: SelectSettingSchema;
61+
value: string;
5962
onValueChange: (value: string) => void;
6063
}) {
6164
return (
62-
<Select.Root onValueChange={props.onValueChange}>
65+
<Select.Root
66+
value={props.value ?? props.schema.value ?? ''}
67+
onValueChange={props.onValueChange}
68+
>
6369
<Select.Trigger />
6470
<Select.Content position="popper">
6571
{props.schema.selectOptions.map((option) => (
@@ -221,6 +227,7 @@ export function OptionNode({
221227
headerArea = (
222228
<InputItem
223229
schema={schema}
230+
value={getSettingItem(getKeyTree()) as string}
224231
onChange={(e) => updateSettingItem(getKeyTree(), e.target.value)}
225232
/>
226233
);
@@ -229,6 +236,7 @@ export function OptionNode({
229236
headerArea = (
230237
<SelectItem
231238
schema={schema}
239+
value={getSettingItem(getKeyTree()) as string}
232240
onValueChange={(value) => updateSettingItem(getKeyTree(), value)}
233241
/>
234242
);
@@ -273,7 +281,7 @@ export function OptionNode({
273281
default:
274282
break;
275283
}
276-
console.log('[Setting]', settings);
284+
277285
return (
278286
<div
279287
className={

packages/frontend/src/store/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const createSharedStore: StateCreator<StoreType, [], [], SharedSlice> = (
2727
get,
2828
) => ({
2929
// Auth
30-
setSessionToken(token: string) {
30+
setSessionToken(token: string | undefined) {
3131
set({ sessionToken: token });
3232
},
3333

packages/frontend/src/styles/module/radix-ui-lib.module.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
background-color: var(--gray-2);
88
display: flex;
99
flex-direction: column;
10-
width: 100%;
10+
max-width: 100%;
1111
box-shadow: 0 2px 10px var(--gray-11);
1212
padding: 20px;
1313
}
@@ -32,12 +32,12 @@
3232
display: flex;
3333
flex-direction: column;
3434
align-items: baseline;
35-
35+
3636
.label {
3737
font-size: 1rem;
3838
font-weight: 600;
3939
}
40-
40+
4141
.description {
4242
font-size: 0.8rem;
4343
font-weight: 300;
@@ -58,6 +58,6 @@
5858

5959
.option-list-item-nested {
6060
.item-main-area {
61-
61+
6262
}
63-
}
63+
}

0 commit comments

Comments
 (0)