config.custom_header

Massimo Melina committed Apr 10, 2022 at 15:55 UTC 537fee3d4a3b06c7f4ea3863620b618937a89164
6 files changed +20 -2
README.md
+3
@@ -213,6 +213,9 @@ Supported entries are:
213 - ip: 192.168.0.90
214 ```
215 - `plugins_config` this is a generic place where you can find/put configuration for each plugin, at least those that need configuration.
216 +- `custom_header` provide HTML code to be put at the top of your Frontend. Default is none.
217 +- `localhost_admin` should Admin be accessed without credentials when on localhost. Default is true.
218 +- `proxies` number of proxies between server and clients to be trusted about providing clients' IP addresses. Default is 0.
219
220 ## Virtual File System (VFS)
221
admin/src/ConfigPage.ts
+3
@@ -97,6 +97,9 @@ export default function ConfigPage() {
97 helperText: values.allowed_referer ? "Leave empty to allow any" : "Use this to avoid direct links from other websites", },
98 { k: 'zip_calculate_size_for_seconds', comp: NumberField, sm: 6, label: "Calculate ZIP size for seconds",
99 helperText: "If time is not enough, the browser will not show download percentage" },
100 + { k: 'custom_header', multiline: true, sx: { '& textarea': { fontFamily: 'monospace' } },
101 + helperText: "Any HTML code here will be used as header for the Frontend"
102 + },
103 { k: 'mime', comp: StringStringField,
104 keyLabel: "Files", keyWidth: 7,
105 valueLabel: "Mime type", valueWidth: 4
frontend/src/BrowseFiles.ts
+2 -1
@@ -19,8 +19,9 @@ export type DirList = DirEntry[]
19
20 export function BrowseFiles() {
21 useFetchList()
22 - const { error, list } = useSnapState()
22 + const { error, list, serverConfig } = useSnapState()
23 return h(Fragment, {},
24 + h(Html, { code: serverConfig?.custom_header }),
25 h(Head),
26 hError(error && 'Failed to retrieve list')
27 || h(list ? FilesList : Spinner))
frontend/src/state.ts
+7
@@ -3,6 +3,7 @@
3 import _ from 'lodash'
4 import { proxy, useSnapshot } from 'valtio'
5 import { subscribeKey } from 'valtio/utils'
6 +import { apiCall } from './api'
7 import { DirList } from './BrowseFiles'
8
9 export const state = proxy<{
@@ -24,6 +25,7 @@ export const state = proxy<{
25 foldersFirst: boolean,
26 theme: string,
27 adminUrl?: string,
28 + serverConfig?: any,
29 }>({
30 iconsClass: '',
31 username: '',
@@ -53,6 +55,11 @@ loadSettings()
55 for (const k of SETTINGS_TO_STORE)
56 subscribeKey(state, k, storeSettings)
57
58 +// load server config
59 +setTimeout(() =>
60 + apiCall('config', {}, { noModal: true }).then(res =>
61 + state.serverConfig = res) )
62 +
63 function loadSettings() {
64 const json = localStorage.getItem(SETTINGS_KEY)
65 if (!json) return
server/src/frontEndApis.ts
+5
@@ -3,8 +3,13 @@
3 import { ApiHandlers } from './apiMiddleware'
4 import { file_list } from './api.file_list'
5 import * as api_auth from './api.auth'
6 +import { getConfig } from './config'
7
8 export const frontEndApis: ApiHandlers = {
9 file_list,
10 ...api_auth,
11 +
12 + config() {
13 + return Object.fromEntries(['custom_header'].map(k => [k, getConfig(k)]))
14 + }
15 }
todo.md
-1
@@ -1,5 +1,4 @@
1 # To do
2 -- custom text to display on the frontend
2 - log exceptions
3 - watch certificates for change
4 - admin/fs: render virtual folders differently