admin/options: validate server_code
Massimo Melina committed
Sep 22, 2023 at 23:58 UTC
4d42010931368f54d139e1705cc8b906ee4131a2
1 file changed
+3
-3
admin/src/OptionsPage.ts
+3
-3
@@ -5,7 +5,7 @@ import { createElement as h, Fragment, useEffect, useRef } from 'react';
5
import { apiCall, useApiEx } from './api'
6
import { state, useSnapState } from './state'
7
import { CardMembership, Refresh, Warning } from '@mui/icons-material'
8
-import { Dict, iconTooltip, InLink, LinkBtn, MAX_TILES_SIZE, modifiedSx, REPO_URL, wait, wikiLink, with_ } from './misc'
8
+import { Dict, iconTooltip, InLink, LinkBtn, MAX_TILES_SIZE, modifiedSx, REPO_URL, wait, wikiLink, with_, try_ } from './misc'
9
import { Form, BoolField, NumberField, SelectField, FieldProps, Field, StringField } from '@hfs/mui-grid-form';
10
import { ArrayField } from './ArrayField'
11
import FileField from './FileField'
@@ -89,7 +89,7 @@ export default function OptionsPage() {
89
{ k: 'https_port', comp: ServerPort, md: 3, label: "HTTPS port", status: status?.https||true, suggestedPort: 443,
90
onChange(v: number) {
91
if (v >= 0 && !httpsEnabled && !values.cert)
92
- suggestMakingCert()
92
+ suggestMakingCert().then()
93
return v
94
}
95
},
@@ -171,7 +171,7 @@ export default function OptionsPage() {
171
fromField: (all:string) => all.split('\n').map(s => s.trim()).filter(Boolean).map(ip => ({ ip })),
172
toField: (all: any) => !Array.isArray(all) ? '' : all.map(x => x?.ip).filter(Boolean).join('\n')
173
},
174
- { k: 'server_code', comp: TextEditorField, sm: 12,
174
+ { k: 'server_code', comp: TextEditorField, sm: 12, getError: v => try_(() => new Function(v) && null, e => e.message),
175
helperText: md(`This code works similarly to [a plugin](${REPO_URL}blob/main/dev-plugins.md) (with some limitations)`)
176
}
177
]