plugins: api.getConfig()
Massimo Melina committed
May 31, 2024 at 17:04 UTC
6ccb7d0e6a13db34f34125f9c2aef4947ebbde51
2 files changed
+14
-7
dev-plugins.md
+5
-3
@@ -155,8 +155,9 @@ Based on `type`, other properties are supported:
155
156
The `api` object you get as parameter of the `init` contains the following:
157
158
-- `getConfig(key: string): any` get plugin's config value, described in `exports.config`.
159
-
158
+- `getConfig(key?: string): any` get plugin's config value, described in `exports.config`.
159
+ If key is not provided, an object with all keys is returned.
160
+
161
- `setConfig(key: string, value: any)` set plugin's config value.
162
163
- `subscribeConfig(key: string, callback: (value: any) => void): Unsubscriber`
@@ -449,7 +450,7 @@ Where information is too little, you'll have to consult the source code, sorry.
450
uploads?: string[] // in case of request with potentially multiple uploads (POST), we register all filenames (no full path)
451
length?: number
452
originalStream?: typeof ctx.body
452
- uploadDestinationPath?: string
453
+ uploadDestinationPath?: string // this value is the temporary file in uploadStart and the final one in uploadFinished
454
archive?: string
455
456
## Other files
@@ -551,6 +552,7 @@ If you want to override a text regardless of the language, use the special langu
552
- config.type:username
553
- api.events class has changed
554
- frontend event "fileMenu": changed props format
555
+ - api.getConfig() without parameters
556
- 8.72 (v0.52.0)
557
- HFS.toast
558
- HFS.misc functions
src/plugins.ts
+9
-4
@@ -7,8 +7,10 @@ import { API_VERSION, APP_PATH, COMPATIBLE_API_VERSION, HTTP_NOT_FOUND, IS_WINDO
7
PLUGINS_PUB_URI } from './const'
8
import * as Const from './const'
9
import Koa from 'koa'
10
-import { adjustStaticPathForGlob, Callback, debounceAsync, Dict, getOrSet, onlyTruthy,
11
- PendingPromise, pendingPromise, Promisable, same, tryJson, wait, waitFor, wantArray, watchDir } from './misc'
10
+import {
11
+ adjustStaticPathForGlob, Callback, debounceAsync, Dict, getOrSet, objSameKeys, onlyTruthy,
12
+ PendingPromise, pendingPromise, Promisable, same, tryJson, wait, waitFor, wantArray, watchDir
13
+} from './misc'
14
import { defineConfig, getConfig } from './config'
15
import { DirEntry } from './api.get_file_list'
16
import { VfsNode } from './vfs'
@@ -405,8 +407,11 @@ function watchPlugin(id: string, path: string) {
407
log(...args: any[]) {
408
console.log('plugin', id+':', ...args)
409
},
408
- getConfig: (cfgKey: string) =>
409
- pluginsConfig.get()?.[id]?.[cfgKey] ?? pluginData.config?.[cfgKey]?.defaultValue,
410
+ getConfig(cfgKey?: string) {
411
+ const cur = pluginsConfig.get()?.[id]
412
+ return cfgKey ? cur?.[cfgKey] ?? pluginData.config?.[cfgKey]?.defaultValue
413
+ : _.defaults(cur, objSameKeys(pluginData.config, x => x.defaultValue))
414
+ },
415
setConfig: (cfgKey: string, value: any) =>
416
setPluginConfig(id, { [cfgKey]: value }),
417
subscribeConfig(cfgKey: string, cb: Callback<any>) {