@abtnode/core 1.16.0-beta-8ee536d7 → 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.
- package/lib/blocklet/manager/helper/install-component-from-upload.js +1 -1
- package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +1 -1
- package/lib/blocklet/manager/helper/upgrade-components.js +6 -2
- package/lib/blocklet/storage/backup/blocklet.js +63 -2
- package/lib/blocklet/storage/backup/spaces.js +8 -2
- package/lib/blocklet/storage/restore/spaces.js +1 -1
- package/lib/util/blocklet.js +33 -0
- package/package.json +18 -18
|
@@ -138,7 +138,7 @@ const diff = async ({ did, hashFiles: clientFiles, rootDid: inputRootDid, states
|
|
|
138
138
|
|
|
139
139
|
const rootBlocklet = await states.blocklet.getBlocklet(rootDid);
|
|
140
140
|
if (childDid && !rootBlocklet) {
|
|
141
|
-
throw new Error(
|
|
141
|
+
throw new Error(`Root blocklet does not exist: ${rootDid}`);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
const state = childDid ? await (rootBlocklet.children || []).find((x) => x.meta.did === childDid) : rootBlocklet;
|
|
@@ -250,7 +250,7 @@ const migrateApplicationToStructV2 = async ({ did, appSk: newAppSk, context = {}
|
|
|
250
250
|
// add root component to blockletData
|
|
251
251
|
const { source, deployedFrom } = component;
|
|
252
252
|
let bundleSource;
|
|
253
|
-
if (source === BlockletSource.
|
|
253
|
+
if (source === BlockletSource.registry && deployedFrom && component.meta.bundleName) {
|
|
254
254
|
bundleSource = {
|
|
255
255
|
store: component.deployedFrom,
|
|
256
256
|
name: component.meta.bundleName,
|
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
checkStructVersion,
|
|
14
14
|
checkVersionCompatibility,
|
|
15
15
|
validateBlocklet,
|
|
16
|
+
getFixedBundleSource,
|
|
16
17
|
} = require('../../../util/blocklet');
|
|
17
18
|
|
|
18
19
|
const check = async ({ did, states }) => {
|
|
@@ -24,7 +25,10 @@ const check = async ({ did, states }) => {
|
|
|
24
25
|
const newChildren = [];
|
|
25
26
|
|
|
26
27
|
for (const child of newBlocklet.children || []) {
|
|
27
|
-
|
|
28
|
+
// There may be dirty data without bundleSource but with source and deployedFrom
|
|
29
|
+
const bundleSource = getFixedBundleSource(child);
|
|
30
|
+
|
|
31
|
+
if (bundleSource) {
|
|
28
32
|
const {
|
|
29
33
|
staticComponents: [newChild],
|
|
30
34
|
dynamicComponents,
|
|
@@ -32,7 +36,7 @@ const check = async ({ did, states }) => {
|
|
|
32
36
|
meta: {
|
|
33
37
|
staticComponents: [
|
|
34
38
|
{
|
|
35
|
-
source:
|
|
39
|
+
source: bundleSource,
|
|
36
40
|
name: child.meta.name,
|
|
37
41
|
title: child.meta.title,
|
|
38
42
|
mountPoint: child.mountPoint,
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
const { removeSync, outputJsonSync } = require('fs-extra');
|
|
1
|
+
const { removeSync, outputJsonSync, createWriteStream, createReadStream } = require('fs-extra');
|
|
2
2
|
const { cloneDeep } = require('lodash');
|
|
3
|
-
const { join } = require('path');
|
|
3
|
+
const { join, basename } = require('path');
|
|
4
|
+
const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/constant');
|
|
5
|
+
const isEmpty = require('lodash/isEmpty');
|
|
6
|
+
const streamToPromise = require('stream-to-promise');
|
|
7
|
+
const axios = require('@abtnode/util/lib/axios');
|
|
8
|
+
const isUrl = require('is-url');
|
|
9
|
+
const { getLogoUrl } = require('@abtnode/util/lib/logo');
|
|
4
10
|
const { BaseBackup } = require('./base');
|
|
5
11
|
|
|
6
12
|
class BlockletBackup extends BaseBackup {
|
|
@@ -8,6 +14,10 @@ class BlockletBackup extends BaseBackup {
|
|
|
8
14
|
|
|
9
15
|
async export() {
|
|
10
16
|
const blocklet = await this.cleanData();
|
|
17
|
+
|
|
18
|
+
const targetLogoPath = await this.writeLogoFile();
|
|
19
|
+
blocklet.meta.appLogo = basename(targetLogoPath);
|
|
20
|
+
|
|
11
21
|
removeSync(join(this.backupDir, this.filename));
|
|
12
22
|
outputJsonSync(join(this.backupDir, this.filename), blocklet);
|
|
13
23
|
}
|
|
@@ -65,6 +75,57 @@ class BlockletBackup extends BaseBackup {
|
|
|
65
75
|
|
|
66
76
|
return info;
|
|
67
77
|
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
*
|
|
82
|
+
* @param {string} target
|
|
83
|
+
* @returns {Promise<string>}
|
|
84
|
+
* @memberof DataBackup
|
|
85
|
+
*/
|
|
86
|
+
async writeLogoFile() {
|
|
87
|
+
const customLogoSquareUrl = this.blocklet.environments.find(
|
|
88
|
+
(e) => e.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO_SQUARE
|
|
89
|
+
)?.value;
|
|
90
|
+
const appDir = this.blocklet.environments.find((e) => e.key === 'BLOCKLET_APP_DIR')?.value;
|
|
91
|
+
const logo = this.blocklet?.meta?.logo;
|
|
92
|
+
const defaultLogoPath = join(this.serverDir, 'data', this.blocklet.meta.name, 'logo.svg');
|
|
93
|
+
|
|
94
|
+
const logoUrl = await getLogoUrl({
|
|
95
|
+
customLogoSquareUrl,
|
|
96
|
+
appDir,
|
|
97
|
+
logo,
|
|
98
|
+
defaultLogoPath,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const logoStream = await this.getLogoStream(logoUrl);
|
|
102
|
+
const targetLogoPath = join(this.backupDir, 'data', basename(logoUrl));
|
|
103
|
+
await streamToPromise(logoStream.pipe(createWriteStream(targetLogoPath)));
|
|
104
|
+
|
|
105
|
+
return targetLogoPath;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
*
|
|
111
|
+
* @param {string} logoUrl
|
|
112
|
+
* @returns {Promise<NodeJS.ReadStream>}
|
|
113
|
+
* @memberof DataBackup
|
|
114
|
+
*/
|
|
115
|
+
async getLogoStream(logoUrl) {
|
|
116
|
+
if (isEmpty(logoUrl)) {
|
|
117
|
+
throw new Error(`logoUrl(${logoUrl}) cannot be empty`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (isUrl(logoUrl)) {
|
|
121
|
+
const res = await axios.get(logoUrl, {
|
|
122
|
+
responseType: 'stream',
|
|
123
|
+
});
|
|
124
|
+
return res.data;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return createReadStream(logoUrl);
|
|
128
|
+
}
|
|
68
129
|
}
|
|
69
130
|
|
|
70
131
|
module.exports = { BlockletBackup };
|
|
@@ -98,7 +98,6 @@ class SpacesBackup {
|
|
|
98
98
|
new BlockletsBackup(this.input),
|
|
99
99
|
new BlockletExtrasBackup(this.input),
|
|
100
100
|
new RoutingRuleBackup(this.input),
|
|
101
|
-
new DataBackup(this.input),
|
|
102
101
|
];
|
|
103
102
|
}
|
|
104
103
|
|
|
@@ -151,12 +150,19 @@ class SpacesBackup {
|
|
|
151
150
|
progress: 15,
|
|
152
151
|
completed: false,
|
|
153
152
|
});
|
|
153
|
+
|
|
154
|
+
// @note: dataBackup 需要先于 blockletBackup 执行,并且 blockletBackup 与其他 backup的执行可以是无序的
|
|
155
|
+
const dataBackup = new DataBackup(this.input);
|
|
156
|
+
dataBackup.ensureParams(this);
|
|
157
|
+
await dataBackup.export();
|
|
158
|
+
|
|
154
159
|
await Promise.all(
|
|
155
160
|
this.storages.map((storage) => {
|
|
156
161
|
storage.ensureParams(this);
|
|
157
162
|
return storage.export();
|
|
158
163
|
})
|
|
159
164
|
);
|
|
165
|
+
|
|
160
166
|
this.input.event.emit(BlockletEvents.backupProgress, {
|
|
161
167
|
appDid: this.input.appDid,
|
|
162
168
|
message: 'Data ready, start backup...',
|
|
@@ -201,7 +207,7 @@ class SpacesBackup {
|
|
|
201
207
|
const percent = (data.completed * 100) / data.total;
|
|
202
208
|
this.input.event.emit(BlockletEvents.backupProgress, {
|
|
203
209
|
appDid: this.input.appDid,
|
|
204
|
-
message: `
|
|
210
|
+
message: `Uploading file ${basename(data.key)} (${data.completed}/${data.total})`,
|
|
205
211
|
// 0.8 是因为上传文件到 spaces 占进度的 80%,+ 20 是因为需要累加之前的进度
|
|
206
212
|
progress: +Math.ceil(percent * 0.8).toFixed(2) + 20,
|
|
207
213
|
completed: false,
|
|
@@ -120,7 +120,7 @@ class SpacesRestore {
|
|
|
120
120
|
logger.info('restore progress', { appDid: this.input.appDid, data });
|
|
121
121
|
this.input.event.emit(BlockletEvents.restoreProgress, {
|
|
122
122
|
appDid: this.input.appDid,
|
|
123
|
-
message: `
|
|
123
|
+
message: `Downloading file ${basename(data.key)} (${data.completed}/${data.total})`,
|
|
124
124
|
});
|
|
125
125
|
},
|
|
126
126
|
|
package/lib/util/blocklet.js
CHANGED
|
@@ -1825,6 +1825,38 @@ const getBlockletKnownAs = (blocklet) => {
|
|
|
1825
1825
|
return alsoKnownAs.filter(Boolean).map(toDid);
|
|
1826
1826
|
};
|
|
1827
1827
|
|
|
1828
|
+
const getFixedBundleSource = (component) => {
|
|
1829
|
+
if (!component) {
|
|
1830
|
+
return null;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
if (component.bundleSource) {
|
|
1834
|
+
return component.bundleSource;
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
const { source, deployedFrom, meta: { bundleName } = {} } = component;
|
|
1838
|
+
|
|
1839
|
+
if (!deployedFrom) {
|
|
1840
|
+
return null;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
if (source === BlockletSource.registry && bundleName) {
|
|
1844
|
+
return {
|
|
1845
|
+
store: deployedFrom,
|
|
1846
|
+
name: bundleName,
|
|
1847
|
+
version: 'latest',
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
if (source === BlockletSource.url) {
|
|
1852
|
+
return {
|
|
1853
|
+
url: deployedFrom,
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
return null;
|
|
1858
|
+
};
|
|
1859
|
+
|
|
1828
1860
|
module.exports = {
|
|
1829
1861
|
consumeServerlessNFT,
|
|
1830
1862
|
forEachBlocklet,
|
|
@@ -1879,4 +1911,5 @@ module.exports = {
|
|
|
1879
1911
|
checkVersionCompatibility,
|
|
1880
1912
|
validateBlockletMeta,
|
|
1881
1913
|
getBlockletKnownAs,
|
|
1914
|
+
getFixedBundleSource,
|
|
1882
1915
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.0-beta-
|
|
6
|
+
"version": "1.16.0-beta-1d6c582e",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.16.0-beta-
|
|
23
|
-
"@abtnode/certificate-manager": "1.16.0-beta-
|
|
24
|
-
"@abtnode/constant": "1.16.0-beta-
|
|
25
|
-
"@abtnode/cron": "1.16.0-beta-
|
|
26
|
-
"@abtnode/db": "1.16.0-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.0-beta-
|
|
28
|
-
"@abtnode/queue": "1.16.0-beta-
|
|
29
|
-
"@abtnode/rbac": "1.16.0-beta-
|
|
30
|
-
"@abtnode/router-provider": "1.16.0-beta-
|
|
31
|
-
"@abtnode/static-server": "1.16.0-beta-
|
|
32
|
-
"@abtnode/timemachine": "1.16.0-beta-
|
|
33
|
-
"@abtnode/util": "1.16.0-beta-
|
|
22
|
+
"@abtnode/auth": "1.16.0-beta-1d6c582e",
|
|
23
|
+
"@abtnode/certificate-manager": "1.16.0-beta-1d6c582e",
|
|
24
|
+
"@abtnode/constant": "1.16.0-beta-1d6c582e",
|
|
25
|
+
"@abtnode/cron": "1.16.0-beta-1d6c582e",
|
|
26
|
+
"@abtnode/db": "1.16.0-beta-1d6c582e",
|
|
27
|
+
"@abtnode/logger": "1.16.0-beta-1d6c582e",
|
|
28
|
+
"@abtnode/queue": "1.16.0-beta-1d6c582e",
|
|
29
|
+
"@abtnode/rbac": "1.16.0-beta-1d6c582e",
|
|
30
|
+
"@abtnode/router-provider": "1.16.0-beta-1d6c582e",
|
|
31
|
+
"@abtnode/static-server": "1.16.0-beta-1d6c582e",
|
|
32
|
+
"@abtnode/timemachine": "1.16.0-beta-1d6c582e",
|
|
33
|
+
"@abtnode/util": "1.16.0-beta-1d6c582e",
|
|
34
34
|
"@arcblock/did": "1.18.62",
|
|
35
35
|
"@arcblock/did-motif": "^1.1.10",
|
|
36
36
|
"@arcblock/did-util": "1.18.62",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"@arcblock/jwt": "^1.18.62",
|
|
39
39
|
"@arcblock/pm2-events": "^0.0.5",
|
|
40
40
|
"@arcblock/vc": "1.18.62",
|
|
41
|
-
"@blocklet/constant": "1.16.0-beta-
|
|
42
|
-
"@blocklet/meta": "1.16.0-beta-
|
|
43
|
-
"@blocklet/sdk": "1.16.0-beta-
|
|
44
|
-
"@did-space/client": "^0.2.
|
|
41
|
+
"@blocklet/constant": "1.16.0-beta-1d6c582e",
|
|
42
|
+
"@blocklet/meta": "1.16.0-beta-1d6c582e",
|
|
43
|
+
"@blocklet/sdk": "1.16.0-beta-1d6c582e",
|
|
44
|
+
"@did-space/client": "^0.2.40",
|
|
45
45
|
"@fidm/x509": "^1.2.1",
|
|
46
46
|
"@ocap/client": "1.18.62",
|
|
47
47
|
"@ocap/mcrypto": "1.18.62",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"express": "^4.18.2",
|
|
92
92
|
"jest": "^27.5.1"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "209fa1413ae05d8961942b2c21f2d83df66f4b68"
|
|
95
95
|
}
|