admin/config: try to redirect user on port change
Massimo Melina committed
Mar 13, 2022 at 19:51 UTC
4143e2a264555b921f2ec79fd903d3a0d58b787e
1 file changed
+14
-3
admin/src/ConfigPage.ts
+14
-3
@@ -9,7 +9,7 @@ import { Dict } from './misc'
9
import { subscribeKey } from 'valtio/utils'
10
import { Form, BoolField, NumberField, StringField, SelectField, FieldProps, Field } from './Form';
11
import StringStringField from './StringStringField'
12
-import { alertDialog } from './dialog'
12
+import { alertDialog, confirmDialog } from './dialog'
13
14
let loaded: Dict | undefined
15
@@ -86,9 +86,20 @@ export default function ConfigPage() {
86
})
87
88
async function save() {
89
- await apiCall('set_config', { values: state.changes })
89
+ const values = state.changes
90
+ const loc = window.location
91
+ const newPort = loc.protocol === 'http:' ? values.port : values.https_port
92
+ if (newPort <= 0 && !await confirmDialog("You are switching off the server port and you will be disconnected"))
93
+ return
94
+ else if (newPort > 0 && !await confirmDialog("You are changing the port and you may be disconnected"))
95
+ return
96
+ await apiCall('set_config', { values })
97
+ if (newPort > 0) {
98
+ await alertDialog("You are being redirected but in some cases this may fail. Hold on tight!", 'warning')
99
+ return window.location.href = loc.protocol + '//' + loc.hostname + ':' + newPort + loc.pathname
100
+ }
101
setTimeout(reloadStatus, 1000)
91
- Object.assign(loaded, state.changes) // since changes are recalculated subscribing state.config, but it depends on 'loaded' to (which cannot be subscribed), be sure to update loaded first
102
+ Object.assign(loaded, values) // since changes are recalculated subscribing state.config, but it depends on 'loaded' to (which cannot be subscribed), be sure to update loaded first
103
recalculateChanges()
104
await alertDialog("Changes applied", 'success')
105
}