waibu-mpa 2.1.3 → 2.1.4

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.
@@ -8,6 +8,8 @@ class Wmpa {
8
8
  this.prefixMain = '<%= prefix.main %>'
9
9
  this.accessTokenUrl = '<%= accessTokenUrl %>'
10
10
  this.renderUrl = '<%= renderUrl %>'
11
+ this.theme = '<%= _meta.theme.name %>'
12
+ this.iconset = '<%= _meta.iconset.name %>'
11
13
  this.apiPrefix = '<%= api.prefix %>'
12
14
  this.apiExt = '<%= api.ext %>'
13
15
  this.apiHeaderKey = '<%= api.headerKey %>'
@@ -101,14 +103,22 @@ class Wmpa {
101
103
  fetchRender = async (body, qs = {}) => {
102
104
  if (_.isArray(body)) body = body.join('\n')
103
105
  let url = this.renderUrl + '?'
104
- _.forOwn(qs, (v, k) => {
106
+ _.forOwn(_.omit(qs, ['theme', 'iconset']), (v, k) => {
105
107
  url += '&' + k + '=' + v
106
108
  })
107
- const resp = await fetch(url, {
109
+ const opts = {
108
110
  method: 'POST',
109
- headers: { 'Content-Type': 'text/plain', 'Waibu-Referer': window.location.href },
111
+ headers: {
112
+ 'Content-Type': 'text/plain',
113
+ 'X-Referer': window.location.href,
114
+ 'X-Theme': this.theme,
115
+ 'X-Iconset': this.iconset
116
+ },
110
117
  body
111
- })
118
+ }
119
+ if (qs.theme) opts.headers['X-Theme'] = qs.theme
120
+ if (qs.iconset) opts.headers['X-Iconset'] = qs.iconset
121
+ const resp = await fetch(url, opts)
112
122
  if (!resp.ok) throw new Error('Response status: ' + resp.status)
113
123
  return await resp.text()
114
124
  }
@@ -1,11 +1,11 @@
1
1
  const component = {
2
2
  method: 'POST',
3
3
  handler: async function (req, reply) {
4
- req.referer = req.headers['waibu-referer']
4
+ req.referer = req.headers['x-referer']
5
5
  const { ext = '.html' } = req.body
6
6
  reply.header('Content-Type', `text/html; charset=${this.config.page.charset}`)
7
7
  reply.header('Content-Language', req.lang)
8
- const opts = { req, reply, partial: true, ext, theme: req.params.theme ?? req.query.theme, iconset: req.params.iconset ?? req.query.iconset }
8
+ const opts = { req, reply, partial: true, ext, theme: req.headers['x-theme'], iconset: req.headers['x-iconset'] }
9
9
  return this.renderString(req.body, req.query, opts)
10
10
  }
11
11
  }
package/index.js CHANGED
@@ -628,6 +628,18 @@ async function factory (pkgName) {
628
628
  })
629
629
  return attrs.join(' ')
630
630
  }
631
+
632
+ getTheme = (name, nameOnly) => {
633
+ const theme = this.themes.find(item => item.name === name)
634
+ if (!theme) return theme
635
+ return nameOnly ? theme.name : theme
636
+ }
637
+
638
+ getIconset = (name, nameOnly) => {
639
+ const iconset = this.iconsets.find(item => item.name === name)
640
+ if (!iconset) return iconset
641
+ return nameOnly ? iconset.name : iconset
642
+ }
631
643
  }
632
644
 
633
645
  return WaibuMpa
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-mpa",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "MPA support for Waibu Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -3,6 +3,7 @@
3
3
  ## 2026-01-17
4
4
 
5
5
  - [2.1.3] Bug fix on ```getAppTitle()```
6
+ - [2.1.4] Add capability to set custom theme & iconset through headers
6
7
 
7
8
  ## 2026-01-13
8
9