Skip to content

Commit c8471f9

Browse files
committed
fix: failed to issue cert after switching mode from advance to basic #704
1 parent 187dd12 commit c8471f9

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

api/nginx/nginx.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func TokenizeNginxConfig(c *gin.Context) {
3838
return
3939
}
4040
c.JSON(http.StatusOK, ngxConfig)
41-
4241
}
4342

4443
func FormatNginxConfig(c *gin.Context) {

app/src/views/site/site_edit/SiteEdit.vue

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,85 +27,97 @@ const ngx_config: NgxConfig = reactive({
2727
2828
const certInfoMap: Ref<Record<number, CertificateInfo[]>> = ref({})
2929
30-
const auto_cert = ref(false)
30+
const autoCert = ref(false)
3131
const enabled = ref(false)
3232
const filepath = ref('')
3333
const configText = ref('')
34-
const advance_mode_ref = ref(false)
34+
const advanceModeRef = ref(false)
3535
const saving = ref(false)
3636
const filename = ref('')
37-
const parse_error_status = ref(false)
38-
const parse_error_message = ref('')
37+
const parseErrorStatus = ref(false)
38+
const parseErrorMessage = ref('')
3939
const data = ref({}) as Ref<Site>
40+
const historyChatgptRecord = ref([]) as Ref<ChatComplicationMessage[]>
41+
const loading = ref(true)
4042
41-
init()
43+
onMounted(init)
4244
4345
const advanceMode = computed({
4446
get() {
45-
return advance_mode_ref.value || parse_error_status.value
47+
return advanceModeRef.value || parseErrorStatus.value
4648
},
4749
set(v: boolean) {
48-
advance_mode_ref.value = v
50+
advanceModeRef.value = v
4951
},
5052
})
5153
52-
const history_chatgpt_record = ref([]) as Ref<ChatComplicationMessage[]>
53-
54-
function handle_response(r: Site) {
54+
async function handleResponse(r: Site) {
5555
if (r.advanced)
5656
advanceMode.value = true
5757
58-
if (r.advanced)
59-
advanceMode.value = true
60-
61-
parse_error_status.value = false
62-
parse_error_message.value = ''
58+
parseErrorStatus.value = false
59+
parseErrorMessage.value = ''
6360
filename.value = r.name
6461
filepath.value = r.filepath
6562
configText.value = r.config
6663
enabled.value = r.enabled
67-
auto_cert.value = r.auto_cert
68-
history_chatgpt_record.value = r.chatgpt_messages
64+
autoCert.value = r.auto_cert
65+
historyChatgptRecord.value = r.chatgpt_messages
6966
data.value = r
7067
certInfoMap.value = r.cert_info || {}
7168
Object.assign(ngx_config, r.tokenized)
7269
}
7370
74-
function init() {
71+
async function init() {
72+
loading.value = true
7573
if (name.value) {
76-
site.get(name.value).then(r => {
77-
handle_response(r)
78-
}).catch(handle_parse_error)
74+
await site.get(name.value).then(r => {
75+
handleResponse(r)
76+
}).catch(handleParseError)
7977
}
8078
else {
81-
history_chatgpt_record.value = []
79+
historyChatgptRecord.value = []
8280
}
81+
loading.value = false
8382
}
8483
85-
function handle_parse_error(e: { error?: string, message: string }) {
84+
function handleParseError(e: { error?: string, message: string }) {
8685
console.error(e)
87-
parse_error_status.value = true
88-
parse_error_message.value = e.message
86+
parseErrorStatus.value = true
87+
parseErrorMessage.value = e.message
8988
config.get(`sites-available/${name.value}`).then(r => {
9089
configText.value = r.content
9190
})
9291
}
9392
94-
function on_mode_change(advanced: CheckedType) {
95-
site.advance_mode(name.value, { advanced: advanced as boolean }).then(() => {
93+
async function onModeChange(advanced: CheckedType) {
94+
loading.value = true
95+
96+
try {
97+
await site.advance_mode(name.value, { advanced: advanced as boolean })
9698
advanceMode.value = advanced as boolean
9799
if (advanced) {
98-
build_config()
100+
await buildConfig()
99101
}
100102
else {
101-
return ngx.tokenize_config(configText.value).then(r => {
102-
Object.assign(ngx_config, r)
103-
}).catch(handle_parse_error)
103+
let r = await site.get(name.value)
104+
await handleResponse(r)
105+
r = await ngx.tokenize_config(configText.value)
106+
Object.assign(ngx_config, {
107+
...r,
108+
name: name.value,
109+
})
104110
}
105-
})
111+
}
112+
// eslint-disable-next-line ts/no-explicit-any
113+
catch (e: any) {
114+
handleParseError(e)
115+
}
116+
117+
loading.value = false
106118
}
107119
108-
async function build_config() {
120+
async function buildConfig() {
109121
return ngx.build_config(ngx_config).then(r => {
110122
configText.value = r.content
111123
})
@@ -116,7 +128,7 @@ async function save() {
116128
117129
if (!advanceMode.value) {
118130
try {
119-
await build_config()
131+
await buildConfig()
120132
}
121133
catch {
122134
saving.value = false
@@ -132,21 +144,21 @@ async function save() {
132144
site_category_id: data.value.site_category_id,
133145
sync_node_ids: data.value.sync_node_ids,
134146
}).then(r => {
135-
handle_response(r)
147+
handleResponse(r)
136148
router.push({
137149
path: `/sites/${filename.value}`,
138150
query: route.query,
139151
})
140152
message.success($gettext('Saved successfully'))
141-
}).catch(handle_parse_error).finally(() => {
153+
}).catch(handleParseError).finally(() => {
142154
saving.value = false
143155
})
144156
}
145157
146158
provide('save_config', save)
147159
provide('configText', configText)
148160
provide('ngx_config', ngx_config)
149-
provide('history_chatgpt_record', history_chatgpt_record)
161+
provide('history_chatgpt_record', historyChatgptRecord)
150162
provide('enabled', enabled)
151163
provide('name', name)
152164
provide('filepath', filepath)
@@ -182,9 +194,10 @@ provide('data', data)
182194
<div class="switch">
183195
<ASwitch
184196
size="small"
185-
:disabled="parse_error_status"
197+
:disabled="parseErrorStatus"
186198
:checked="advanceMode"
187-
@change="on_mode_change"
199+
:loading
200+
@change="onModeChange"
188201
/>
189202
</div>
190203
<template v-if="advanceMode">
@@ -202,12 +215,12 @@ provide('data', data)
202215
key="advance"
203216
>
204217
<div
205-
v-if="parse_error_status"
218+
v-if="parseErrorStatus"
206219
class="parse-error-alert-wrapper"
207220
>
208221
<AAlert
209222
:message="$gettext('Nginx Configuration Parse Error')"
210-
:description="parse_error_message"
223+
:description="parseErrorMessage"
211224
type="error"
212225
show-icon
213226
/>
@@ -223,7 +236,7 @@ provide('data', data)
223236
class="domain-edit-container"
224237
>
225238
<NgxConfigEditor
226-
v-model:auto-cert="auto_cert"
239+
v-model:auto-cert="autoCert"
227240
:cert-info="certInfoMap"
228241
:enabled="enabled"
229242
@callback="save"

0 commit comments

Comments
 (0)