plugins: api.getHfsConfig

Massimo Melina committed Jun 6, 2022 at 16:45 UTC a074ac0ebbd73da0d15212ca5445691b56515178
3 files changed +5 -2
dev-plugins.md
+2
@@ -102,6 +102,8 @@ The `api` object you get as parameter of the `init` contains the following:
102
103 - `setConfig(key: string, value: any)` set config's value set up by using `exports.config`.
104
105 +- `getHfsConfig(key: string): any` similar to getConfig, but retrieves HFS' config instead.
106 +
107 - `log(...args)` print log in a standard form for plugins.
108
109 - `const: object` all constants of the `const.ts` file are exposed here. E.g. BUILD_TIMESTAMP, API_VERSION, etc.
server/src/config.ts
+1 -1
@@ -75,7 +75,7 @@ function subscribeConfig<T>(k:string, cb: (v:T, was?:T)=>void) {
75 })
76 }
77
78 -function getConfig(k:string) {
78 +export function getConfig(k:string) {
79 return state[k] ?? _.cloneDeep(configProps[k]?.defaultValue) // clone to avoid changing
80 }
81
server/src/plugins.ts
+2 -1
@@ -8,7 +8,7 @@ import { API_VERSION, COMPATIBLE_API_VERSION, PLUGINS_PUB_URI } from './const'
8 import * as Const from './const'
9 import Koa from 'koa'
10 import { debounceAsync, Dict, getOrSet, onProcessExit, same, tryJson, wantArray, watchDir } from './misc'
11 -import { defineConfig } from './config'
11 +import { defineConfig, getConfig } from './config'
12 import { DirEntry } from './api.file_list'
13 import { VfsNode } from './vfs'
14 import { serveFile } from './serveFile'
@@ -232,6 +232,7 @@ export async function rescan() {
232 pluginsConfig.get()?.[id]?.[cfgKey] ?? data.config?.[cfgKey]?.defaultValue,
233 setConfig: (cfgKey: string, value: any) =>
234 setPluginConfig(id, { [cfgKey]: value }),
235 + getHfsConfig: getConfig,
236 })
237 Object.assign(data, res)
238 new Plugin(id, data, unwatch)