@samitouri / QOSami-HFS / commits / 3b86b05a

better code

Massimo Melina committed Apr 14, 2024 at 14:54 UTC 3b86b05a120ec6977141dfe2ed2bdd3a6fc7db1a
7 files changed +16 -17
admin/src/AccountForm.ts
+1 -3
@@ -4,7 +4,7 @@ import { createElement as h, ReactNode, useEffect, useRef, useState } from 'reac
4 import { BoolField, Form, MultiSelectField, NumberField } from '@hfs/mui-grid-form'
5 import { Alert } from '@mui/material'
6 import { apiCall } from './api'
7 -import { alertDialog, toast, useDialogBarColors } from './dialog'
7 +import { alertDialog, useDialogBarColors } from './dialog'
8 import { isEqualLax, useIsMobile, wantArray } from './misc'
9 import { IconBtn, modifiedProps } from './mui'
10 import { Account } from './AccountsPage'
@@ -101,7 +101,6 @@ export default function AccountForm({ account, done, groups, addToBar, reload }:
101 throw e
102 }
103 done(got?.username)
104 - toast("Account created", 'success')
104 return
105 }
106 const got = await apiCall('set_account', {
@@ -112,7 +111,6 @@ export default function AccountForm({ account, done, groups, addToBar, reload }:
111 await apiNewPassword(values.username, password)
112 if (account.username === username)
113 state.username = values.username
115 - setTimeout(() => toast("Account modified", 'success'), 1) // workaround: showing a dialog at this point is causing a crash if we are in a dialog
114 done(got?.username) // username may have been changed, so we pass it back
115 }
116 }
admin/src/AccountsPage.ts
+3 -2
@@ -10,7 +10,7 @@ import { TreeItem, TreeView } from '@mui/x-tree-view'
10 import MenuButton from './MenuButton'
11 import AccountForm from './AccountForm'
12 import _ from 'lodash'
13 -import { alertDialog, confirmDialog } from './dialog'
13 +import { alertDialog, confirmDialog, toast } from './dialog'
14 import { useSnapState } from './state'
15 import { importAccountsCsv } from './importAccountsCsv'
16 import { AccountAdminSend } from '../../src/api.accounts'
@@ -54,8 +54,9 @@ export default function AccountsPage() {
54 ],
55 reload,
56 done(username) {
57 - setSel([username])
57 + setSel(isSideBreakpoint ? [username] : [])
58 reload()
59 + toast("Account saved", 'success')
60 }
61 }))
62 useEffect(() => {
admin/src/DataTable.ts
+2 -2
@@ -34,7 +34,7 @@ export function DataTable({ columns, initialState={}, actions, actionsProps, ini
34 const ret = columns.map(col => {
35 const { type } = col
36 if (!type || type === 'string') // offer negated version of default string operators
37 - col.filterOperators ??= getGridStringOperators().map(op => op.value.includes('Empty') ? op : [ // isEmpty already has isNotEmpty
37 + col.filterOperators ??= getGridStringOperators().flatMap(op => op.value.includes('Empty') ? op : [ // isEmpty already has isNotEmpty
38 op,
39 {
40 ...op,
@@ -49,7 +49,7 @@ export function DataTable({ columns, initialState={}, actions, actionsProps, ini
49 } },
50 label: "(not) " + ((localeText as any)['filterOperator' + _.upperFirst(op.value)] || op.value)
51 } satisfies typeof op
52 - ]).flat()
52 + ])
53 const { mergeRender } = col
54 if (!mergeRender)
55 return col
src/QuickZipStream.ts
+1 -1
@@ -201,7 +201,7 @@ export class QuickZipStream extends Readable {
201 offset = ZIP64_SIZE_LIMIT
202 }
203 const extraData = buffer(!extra.length ? []
204 - : [ 2,1, 2,8*extra.length, ...extra.map(x=> [8,x]).flat() ])
204 + : [ 2,1, 2,8*extra.length, ...extra.flatMap(x=> [8,x]) ])
205 if (extraData.length && version < 45)
206 version = 45
207 this.controlledPush([
src/geo.ts
+1 -1
@@ -41,7 +41,7 @@ async function checkFiles() {
41 const TEMP = LOCAL_FILE + '.downloading'
42 const { mtime=0 } = await stat(LOCAL_FILE).catch(() => ({ mtime: 0 }))
43 const now = Date.now()
44 - if (mtime < now - 31 * DAY) { // month-old or non-existing
44 + if (+mtime < now - 31 * DAY) { // month-old or non-existing
45 console.log('downloading geo-ip db')
46 await unzip(await httpStream(URL), path =>
47 path.toUpperCase().endsWith(ZIP_FILE) && TEMP)
src/listen.ts
+2 -2
@@ -267,9 +267,9 @@ const ignore = /^(lo|.*loopback.*|virtualbox.*|.*\(wsl\).*|llw\d|awdl\d|utun\d|a
267 const isLinkLocal = makeNetMatcher('169.254.0.0/16|FE80::/16')
268
269 export async function getIps(external=true) {
270 - const ips = onlyTruthy(Object.entries(networkInterfaces()).map(([name, nets]) =>
270 + const ips = onlyTruthy(Object.entries(networkInterfaces()).flatMap(([name, nets]) =>
271 nets && !ignore.test(name) && nets.map(net => !net.internal && net.address)
272 - ).flat())
272 + ))
273 const e = external && defaultBaseUrl.externalIp
274 if (e && !ips.includes(e))
275 ips.unshift(e)
src/serveGuiFiles.ts
+6 -6
@@ -129,13 +129,13 @@ async function treatIndex(ctx: Koa.Context, filesUri: string, body: string) {
129 }
130 </style>
131 ${!isFrontend ? '' : mapPlugins((plug,id) =>
132 - plug.frontend_css?.map(f =>
133 - `<link rel='stylesheet' type='text/css' href='${f.includes('//') ? f : pub + id + '/' + f}' plugin=${JSON.stringify(id)}/>`))
134 - .flat().filter(Boolean).join('\n')}
132 + plug.frontend_css?.map(f =>
133 + `<link rel='stylesheet' type='text/css' href='${f.includes('//') ? f : pub + id + '/' + f}' plugin=${JSON.stringify(id)}/>`))
134 + .flat().filter(Boolean).join('\n')}
135 ${!isFrontend ? '' : mapPlugins((plug,id) =>
136 - plug.frontend_js?.map(f =>
137 - `<script defer plugin=${JSON.stringify(id)} src='${f.includes('//') ? f : pub + id + '/' + f}'></script>`))
138 - .flat().filter(Boolean).join('\n')}
136 + plug.frontend_js?.map(f =>
137 + `<script defer plugin=${JSON.stringify(id)} src='${f.includes('//') ? f : pub + id + '/' + f}'></script>`))
138 + .flat().filter(Boolean).join('\n')}
139 `
140 if (isBody && isClose)
141 return getSection('bottom') + all