waibu 2.10.0 → 2.11.0
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 +11 -0
- package/lib/decorate.js +1 -8
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -0
package/index.js
CHANGED
|
@@ -579,6 +579,17 @@ async function factory (pkgName) {
|
|
|
579
579
|
})
|
|
580
580
|
return result.join(delimiter)
|
|
581
581
|
}
|
|
582
|
+
|
|
583
|
+
getSetting = (key, { defValue, req = {} } = {}) => {
|
|
584
|
+
const { breakNsPath } = this.app.bajo
|
|
585
|
+
const { get } = this.app.lib._
|
|
586
|
+
let { ns, path } = breakNsPath(key)
|
|
587
|
+
const paths = path.replaceAll('/', '.').split('.')
|
|
588
|
+
if (paths[0] === '') paths.shift()
|
|
589
|
+
path = paths.join('.')
|
|
590
|
+
const cfgValue = get(this.app, `${ns}.config.${path}`, defValue)
|
|
591
|
+
return get(req, `site.setting.${ns}.${path}`, cfgValue)
|
|
592
|
+
}
|
|
582
593
|
}
|
|
583
594
|
|
|
584
595
|
return Waibu
|
package/lib/decorate.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
async function decorate () {
|
|
2
|
-
const { get } = this.app.lib._
|
|
3
|
-
const { breakNsPath } = this.app.bajo
|
|
4
2
|
const me = this
|
|
5
3
|
this.instance.decorateRequest('lang', null)
|
|
6
4
|
this.instance.decorateRequest('t', () => {})
|
|
@@ -9,12 +7,7 @@ async function decorate () {
|
|
|
9
7
|
this.instance.decorateRequest('site', null)
|
|
10
8
|
this.instance.decorateRequest('ns', null)
|
|
11
9
|
this.instance.decorateRequest('getSetting', function (key, defValue) {
|
|
12
|
-
|
|
13
|
-
const paths = path.replaceAll('/', '.').split('.')
|
|
14
|
-
if (paths[0] === '') paths.shift()
|
|
15
|
-
path = paths.join('.')
|
|
16
|
-
const cfgValue = get(me.app, `${ns}.config.${path}`, defValue)
|
|
17
|
-
return get(this, `site.setting.${ns}.${path}`, cfgValue)
|
|
10
|
+
return me.app.waibu.getSetting(key, { defValue, req: this })
|
|
18
11
|
})
|
|
19
12
|
}
|
|
20
13
|
|
package/package.json
CHANGED