better code
Massimo Melina committed
May 8, 2024 at 23:57 UTC
a62ac39b663ea97790f207d319b6cbf70e4407d3
5 files changed
+10
-15
admin/src/LogsPage.ts
+6
-1
@@ -6,7 +6,6 @@ import { API_URL, useApi, useApiList } from './api'
6
import { DataTable } from './DataTable'
7
import { CFG, Dict, formatBytes, HTTP_UNAUTHORIZED, newDialog, prefix, shortenAgent, splitAt, tryJson, md,
8
typedKeys, NBSP, _dbg, mapFilter } from '@hfs/shared'
9
-import { logLabels } from './OptionsPage'
9
import {
10
NetmaskField, Flex, IconBtn, useBreakpoint, usePauseButton, useToggleButton, WildcardsSupported, Country,
11
hTooltip, Btn, wikiLink
@@ -19,6 +18,12 @@ import { BoolField, SelectField } from '@hfs/mui-grid-form'
18
import { toast, useDialogBarColors } from './dialog'
19
import { useBlockIp } from './useBlockIp'
20
21
+const logLabels = {
22
+ log: "Access",
23
+ error_log: "Access error",
24
+ console: "Console",
25
+}
26
+
27
export default function LogsPage() {
28
const [tab, setTab] = useState(0)
29
const files = typedKeys(logLabels)
admin/src/OptionsPage.ts
-6
@@ -30,12 +30,6 @@ subscribe(state, (ops) => {
30
recalculateChanges()
31
})
32
33
-export const logLabels = {
34
- log: "Access",
35
- error_log: "Access error",
36
- console: "Console",
37
-}
38
-
33
export default function OptionsPage() {
34
const { data, reload: reloadConfig, element } = useApiEx('get_config', { omit: ['vfs'] })
35
const snap = useSnapState()
admin/src/VfsPathField.ts
+1
-1
@@ -8,7 +8,7 @@ interface VfsPathFieldProps extends FieldProps<string> {
8
autocompleteProps: Partial<AutocompleteProps<string, false, true, undefined>>
9
}
10
11
-export default function VfsPaathField({ value='', onChange, helperText, setApi, autocompleteProps, onlyFolders=true, ...props }: VfsPathFieldProps) {
11
+export default function VfsPathField({ value='', onChange, helperText, setApi, autocompleteProps, onlyFolders=true, ...props }: VfsPathFieldProps) {
12
const uri = dirname(value)
13
const { list, loading } = useApiList('get_file_list', { uri, admin: true, onlyFolders })
14
const options = useMemo(() => [uri + '/'].concat(list.map(x => value + x.n)), [list, uri])
frontend/src/upload.ts
+2
-2
@@ -5,7 +5,7 @@ import { Btn, Flex, FlexV, iconBtn, Select } from './components'
5
import {
6
basename, closeDialog, formatBytes, formatPerc, hIcon, useIsMobile, newDialog, prefix, selectFiles, working,
7
HTTP_CONFLICT, HTTP_PAYLOAD_TOO_LARGE, formatSpeed, dirname, getHFS, onlyTruthy, with_, cpuSpeedIndex,
8
- buildUrlQueryString,
8
+ buildUrlQueryString, randomId,
9
} from './misc'
10
import _ from 'lodash'
11
import { INTERNAL_Snapshot, proxy, ref, snapshot, subscribe, useSnapshot } from 'valtio'
@@ -346,7 +346,7 @@ async function startUpload(toUpload: ToUpload, to: string, resume=0) {
346
347
async function subscribeNotifications() {
348
if (notificationChannel) return
349
- notificationChannel = 'upload-' + Math.random().toString(36).slice(2)
349
+ notificationChannel = 'upload-' + randomId()
350
notificationSource = await getNotification(notificationChannel, async (name, data) => {
351
const {uploading} = uploadState
352
if (!uploading) return
src/listen.ts
+1
-5
@@ -274,13 +274,9 @@ export async function getIps(external=true) {
274
if (e && !ips.includes(e))
275
ips.unshift(e)
276
const noLinkLocal = ips.filter(x => !isLinkLocal(x))
277
- const ret = v4first(noLinkLocal.length ? noLinkLocal : ips)
277
+ const ret = _.sortBy(noLinkLocal.length ? noLinkLocal : ips, isIPv6) // false=IPV4 comes first
278
defaultBaseUrl.localIp = ret[0] || ''
279
return ret
280
-
281
- function v4first(a: string[]) {
282
- return _.sortBy(a, isIPv6) // works because `false` comes first
283
- }
280
}
281
282
export async function getUrls() {