@abtnode/util 1.16.26-beta-bdd2d7c0 → 1.16.26-beta-346cba92
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.
- package/lib/blocklet.js +52 -0
- package/lib/serverless.js +15 -0
- package/package.json +10 -10
package/lib/blocklet.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const { createHash } = require('crypto');
|
|
3
|
+
const isUrl = require('is-url');
|
|
4
|
+
const joinURL = require('url-join');
|
|
5
|
+
const { WELLKNOWN_SERVICE_PATH_PREFIX } = require('@abtnode/constant');
|
|
6
|
+
const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/constant');
|
|
7
|
+
|
|
8
|
+
const getLogoHash = (logo) => encodeURIComponent((logo || '').split('/').slice(-1)[0].slice(0, 7));
|
|
3
9
|
|
|
4
10
|
const getComponentApiKey = ({ serverSk, app, component } = {}) => {
|
|
5
11
|
if (!serverSk) {
|
|
@@ -19,8 +25,54 @@ const getComponentApiKey = ({ serverSk, app, component } = {}) => {
|
|
|
19
25
|
return token;
|
|
20
26
|
};
|
|
21
27
|
|
|
28
|
+
const formatLogoURL = (logoURL, defaultLogoURL) => {
|
|
29
|
+
if (!logoURL) {
|
|
30
|
+
return logoURL;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isUrl(logoURL)) {
|
|
34
|
+
const tmp = new URL(logoURL);
|
|
35
|
+
if (!tmp.searchParams.get('imageFilter')) {
|
|
36
|
+
tmp.searchParams.set('imageFilter', 'convert');
|
|
37
|
+
tmp.searchParams.set('f', 'png');
|
|
38
|
+
tmp.searchParams.set('h', '80');
|
|
39
|
+
|
|
40
|
+
return tmp.href;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return logoURL;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const tmp = new URL(defaultLogoURL);
|
|
47
|
+
if (!logoURL.endsWith('.svg')) {
|
|
48
|
+
tmp.searchParams.set('imageFilter', 'convert');
|
|
49
|
+
tmp.searchParams.set('f', 'png');
|
|
50
|
+
tmp.searchParams.set('h', '80');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
tmp.searchParams.set('hash', getLogoHash(logoURL));
|
|
54
|
+
return `${tmp.pathname}${tmp.search}`;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getBlockletLogos = (blocklet) => {
|
|
58
|
+
let appLogo = blocklet.environments?.find((x) => x.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO_SQUARE)?.value;
|
|
59
|
+
let appLogoRect = blocklet.environments?.find(
|
|
60
|
+
(x) => x.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO_RECT
|
|
61
|
+
)?.value;
|
|
62
|
+
|
|
63
|
+
appLogo = formatLogoURL(appLogo, `http://127.0.0.1${WELLKNOWN_SERVICE_PATH_PREFIX}/blocklet/logo`);
|
|
64
|
+
appLogoRect = formatLogoURL(appLogoRect, `http://127.0.0.1${WELLKNOWN_SERVICE_PATH_PREFIX}/blocklet/logo-rect`);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
appLogo: appLogo || joinURL(WELLKNOWN_SERVICE_PATH_PREFIX, '/blocklet/logo?imageFilter=convert&f=png&h=80'),
|
|
68
|
+
appLogoRect: appLogoRect || '',
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
22
72
|
module.exports = {
|
|
23
73
|
getComponentApiKey,
|
|
24
74
|
getAppImageCacheDir: (cacheDir) => path.join(cacheDir, '.services', 'image-filter'),
|
|
25
75
|
getAppOgCacheDir: (cacheDir) => path.join(cacheDir, '.services', 'open-graph'),
|
|
76
|
+
getBlockletLogos,
|
|
77
|
+
getLogoHash,
|
|
26
78
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { NODE_MODES } = require('@abtnode/constant');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if the node is in serverless mode
|
|
5
|
+
* @param {object} param
|
|
6
|
+
* @param {string} param.mode
|
|
7
|
+
* @param {string} param.previousMode
|
|
8
|
+
* @returns {boolean} whether the node is in serverless mode
|
|
9
|
+
*/
|
|
10
|
+
const isInServerlessMode = ({ mode, previousMode } = {}) =>
|
|
11
|
+
mode === NODE_MODES.SERVERLESS || previousMode === NODE_MODES.SERVERLESS;
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
isInServerlessMode,
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.26-beta-
|
|
6
|
+
"version": "1.16.26-beta-346cba92",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,14 +18,14 @@
|
|
|
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.26-beta-
|
|
22
|
-
"@abtnode/logger": "1.16.26-beta-
|
|
23
|
-
"@blocklet/constant": "1.16.26-beta-
|
|
24
|
-
"@blocklet/meta": "1.16.26-beta-
|
|
25
|
-
"@ocap/client": "1.18.
|
|
26
|
-
"@ocap/mcrypto": "1.18.
|
|
27
|
-
"@ocap/util": "1.18.
|
|
28
|
-
"@ocap/wallet": "1.18.
|
|
21
|
+
"@abtnode/constant": "1.16.26-beta-346cba92",
|
|
22
|
+
"@abtnode/logger": "1.16.26-beta-346cba92",
|
|
23
|
+
"@blocklet/constant": "1.16.26-beta-346cba92",
|
|
24
|
+
"@blocklet/meta": "1.16.26-beta-346cba92",
|
|
25
|
+
"@ocap/client": "1.18.115",
|
|
26
|
+
"@ocap/mcrypto": "1.18.115",
|
|
27
|
+
"@ocap/util": "1.18.115",
|
|
28
|
+
"@ocap/wallet": "1.18.115",
|
|
29
29
|
"archiver": "^7.0.1",
|
|
30
30
|
"axios": "^0.27.2",
|
|
31
31
|
"axios-mock-adapter": "^1.21.2",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"fs-extra": "^11.2.0",
|
|
77
77
|
"jest": "^29.7.0"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "389bb6584585302b9b12ec7133c73cb28b0d663b"
|
|
80
80
|
}
|