sumba 2.40.0 → 2.42.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/extend/bajo/hook.js +22 -4
- package/index.js +5 -73
- package/lib/config.js +0 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +11 -0
package/extend/bajo/hook.js
CHANGED
|
@@ -254,11 +254,14 @@ async function hook () {
|
|
|
254
254
|
level: 10,
|
|
255
255
|
name: 'waibu:preParsing',
|
|
256
256
|
handler: async function (req, reply) {
|
|
257
|
-
const {
|
|
257
|
+
const { get } = this.app.lib._
|
|
258
|
+
const { getHostname, checkRoute } = this.app.waibu
|
|
259
|
+
const { checkTheme, checkIconset } = this.app.waibuMpa
|
|
258
260
|
req.site = await this.getSite(getHostname(req))
|
|
259
|
-
await
|
|
260
|
-
|
|
261
|
-
await
|
|
261
|
+
await checkRoute(req)
|
|
262
|
+
if (get(req, 'routeOptions.config.webApp') !== 'waibuMpa') return
|
|
263
|
+
await checkTheme(req, reply)
|
|
264
|
+
await checkIconset(req, reply)
|
|
262
265
|
}
|
|
263
266
|
}, {
|
|
264
267
|
name: 'waibu:beforeStart',
|
|
@@ -276,6 +279,21 @@ async function hook () {
|
|
|
276
279
|
} catch (err) {
|
|
277
280
|
}
|
|
278
281
|
}
|
|
282
|
+
}, {
|
|
283
|
+
level: 1000,
|
|
284
|
+
name: 'waibuMpa:afterBuildLocals',
|
|
285
|
+
handler: async function (locals, req, opts = {}) {
|
|
286
|
+
const { normalizeMenuItems } = this.app.waibuMpa
|
|
287
|
+
const { pullAt } = this.app.lib._
|
|
288
|
+
locals.sidebar = await normalizeMenuItems(locals.sidebar, req)
|
|
289
|
+
const deleted = []
|
|
290
|
+
for (const [index, menu] of locals.menu.pages.entries()) {
|
|
291
|
+
if (!menu.children) continue
|
|
292
|
+
menu.children = await normalizeMenuItems(menu.children, req)
|
|
293
|
+
if (menu.children.length === 0) deleted.push(index)
|
|
294
|
+
}
|
|
295
|
+
pullAt(locals.menu.pages, deleted)
|
|
296
|
+
}
|
|
279
297
|
}]
|
|
280
298
|
}
|
|
281
299
|
|
package/index.js
CHANGED
|
@@ -870,59 +870,6 @@ async function factory (pkgName) {
|
|
|
870
870
|
return asValue ? values.map(item => ({ value: item, text: item })) : values
|
|
871
871
|
}
|
|
872
872
|
|
|
873
|
-
/**
|
|
874
|
-
* Gather all paths to check for a request
|
|
875
|
-
* @method
|
|
876
|
-
* @param {Object} req - The request object
|
|
877
|
-
* @returns {Array} - An array of paths to check
|
|
878
|
-
*/
|
|
879
|
-
pathsToCheck = (req) => {
|
|
880
|
-
const { isSet } = this.app.lib.aneka
|
|
881
|
-
const { uniq, without } = this.app.lib._
|
|
882
|
-
const items = [req.routeOptions.url, req.url].filter(url => isSet(url)).map(url => url.split('?')[0].split('#')[0])
|
|
883
|
-
return uniq(without(items, undefined, null))
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
/**
|
|
887
|
-
* Check and set the iconset for a request
|
|
888
|
-
* @async
|
|
889
|
-
* @method
|
|
890
|
-
* @param {Object} req - The request object
|
|
891
|
-
* @param {Object} reply - The reply object
|
|
892
|
-
* @returns {Promise<void>} A promise that resolves when the iconset is checked and set
|
|
893
|
-
*/
|
|
894
|
-
checkIconset = async (req, reply) => {
|
|
895
|
-
const { get, isString } = this.app.lib._
|
|
896
|
-
const mpa = this.app.waibuMpa
|
|
897
|
-
|
|
898
|
-
if (!req.site) return
|
|
899
|
-
const siteIconset = get(req, 'site.setting.waibuMpa.iconset')
|
|
900
|
-
req.iconset = siteIconset ?? get(mpa, 'config.iconset.set', 'default')
|
|
901
|
-
const hiconset = req.headers['x-iconset']
|
|
902
|
-
if (isString(hiconset) && mpa.getIconset(hiconset)) req.iconset = hiconset
|
|
903
|
-
req.iconset = req.iconset ?? 'default'
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
/**
|
|
907
|
-
* Check and set the theme for a request
|
|
908
|
-
* @async
|
|
909
|
-
* @method
|
|
910
|
-
* @param {Object} req - The request object
|
|
911
|
-
* @param {Object} reply - The reply object
|
|
912
|
-
* @returns {Promise<void>} A promise that resolves when the theme is checked and set
|
|
913
|
-
*/
|
|
914
|
-
checkTheme = async (req, reply) => {
|
|
915
|
-
const { get, isString } = this.app.lib._
|
|
916
|
-
const mpa = this.app.waibuMpa
|
|
917
|
-
|
|
918
|
-
if (!req.site) return
|
|
919
|
-
const siteTheme = get(req, 'site.setting.waibuMpa.theme')
|
|
920
|
-
req.theme = siteTheme ?? get(mpa, 'config.theme.set', 'default')
|
|
921
|
-
const htheme = req.headers['x-theme']
|
|
922
|
-
if (isString(htheme) && mpa.getTheme(htheme)) req.theme = htheme
|
|
923
|
-
req.theme = req.theme ?? 'default'
|
|
924
|
-
}
|
|
925
|
-
|
|
926
873
|
/**
|
|
927
874
|
* Check and set the team for a request
|
|
928
875
|
* @async
|
|
@@ -934,6 +881,7 @@ async function factory (pkgName) {
|
|
|
934
881
|
checkTeam = async (req, reply) => {
|
|
935
882
|
const { includes } = this.app.lib.aneka
|
|
936
883
|
const { outmatch } = this.app.lib
|
|
884
|
+
const { pathsToCheck } = this.app.waibu
|
|
937
885
|
|
|
938
886
|
if (req.user.isAdmin) return
|
|
939
887
|
if (req.routeOptions.config.xSite && req.user.isXSiteAdmin) return
|
|
@@ -941,7 +889,7 @@ async function factory (pkgName) {
|
|
|
941
889
|
const teamIds = req.user.teams.map(item => item.id + '')
|
|
942
890
|
// if (req.user.teams.map(item => item.alias).length === 0) throw this.error('accessDenied', { statusCode: 403 })
|
|
943
891
|
|
|
944
|
-
const paths =
|
|
892
|
+
const paths = pathsToCheck(req)
|
|
945
893
|
const results = (await this.getSecureGuards()).filter(item => {
|
|
946
894
|
if (item.siteId !== req.site.id + '' || item.path[0] === '!') return false
|
|
947
895
|
return paths.some(outmatch([item.path]))
|
|
@@ -964,7 +912,7 @@ async function factory (pkgName) {
|
|
|
964
912
|
*/
|
|
965
913
|
checkUser = async (req, reply, source) => {
|
|
966
914
|
const { merge, isEmpty, camelCase, get } = this.app.lib._
|
|
967
|
-
const { routePath } = this.app.waibu
|
|
915
|
+
const { routePath, pathsToCheck } = this.app.waibu
|
|
968
916
|
const userId = get(req, 'session.userId')
|
|
969
917
|
const setUser = async () => {
|
|
970
918
|
if (!userId) return
|
|
@@ -987,7 +935,7 @@ async function factory (pkgName) {
|
|
|
987
935
|
return
|
|
988
936
|
}
|
|
989
937
|
|
|
990
|
-
const paths =
|
|
938
|
+
const paths = pathsToCheck(req)
|
|
991
939
|
let guards = (await this.getAnonymousGuards()).filter(item => item.siteId === req.site.id + '')
|
|
992
940
|
const anonymous = this.checkRouteGuard(guards, paths)
|
|
993
941
|
if (anonymous) {
|
|
@@ -1038,23 +986,6 @@ async function factory (pkgName) {
|
|
|
1038
986
|
if (!get(req, 'user.isXSiteAdmin')) throw this.error('accessDenied', { statusCode: 403 })
|
|
1039
987
|
}
|
|
1040
988
|
|
|
1041
|
-
/**
|
|
1042
|
-
* Check the route for a request
|
|
1043
|
-
* @async
|
|
1044
|
-
* @method
|
|
1045
|
-
* @param {Object} req - The request object
|
|
1046
|
-
* @returns {Promise<void>} A promise that resolves when the route is checked
|
|
1047
|
-
*/
|
|
1048
|
-
checkRoute = async (req) => {
|
|
1049
|
-
const { routePath } = this.app.waibu
|
|
1050
|
-
const { outmatch } = this.app.lib
|
|
1051
|
-
const routes = req.getSetting('waibu:route.disabled', []).map(item => routePath(item, false))
|
|
1052
|
-
if (routes.length === 0) return
|
|
1053
|
-
const isMatch = outmatch(routes)
|
|
1054
|
-
const paths = this.pathsToCheck(req)
|
|
1055
|
-
if (paths.find(isMatch)) throw this.error('_notFound')
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
989
|
/**
|
|
1059
990
|
* Parse namespace settings for a request
|
|
1060
991
|
* @method
|
|
@@ -1289,6 +1220,7 @@ async function factory (pkgName) {
|
|
|
1289
1220
|
const defSetting = {}
|
|
1290
1221
|
const nsSetting = {}
|
|
1291
1222
|
const names = this.app.getAllNs()
|
|
1223
|
+
names.push('bajo')
|
|
1292
1224
|
const query = {
|
|
1293
1225
|
ns: { $in: names },
|
|
1294
1226
|
siteId: site.id + ''
|
package/lib/config.js
CHANGED
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-08-01
|
|
4
|
+
|
|
5
|
+
- [2.42.0] Remove `checkTheme()` and `checkIconset()` and move to `waibu-mpa`
|
|
6
|
+
- [2.42.0] Remove `pathsToCheck()` and `checkRoute()` and move to `waibu`
|
|
7
|
+
- [2.42.0] Update `hook.js`
|
|
8
|
+
|
|
9
|
+
## 2026-07-29
|
|
10
|
+
|
|
11
|
+
- [2.41.0] Add `bajo` namespace to `getSite`
|
|
12
|
+
- [2.41.0] Remove `config.siteSetting.timeZone` and use default `timeZone` from `bajo` instead
|
|
13
|
+
|
|
3
14
|
## 2026-07-28
|
|
4
15
|
|
|
5
16
|
- [2.40.0] Add queue for `download` & all necessary methods to support it
|