@abtnode/util 1.16.0-beta-b16cb035 → 1.16.0-beta-1d6c582e

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.
@@ -4,6 +4,13 @@ const get = require('lodash/get');
4
4
 
5
5
  const logger = require('@abtnode/logger')('@abtnode/util:logo-middleware');
6
6
 
7
+ /**
8
+ *
9
+ * @param {import('express').Request} req
10
+ * @param {import('express').Response & {sendFallbackLogo: Function} } res
11
+ * @param {import('express').NextFunction} next
12
+ * @returns
13
+ */
7
14
  const ensureBlockletExist = async (req, res, next) => {
8
15
  const { blocklet } = req;
9
16
 
@@ -15,9 +22,17 @@ const ensureBlockletExist = async (req, res, next) => {
15
22
  next();
16
23
  };
17
24
 
25
+ /**
26
+ *
27
+ * @param {import('express').Request} req
28
+ * @param {import('express').Response & {sendFallbackLogo: Function} } res
29
+ * @param {import('express').NextFunction} next
30
+ * @returns
31
+ */
18
32
  const ensureCustomSquareLogo = async (req, res, next) => {
19
33
  const { blocklet, sendOptions } = req;
20
34
 
35
+ /** @type {string} */
21
36
  const customLogoSquare = get(blocklet, 'environmentObj.BLOCKLET_APP_LOGO_SQUARE');
22
37
 
23
38
  if (customLogoSquare) {
@@ -36,7 +51,20 @@ const ensureCustomSquareLogo = async (req, res, next) => {
36
51
  next();
37
52
  };
38
53
 
54
+ /**
55
+ *
56
+ * @param {import('express').Request} req
57
+ * @param {import('express').Response & {sendFallbackLogo: Function} } res
58
+ * @param {import('express').NextFunction} next
59
+ * @returns
60
+ */
39
61
  const ensureBundleLogo = async (req, res, next) => {
62
+ /**
63
+ * @type {{
64
+ * blocklet: import('@abtnode/client').BlockletState, // 目前肯定是不准确的,但是有些属性是通用的,无伤大雅
65
+ * sendOptions: any
66
+ * }}
67
+ * */
40
68
  const { blocklet, sendOptions } = req;
41
69
 
42
70
  if (blocklet.meta.logo) {
@@ -51,7 +79,13 @@ const ensureBundleLogo = async (req, res, next) => {
51
79
  next();
52
80
  };
53
81
 
54
- const fallbackLogo = async (req, res) => {
82
+ /**
83
+ *
84
+ * @param {import('express').Request} _req
85
+ * @param {import('express').Response & {sendFallbackLogo: Function} } res
86
+ * @returns
87
+ */
88
+ const fallbackLogo = async (_req, res) => {
55
89
  res.sendFallbackLogo();
56
90
  };
57
91
 
@@ -61,7 +95,20 @@ const cacheError = async (err, req, res, next) => {
61
95
  res.sendFallbackLogo();
62
96
  };
63
97
 
98
+ /**
99
+ *
100
+ * @param {import('express').Request} req
101
+ * @param {import('express').Response & {sendFallbackLogo: Function} } res
102
+ * @param {import('express').NextFunction} next
103
+ * @returns
104
+ */
64
105
  const ensureDefaultLogo = async (req, res, next) => {
106
+ /**
107
+ * @type {{
108
+ * blocklet: import('@abtnode/client').BlockletState, // 目前肯定是不准确的,但是有些属性是通用的,无伤大雅
109
+ * sendOptions: any
110
+ * }}
111
+ * */
65
112
  const { blocklet, sendOptions } = req;
66
113
 
67
114
  if (blocklet && get(blocklet, 'env.dataDir')) {
@@ -83,7 +130,20 @@ const ensureDefaultLogo = async (req, res, next) => {
83
130
  next();
84
131
  };
85
132
 
133
+ /**
134
+ *
135
+ * @param {import('express').Request} req
136
+ * @param {import('express').Response & {sendFallbackLogo: Function} } res
137
+ * @param {import('express').NextFunction} next
138
+ * @returns
139
+ */
86
140
  const ensureCustomFavicon = async (req, res, next) => {
141
+ /**
142
+ * @type {{
143
+ * blocklet: import('@abtnode/client').BlockletState, // 目前肯定是不准确的,但是有些属性是通用的,无伤大雅
144
+ * sendOptions: any
145
+ * }}
146
+ * */
87
147
  const { blocklet, sendOptions } = req;
88
148
 
89
149
  const customLogoFavicon = get(blocklet, 'environmentObj.BLOCKLET_APP_LOGO_FAVICON');
package/lib/logo.js ADDED
@@ -0,0 +1,46 @@
1
+ const { existsSync } = require('fs-extra');
2
+ const isUrl = require('is-url');
3
+ const { join } = require('path');
4
+ const axios = require('./axios');
5
+
6
+ /**
7
+ *
8
+ *
9
+ * @param {{
10
+ * customLogoSquareUrl?: string;
11
+ * appDir: string;
12
+ * logo?: string;
13
+ * defaultLogoPath?: string;
14
+ * }}{ blocklet }
15
+ * @return {Promise<string | undefined>}
16
+ */
17
+ async function getLogoUrl({ customLogoSquareUrl, appDir, logo, defaultLogoPath }) {
18
+ if (customLogoSquareUrl) {
19
+ if (isUrl(customLogoSquareUrl)) {
20
+ const res = await axios.get(customLogoSquareUrl, { responseType: 'stream' }).catch(() => {
21
+ return { data: null };
22
+ });
23
+ if (res.data) {
24
+ return customLogoSquareUrl;
25
+ }
26
+ } else if (appDir) {
27
+ const localCustomLogoSquareUrl = join(appDir, customLogoSquareUrl);
28
+ if (existsSync(localCustomLogoSquareUrl)) {
29
+ return localCustomLogoSquareUrl;
30
+ }
31
+ }
32
+ }
33
+
34
+ if (appDir && logo) {
35
+ const metaLogoPath = join(appDir, logo);
36
+ if (existsSync(metaLogoPath)) {
37
+ return metaLogoPath;
38
+ }
39
+ }
40
+
41
+ return defaultLogoPath;
42
+ }
43
+
44
+ module.exports = {
45
+ getLogoUrl,
46
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.0-beta-b16cb035",
6
+ "version": "1.16.0-beta-1d6c582e",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,13 +18,13 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.0-beta-b16cb035",
22
- "@abtnode/logger": "1.16.0-beta-b16cb035",
23
- "@arcblock/jwt": "^1.18.59",
24
- "@blocklet/constant": "1.16.0-beta-b16cb035",
25
- "@ocap/mcrypto": "1.18.59",
26
- "@ocap/util": "1.18.59",
27
- "@ocap/wallet": "1.18.59",
21
+ "@abtnode/constant": "1.16.0-beta-1d6c582e",
22
+ "@abtnode/logger": "1.16.0-beta-1d6c582e",
23
+ "@arcblock/jwt": "^1.18.62",
24
+ "@blocklet/constant": "1.16.0-beta-1d6c582e",
25
+ "@ocap/mcrypto": "1.18.62",
26
+ "@ocap/util": "1.18.62",
27
+ "@ocap/wallet": "1.18.62",
28
28
  "archiver": "^5.3.1",
29
29
  "axios": "^0.27.2",
30
30
  "axios-mock-adapter": "^1.21.2",
@@ -42,6 +42,7 @@
42
42
  "hpagent": "^1.1.0",
43
43
  "internal-ip": "^6.2.0",
44
44
  "is-docker": "^2.2.1",
45
+ "is-url": "^1.2.4",
45
46
  "json-stable-stringify": "^1.0.1",
46
47
  "lodash": "^4.17.21",
47
48
  "multiformats": "9.9.0",
@@ -70,5 +71,5 @@
70
71
  "jest": "^27.5.1",
71
72
  "unzipper": "^0.10.11"
72
73
  },
73
- "gitHead": "138bd91aee5a35b28c2de4e1e924c44932efaf3a"
74
+ "gitHead": "209fa1413ae05d8961942b2c21f2d83df66f4b68"
74
75
  }