waibu-mpa 2.9.1 → 2.9.2

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.
@@ -3,21 +3,31 @@ async function resolveFile (req) {
3
3
  const { camelCase } = this.app.lib._
4
4
  const { fastGlob } = this.app.lib
5
5
  const id = camelCase(req.params.id)
6
- const plugin = getPlugin(id)
7
6
  let type = ''
7
+ let files
8
8
  if (req.query.type) type = `-${req.query.type}`
9
- if (id === 'main' && req.site) {
10
- // check site logo first, if any
11
- const dir = getPluginDataDir('dobo')
12
- const files = await fastGlob(`${dir}/attachment/SumbaSite/${req.site.id}/file/logo${type}.*`)
9
+ if (id !== 'main') {
10
+ const plugin = getPlugin(id)
11
+ files = await fastGlob(`${plugin.dir.pkg}/logo${type}.*`)
13
12
  if (files.length > 0) return files[0]
13
+ throw this.error('_notFound')
14
14
  }
15
- let files = await fastGlob(`${plugin.dir.pkg}/logo${type}.*`)
16
- if (files.length === 0) {
17
- files = await fastGlob(`${getPlugin('waibu').dir.pkg}/logo${type}.*`)
18
- if (files.length === 0) throw this.error('_notFound')
19
- }
20
- return files[0]
15
+ // 1. main
16
+ files = await fastGlob(`${this.app.main.dir.pkg}/logo${type}.*`)
17
+ // 2. site attachment
18
+ if (files.length > 0) return files[0]
19
+ let dir = getPluginDataDir('dobo')
20
+ files = await fastGlob(`${dir}/attachment/SumbaSite/${req.site.id}/file/logo${type}.*`)
21
+ if (files.length > 0) return files[0]
22
+ // 3. theme
23
+ const theme = this.app.waibuMpa.themes.find(item => item.name === req.theme)
24
+ files = await fastGlob(`${theme.plugin.dir.pkg}/extend/waibuStatic/asset/logo${type}.*`)
25
+ if (files.length > 0) return files[0]
26
+ // 4. default
27
+ dir = this.app.waibu.dir.pkg
28
+ files = await fastGlob(`${dir}/logo${type}.*`)
29
+ if (files.length > 0) return files[0]
30
+ throw this.error('_notFound')
21
31
  }
22
32
 
23
33
  async function logo (req, reply) {
@@ -34,10 +34,10 @@ async function meta (options) {
34
34
  else pageTitle = sprintf(formatter, title, this.app.waibuMpa.getAppTitle(req))
35
35
  $('head').append(`<title>${pageTitle}</title>`)
36
36
  // favicon
37
- const favicon = this.app.waibu.config.favicon
37
+ const favicon = this.app.waibuMpa.config.favicon
38
38
  if (favicon) {
39
39
  const mime = await importPkg('waibu:mime')
40
- const ext = favicon === true ? '.ico' : path.extname(favicon)
40
+ const ext = favicon === true ? '.png' : path.extname(favicon)
41
41
  const type = mime.getType(ext)
42
42
  items.push({ tag: 'link', href: `/favicon${ext}`, rel: 'icon', type })
43
43
  }
package/lib/favicon.js CHANGED
@@ -1,18 +1,24 @@
1
1
  async function handleFavicon () {
2
2
  if (!this.config.favicon) return
3
3
  const { getPluginFile, importModule, getPluginDataDir } = this.app.bajo
4
- const { fs, fastGlob } = this.app.lib
4
+ const { fs } = this.app.lib
5
5
  const handleDownload = await importModule('waibu:/lib/handle-download.js')
6
6
  const me = this
7
7
  this.webAppCtx.get('/favicon.:ext', async function (req, reply) {
8
- let file = getPluginFile('main:/favicon.png')
9
- if (!fs.existsSync(file)) file = getPluginFile('waibu:/favicon.png')
10
- if (req.site) {
8
+ // 1. main favicon
9
+ let file = getPluginFile(`main:/favicon.${req.params.ext}`)
10
+ if (!fs.existsSync(file)) {
11
11
  const dir = getPluginDataDir('dobo')
12
- const files = await fastGlob(`${dir}/attachment/SumbaSite/${req.site.id}/file/favicon.*`)
13
- if (files.length > 0) file = files[0]
12
+ // 2. site attachment
13
+ file = `${dir}/attachment/SumbaSite/${req.site.id}/file/favicon.${req.params.ext}`
14
+ }
15
+ if (!fs.existsSync(file)) {
16
+ const theme = me.app.waibuMpa.themes.find(item => item.name === req.theme)
17
+ // 3. static dir of theme
18
+ file = `${theme.plugin.dir.pkg}/extend/waibuStatic/asset/favicon.${req.params.ext}`
14
19
  }
15
- if (!fs.existsSync(file)) return reply.code(404).send()
20
+ // 4. Default
21
+ if (!fs.existsSync(file)) file = getPluginFile('waibu:/favicon.png')
16
22
  reply.header('cache-control', 'max-age=86400')
17
23
  return await handleDownload.call(me, file, req, reply)
18
24
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-mpa",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "description": "MPA support for Waibu Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-15
4
+
5
+ - [2.9.2] Bug fix in ```favicon``` handler
6
+ - [2.9.2] Bug fix in ```logo``` route
7
+
3
8
  ## 2026-03-13
4
9
 
5
10
  - [2.9.1] Bug fix in route ```logo```. If nothing found at all, defaults to waibu logos