--config now supports indicating a folder instead of path-to-file

Massimo Melina committed May 22, 2022 at 07:12 UTC 3b7469842ccb2f2cfd8d73e445b8f6822ed65e7c
2 files changed +12 -4
server/src/config.ts
+12 -3
@@ -5,9 +5,10 @@ import { argv } from './const'
5 import { watchLoad } from './watchLoad'
6 import yaml from 'yaml'
7 import _ from 'lodash'
8 -import { debounceAsync, same, objSameKeys, onOff, wait } from './misc'
9 -import { exists } from 'fs'
8 +import { debounceAsync, same, objSameKeys, onOff, wait, with_ } from './misc'
9 +import { exists, statSync } from 'fs'
10 import { promisify } from 'util'
11 +import { join } from 'path'
12
13 const PATH = 'config.yaml'
14
@@ -17,7 +18,15 @@ let started = false // this will tell the difference for subscribeConfig()s that
18 let state: Record<string, any> = {}
19 const cfgEvents = new EventEmitter()
20 cfgEvents.setMaxListeners(10_000)
20 -const path = argv.config || process.env.HFS_CONFIG || PATH
21 +const path = with_(argv.config || process.env.HFS_CONFIG || PATH, p => {
22 + try {
23 + if (statSync(p).isDirectory()) // try to detect if path points to a folder, in which case we add the standard filename
24 + return join(p, PATH)
25 + }
26 + catch {}
27 + console.log("config", p)
28 + return p
29 +})
30 const { save } = watchLoad(path, values => setConfig(values||{}, false), {
31 failedOnFirstAttempt(){
32 console.log("No config file, using defaults")
todo.md
-1
@@ -13,7 +13,6 @@
13 - admin/monitor: show some info on what folder is browsing
14 - admin/stats: total bytes sent
15 - admin/stats: list of IPs seen
16 -- if specified config is a folder, check for file config.yaml inside
16 - admin: in a group, show linked accounts
17 - admin: warn in case of items with same name
18 - command line help --help