@abtnode/util 1.16.17-beta-ce49fe0e → 1.16.17-beta-2ac96448

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.
@@ -78,7 +78,34 @@ const ensureCustomSquareLogo = (req, res, next) => {
78
78
  return;
79
79
  }
80
80
 
81
- const logoFile = path.join(get(blocklet, 'env.appDir'), customLogoSquare);
81
+ const logoFile = path.join(get(blocklet, 'env.dataDir'), customLogoSquare);
82
+ if (fs.existsSync(logoFile)) {
83
+ res.sendLogoFile(logoFile, sendOptions);
84
+ return;
85
+ }
86
+ }
87
+
88
+ next();
89
+ };
90
+
91
+ /**
92
+ * @param {import('express').Request & {blocklet: any, sendOptions: any}} req
93
+ * @param {import('express').Response & {sendFallbackLogo: Function, sendLogoFile: Function} } res
94
+ * @param {import('express').NextFunction} next
95
+ * @returns
96
+ */
97
+ const ensureCustomRectLogo = (req, res, next) => {
98
+ const { blocklet, sendOptions } = req;
99
+
100
+ /** @type {string} */
101
+ const logo = get(blocklet, 'environmentObj.BLOCKLET_APP_LOGO_RECT');
102
+ if (logo) {
103
+ if (logo.startsWith('http')) {
104
+ sendCustomRemoteFile(req, res, logo);
105
+ return;
106
+ }
107
+
108
+ const logoFile = path.join(get(blocklet, 'env.dataDir'), logo);
82
109
  if (fs.existsSync(logoFile)) {
83
110
  res.sendLogoFile(logoFile, sendOptions);
84
111
  return;
@@ -179,14 +206,15 @@ const ensureCustomFavicon = (req, res, next) => {
179
206
  * */
180
207
  const { blocklet, sendOptions } = req;
181
208
 
182
- const customLogoFavicon = get(blocklet, 'environmentObj.BLOCKLET_APP_LOGO_FAVICON');
183
- if (customLogoFavicon) {
184
- if (customLogoFavicon.startsWith('http')) {
185
- sendCustomRemoteFile(req, res, customLogoFavicon);
209
+ /** @type {string} */
210
+ const logo = get(blocklet, 'environmentObj.BLOCKLET_APP_LOGO_FAVICON');
211
+ if (logo) {
212
+ if (logo.startsWith('http')) {
213
+ sendCustomRemoteFile(req, res, logo);
186
214
  return;
187
215
  }
188
216
 
189
- const logoFile = path.join(get(blocklet, 'env.appDir'), customLogoFavicon);
217
+ const logoFile = path.join(get(blocklet, 'env.dataDir'), logo);
190
218
  if (fs.existsSync(logoFile)) {
191
219
  res.sendLogoFile(logoFile, sendOptions);
192
220
  return;
@@ -223,6 +251,7 @@ module.exports = {
223
251
  ensureCustomSquareLogo,
224
252
  ensureBundleLogo,
225
253
  ensureCustomFavicon,
254
+ ensureCustomRectLogo,
226
255
  ensureDefaultLogo,
227
256
  fallbackLogo,
228
257
  cacheError,
package/lib/logo.js CHANGED
@@ -9,12 +9,13 @@ const axios = require('./axios');
9
9
  * @param {{
10
10
  * customLogoSquareUrl?: string;
11
11
  * appDir: string;
12
+ * dataDir: string;
12
13
  * logo?: string;
13
14
  * defaultLogoPath?: string;
14
15
  * }}{ blocklet }
15
16
  * @return {Promise<string | undefined>}
16
17
  */
17
- async function getLogoUrl({ customLogoSquareUrl, appDir, logo, defaultLogoPath }) {
18
+ async function getLogoUrl({ customLogoSquareUrl, appDir, dataDir, logo, defaultLogoPath }) {
18
19
  if (customLogoSquareUrl) {
19
20
  if (isUrl(customLogoSquareUrl)) {
20
21
  const res = await axios.get(customLogoSquareUrl, { responseType: 'stream' }).catch(() => {
@@ -23,10 +24,14 @@ async function getLogoUrl({ customLogoSquareUrl, appDir, logo, defaultLogoPath }
23
24
  if (res.data) {
24
25
  return customLogoSquareUrl;
25
26
  }
26
- } else if (appDir) {
27
- const localCustomLogoSquareUrl = join(appDir, customLogoSquareUrl);
28
- if (existsSync(localCustomLogoSquareUrl)) {
29
- return localCustomLogoSquareUrl;
27
+ } else {
28
+ const logoInDataDir = dataDir && join(dataDir, customLogoSquareUrl);
29
+ const logoInAppDir = appDir && join(appDir, customLogoSquareUrl);
30
+ if (existsSync(logoInDataDir)) {
31
+ return logoInDataDir;
32
+ }
33
+ if (existsSync(logoInAppDir)) {
34
+ return logoInDataDir;
30
35
  }
31
36
  }
32
37
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.17-beta-ce49fe0e",
6
+ "version": "1.16.17-beta-2ac96448",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,10 +18,10 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.17-beta-ce49fe0e",
22
- "@abtnode/logger": "1.16.17-beta-ce49fe0e",
23
- "@blocklet/constant": "1.16.17-beta-ce49fe0e",
24
- "@blocklet/meta": "1.16.17-beta-ce49fe0e",
21
+ "@abtnode/constant": "1.16.17-beta-2ac96448",
22
+ "@abtnode/logger": "1.16.17-beta-2ac96448",
23
+ "@blocklet/constant": "1.16.17-beta-2ac96448",
24
+ "@blocklet/meta": "1.16.17-beta-2ac96448",
25
25
  "@ocap/client": "1.18.92",
26
26
  "@ocap/mcrypto": "1.18.92",
27
27
  "@ocap/util": "1.18.92",
@@ -76,5 +76,5 @@
76
76
  "fs-extra": "^10.1.0",
77
77
  "jest": "^27.5.1"
78
78
  },
79
- "gitHead": "d8a04ff2ef9cd52a02d019bc2c9a743785e869c3"
79
+ "gitHead": "3f18c2e1dd086879b22faf92b6b6954898ed72ef"
80
80
  }