better code
Massimo Melina committed
Oct 3, 2024 at 15:53 UTC
bcd4e35134946dab900968d0b377b98950e82ee8
1 file changed
+7
-5
admin/src/InternetPage.ts
+7
-5
@@ -214,9 +214,7 @@ export default function InternetPage() {
214
if (fresh && !await confirmDialog("Your certificate is still good", { trueText: "Make a new one anyway" }))
215
return
216
if (!await confirmDialog("HFS must temporarily serve HTTP on public port 80, and your router must be configured or this operation will fail")) return
217
- const res = await apiCall('check_domain', { domain }).catch(e =>
218
- confirmDialog(String(e), { trueText: "Continue anyway" }) )
219
- if (res === false) return
217
+ if (await stopOnCheckDomain(domain)) return
218
await apiCall('make_cert', { domain, altNames, email: values.acme_email }, { timeout: 20_000 })
219
.then(async () => {
220
await alertDialog("Certificate created", 'success')
@@ -314,6 +312,11 @@ export default function InternetPage() {
312
)
313
}
314
315
+ async function stopOnCheckDomain(domain: string) {
316
+ return domain && false === await apiCall('check_domain', { domain }).catch(e =>
317
+ confirmDialog(String(e), { trueText: "Continue anyway", falseText: "Stop" }))
318
+ }
319
+
320
async function verify(again=false): Promise<any> {
321
await nat.loading
322
const data = nat.getData() // fresh data
@@ -326,8 +329,7 @@ export default function InternetPage() {
329
{
330
const hostname = url && new URL(url).hostname
331
const domain = !isIP(hostname) && hostname
329
- if (domain && false === await apiCall('check_domain', { domain }).catch(e =>
330
- confirmDialog(String(e), { trueText: "Continue anyway" }) )) return
332
+ if (await stopOnCheckDomain(domain)) return
333
}
334
const urlResult = url && await apiCall('self_check', { url }).catch(() =>
335
alertDialog(md(`Sorry, we couldn't verify your configured address ${url} 😰\nstill, we are going to test your IP address 🤞`), 'warning'))