better code
Massimo Melina committed
Apr 19, 2023 at 15:50 UTC
04847f51bfd19fb6f5bc94f983aaaf5a26963f8f
5 files changed
+9
-9
README.md
+1
-1
@@ -206,7 +206,7 @@ This is enough, but you may want to configure generated links accordingly:
206
207
- Appending `#LOGIN` to address will bring up the login dialog
208
- Appending ?lang=CODE to address will force a specific language
209
-- env `SESSION_DURATION` can be set to any number of seconds, or to "session" to make it expire when session/browser is closed
209
+- env `SESSION_DURATION` can be set to any number of seconds. Default is 1 day.
210
211
## Contribute
212
admin/src/LoginRequired.ts
+2
-2
@@ -2,7 +2,7 @@
2
3
import { state, useSnapState } from './state'
4
import { createElement as h, Fragment, useEffect, useRef, useState } from 'react'
5
-import { Center } from './misc'
5
+import { Center, getHFS } from './misc'
6
import { Form } from '@hfs/mui-grid-form'
7
import { apiCall } from './api'
8
import { srpSequence } from '@hfs/shared'
@@ -71,7 +71,7 @@ async function login(username: string, password: string) {
71
sessionRefresher(res)
72
}
73
74
-sessionRefresher((window as any).HFS.session)
74
+sessionRefresher(getHFS().session)
75
76
function sessionRefresher(response: any) {
77
if (!response) return
frontend/src/components.ts
+3
-3
@@ -1,6 +1,6 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
-import { hfsEvent, hIcon } from './misc'
3
+import { getHFS, hfsEvent, hIcon } from './misc'
4
import { createElement as h, Fragment, HTMLAttributes, isValidElement, ReactNode, useMemo } from 'react'
5
6
export function Spinner(props: any) {
@@ -60,8 +60,8 @@ export function CustomCode({ name, props }: any) {
60
.map((x, key) => isValidElement(x) ? h(Fragment, { key }, x)
61
: typeof x === 'string' ? h(Html, { key, code: x })
62
: h('span', { key }, x))
63
- const html = (window as any).HFS.customHtml[name]
64
- if (html && html.trim())
63
+ const html = getHFS().customHtml[name]
64
+ if (html?.trim?.())
65
ret.push(h(Html, { key: 'x', code: html }))
66
return ret
67
}, props ? Object.values(props) : []))
frontend/src/login.ts
+2
-2
@@ -3,7 +3,7 @@
3
import { apiCall } from '@hfs/shared/api'
4
import { state, useSnapState } from './state'
5
import { alertDialog, newDialog } from './dialog'
6
-import { getPrefixUrl, hIcon, srpSequence, working } from './misc'
6
+import { getHFS, getPrefixUrl, hIcon, srpSequence, working } from './misc'
7
import { useNavigate } from 'react-router-dom'
8
import { createElement as h, Fragment, useEffect, useRef } from 'react'
9
import { t, useI18N } from './i18n'
@@ -27,7 +27,7 @@ async function login(username:string, password:string) {
27
})
28
}
29
30
-sessionRefresher((window as any).HFS.session)
30
+sessionRefresher(getHFS().session)
31
32
function sessionRefresher(response: any) {
33
if (!response) return
src/api.file_list.ts
+1
-1
@@ -20,7 +20,7 @@ import { HTTP_BAD_REQUEST, HTTP_FOOL, HTTP_METHOD_NOT_ALLOWED, HTTP_NOT_FOUND }
20
import Koa from 'koa'
21
22
export const file_list: ApiHandler = async ({ uri, offset, limit, search, omit, sse }, ctx) => {
23
- let node = await urlToNode( uri || '/', ctx)
23
+ const node = await urlToNode( uri || '/', ctx)
24
const list = new SendListReadable()
25
if (!node)
26
return fail(HTTP_NOT_FOUND)