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
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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.
|
|
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 ? '.
|
|
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
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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