waibu 2.11.0 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +6 -3
- package/lib/decorate.js +5 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -0
package/index.js
CHANGED
|
@@ -582,13 +582,16 @@ async function factory (pkgName) {
|
|
|
582
582
|
|
|
583
583
|
getSetting = (key, { defValue, req = {} } = {}) => {
|
|
584
584
|
const { breakNsPath } = this.app.bajo
|
|
585
|
-
const { get } = this.app.lib._
|
|
585
|
+
const { get, isPlainObject, isArray } = this.app.lib._
|
|
586
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
586
587
|
let { ns, path } = breakNsPath(key)
|
|
587
588
|
const paths = path.replaceAll('/', '.').split('.')
|
|
588
589
|
if (paths[0] === '') paths.shift()
|
|
589
590
|
path = paths.join('.')
|
|
590
|
-
const cfgValue = get(this.app, `${ns}.config.${path}
|
|
591
|
-
|
|
591
|
+
const cfgValue = get(this.app, `${ns}.config.${path}`)
|
|
592
|
+
const reqValue = get(req, `site.setting.${ns}.${path}`)
|
|
593
|
+
if (isPlainObject(cfgValue) || isArray(cfgValue)) return defaultsDeep({}, reqValue, cfgValue, defValue)
|
|
594
|
+
return reqValue ?? cfgValue ?? defValue
|
|
592
595
|
}
|
|
593
596
|
}
|
|
594
597
|
|
package/lib/decorate.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
async function decorate () {
|
|
2
|
+
const { isPlainObject, isArray } = this.app.lib._
|
|
3
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
2
4
|
const me = this
|
|
3
5
|
this.instance.decorateRequest('lang', null)
|
|
4
6
|
this.instance.decorateRequest('t', () => {})
|
|
@@ -7,7 +9,9 @@ async function decorate () {
|
|
|
7
9
|
this.instance.decorateRequest('site', null)
|
|
8
10
|
this.instance.decorateRequest('ns', null)
|
|
9
11
|
this.instance.decorateRequest('getSetting', function (key, defValue) {
|
|
10
|
-
|
|
12
|
+
const value = me.app.waibu.getSetting(key, { req: this })
|
|
13
|
+
if (isPlainObject(value) || isArray(value)) return defaultsDeep({}, value, defValue)
|
|
14
|
+
return value ?? defValue
|
|
11
15
|
})
|
|
12
16
|
}
|
|
13
17
|
|
package/package.json
CHANGED