Skip to content

Commit

Permalink
fix: settings were not saved to file
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Aug 15, 2023
1 parent 21a6acb commit 477bec0
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
2 changes: 1 addition & 1 deletion frontend/src/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"2.0.0-beta.3","build_id":11,"total_build":215}
{"version":"2.0.0-beta.3","build_id":12,"total_build":216}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const data: IData = inject('data')!
<template>
<a-form layout="vertical">
<a-form-item :label="$gettext('Nginx Access Log Path')">
<a-input v-model:value="data.nginx_log.access_log_path"/>
<a-input v-model:value="data.nginx.access_log_path"/>
</a-form-item>
<a-form-item :label="$gettext('Nginx Error Log Path')">
<a-input v-model:value="data.nginx_log.error_log_path"/>
<a-input v-model:value="data.nginx.error_log_path"/>
</a-form-item>
</a-form>
</template>
Expand Down
42 changes: 32 additions & 10 deletions frontend/src/views/preference/Preference.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<script setup lang="ts">
import {useGettext} from 'vue3-gettext'
import {provide, ref} from 'vue'
import {onMounted, provide, ref, watch} from 'vue'
import FooterToolBar from '@/components/FooterToolbar/FooterToolBar.vue'
import {useSettingsStore} from '@/pinia'
import {dark_mode} from '@/lib/theme'
import settings from '@/api/settings'
import {message} from 'ant-design-vue'
import BasicSettings from '@/views/preference/BasicSettings.vue'
import OpenAISettings from '@/views/preference/OpenAISettings.vue'
import NginxLogSettings from '@/views/preference/NginxLogSettings.vue'
import NginxSettings from '@/views/preference/NginxSettings.vue'
import {IData} from '@/views/preference/typedef'
import {useRoute, useRouter} from 'vue-router'
const {$gettext} = useGettext()
Expand All @@ -24,11 +25,16 @@ const data = ref<IData>({
email: '',
http_challenge_port: '9180',
github_proxy: '',
ca_dir: ''
ca_dir: '',
node_secret: ''
},
nginx_log: {
nginx: {
access_log_path: '',
error_log_path: ''
error_log_path: '',
config_dir: '',
pid_path: '',
reload_cmd: '',
restart_cmd: ''
},
openai: {
model: '',
Expand Down Expand Up @@ -66,20 +72,36 @@ async function save() {
provide('data', data)
provide('theme', theme)
const activeKey = ref('1')
const router = useRouter()
const route = useRoute()
const activeKey = ref('basic')
watch(activeKey, () => {
router.push({
query: {
tab: activeKey.value
}
})
})
onMounted(() => {
if (route.query?.tab) {
activeKey.value = route.query.tab.toString()
}
})
</script>

<template>
<a-card :title="$gettext('Preference')">
<div class="preference-container">
<a-tabs v-model:activeKey="activeKey">
<a-tab-pane :tab="$gettext('Basic')" key="1">
<a-tab-pane :tab="$gettext('Basic')" key="basic">
<basic-settings/>
</a-tab-pane>
<a-tab-pane :tab="$gettext('Nginx Log')" key="2">
<nginx-log-settings/>
<a-tab-pane :tab="$gettext('Nginx')" key="nginx">
<nginx-settings/>
</a-tab-pane>
<a-tab-pane :tab="$gettext('OpenAI')" key="3">
<a-tab-pane :tab="$gettext('OpenAI')" key="openai">
<open-a-i-settings/>
</a-tab-pane>
</a-tabs>
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/views/preference/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export interface IData {
email: string,
ca_dir: string
},
nginx_log: {
nginx: {
access_log_path: string
error_log_path: string
config_dir: string
pid_path: string
reload_cmd: string
restart_cmd: string
},
openai: {
model: string
Expand Down
2 changes: 1 addition & 1 deletion frontend/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"2.0.0-beta.3","build_id":11,"total_build":215}
{"version":"2.0.0-beta.3","build_id":12,"total_build":216}
7 changes: 3 additions & 4 deletions server/api/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func GetSettings(c *gin.Context) {
"server": settings.ServerSettings,
"nginx": settings.NginxSettings,
"openai": settings.OpenAISettings,
"git": settings.GitSettings,
})
}

Expand All @@ -26,9 +25,9 @@ func SaveSettings(c *gin.Context) {
return
}

settings.ServerSettings = &json.Server
settings.NginxSettings = &json.Nginx
settings.OpenAISettings = &json.Openai
settings.ServerSettings = json.Server
settings.NginxSettings = json.Nginx
settings.OpenAISettings = json.Openai

settings.ReflectFrom()

Expand Down
28 changes: 9 additions & 19 deletions server/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type Server struct {
type Nginx struct {
AccessLogPath string `json:"access_log_path"`
ErrorLogPath string `json:"error_log_path"`
ConfigDir string `json:"nginx_config_dir"`
PIDPath string `json:"nginx_pid_path"`
ConfigDir string `json:"config_dir"`
PIDPath string `json:"pid_path"`
ReloadCmd string `json:"reload_cmd"`
RestartCmd string `json:"restart_cmd"`
}
Expand All @@ -46,15 +46,7 @@ type OpenAI struct {
Model string `json:"model"`
}

type Git struct {
Url string `json:"url"`
AuthMethod string `json:"auth_method"`
Username string `json:"username"`
Password string `json:"password"`
PrivateKeyFilePath string `json:"private_key_file_path"`
}

var ServerSettings = &Server{
var ServerSettings = Server{
HttpPort: "9000",
RunMode: "debug",
HTTPChallengePort: "9180",
Expand All @@ -66,22 +58,19 @@ var ServerSettings = &Server{
GithubProxy: "",
}

var NginxSettings = &Nginx{
var NginxSettings = Nginx{
AccessLogPath: "",
ErrorLogPath: "",
}

var OpenAISettings = &OpenAI{}

var GitSettings = &Git{}
var OpenAISettings = OpenAI{}

var ConfPath string

var sections = map[string]interface{}{
"server": ServerSettings,
"nginx": NginxSettings,
"openai": OpenAISettings,
"git": GitSettings,
"server": &ServerSettings,
"nginx": &NginxSettings,
"openai": &OpenAISettings,
}

func init() {
Expand Down Expand Up @@ -123,6 +112,7 @@ func mapTo(section string, v interface{}) {
}

func reflectFrom(section string, v interface{}) {
log.Print(section, v)
err := Conf.Section(section).ReflectFrom(v)
if err != nil {
log.Fatalf("Cfg.ReflectFrom %s err: %v", section, err)
Expand Down

0 comments on commit 477bec0

Please sign in to comment.