@abtnode/core 1.8.65-beta-5405baf2 → 1.8.65-beta-bfcc12ce
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/api/team.js +1 -0
- package/lib/blocklet/downloader/blocklet-downloader.js +33 -12
- package/lib/blocklet/manager/disk.js +293 -217
- package/lib/blocklet/manager/helper/install-from-backup.js +13 -4
- package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +4 -0
- package/lib/blocklet/storage/backup/blocklets.js +23 -29
- package/lib/blocklet/storage/backup/data.js +2 -2
- package/lib/blocklet/storage/backup/logs.js +3 -2
- package/lib/blocklet/storage/backup/spaces.js +3 -14
- package/lib/blocklet/storage/restore/blocklet-extras.js +8 -3
- package/lib/blocklet/storage/restore/blocklets.js +29 -11
- package/lib/blocklet/storage/restore/logs.js +21 -0
- package/lib/blocklet/storage/restore/spaces.js +6 -1
- package/lib/blocklet/storage/utils/hash.js +51 -0
- package/lib/blocklet/storage/utils/zip.js +43 -0
- package/lib/router/helper.js +82 -9
- package/lib/router/index.js +8 -1
- package/lib/states/blocklet.js +5 -2
- package/lib/util/blocklet.js +10 -7
- package/lib/validators/router.js +7 -1
- package/package.json +27 -25
package/lib/api/team.js
CHANGED
|
@@ -32,7 +32,10 @@ const isMetaFileExist = (dir) => {
|
|
|
32
32
|
* }}
|
|
33
33
|
* @returns {boolean}
|
|
34
34
|
*/
|
|
35
|
-
const needDownload = (
|
|
35
|
+
const needDownload = (
|
|
36
|
+
component,
|
|
37
|
+
{ installDir, logger = defaultLogger, cachedBundles = [], skipCheckIntegrity } = {}
|
|
38
|
+
) => {
|
|
36
39
|
if (component.mode === BLOCKLET_MODES.DEVELOPMENT) {
|
|
37
40
|
return false;
|
|
38
41
|
}
|
|
@@ -62,10 +65,15 @@ const needDownload = (component, { installDir, logger = defaultLogger, cachedBun
|
|
|
62
65
|
return false;
|
|
63
66
|
}
|
|
64
67
|
|
|
68
|
+
if (skipCheckIntegrity) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
// check integrity
|
|
66
73
|
|
|
67
74
|
const cachedBundle = cachedBundles.find((x) => x.bundleId === bundleId);
|
|
68
75
|
|
|
76
|
+
// FIXME: 不是新安装的组件不应该 check, 不应该 block 安装成功 https://github.com/blocklet/launcher/actions/runs/4184577090/jobs/7250416272
|
|
69
77
|
if (!cachedBundle) {
|
|
70
78
|
return true;
|
|
71
79
|
}
|
|
@@ -84,10 +92,12 @@ const needDownload = (component, { installDir, logger = defaultLogger, cachedBun
|
|
|
84
92
|
class BlockletDownloader extends EventEmitter {
|
|
85
93
|
/**
|
|
86
94
|
* @param {{
|
|
95
|
+
* installDir: string,
|
|
96
|
+
* downloadDir: string,
|
|
87
97
|
* cache: {
|
|
88
98
|
* set: (key: string, value: any) => Promise
|
|
89
99
|
* get: (key: string) => Promise<any>
|
|
90
|
-
* }
|
|
100
|
+
* },
|
|
91
101
|
* }}
|
|
92
102
|
*/
|
|
93
103
|
constructor({ installDir, downloadDir, cache, logger = defaultLogger }) {
|
|
@@ -106,20 +116,25 @@ class BlockletDownloader extends EventEmitter {
|
|
|
106
116
|
|
|
107
117
|
/**
|
|
108
118
|
* @param {{}} blocklet
|
|
109
|
-
* @param {{
|
|
119
|
+
* @param {{
|
|
120
|
+
* preDownload: ({ downloadList: Array<meta>, downloadComponentIds: Array<string> }) => any
|
|
121
|
+
* postDownload: ({ downloadList: Array<meta>, downloadComponentIds: Array<string>, isCancelled: boolean }) => any
|
|
122
|
+
* skipCheckIntegrity: boolean
|
|
123
|
+
* }} [options={}]
|
|
110
124
|
* @return {*}
|
|
111
125
|
*/
|
|
112
|
-
async download(blocklet,
|
|
126
|
+
async download(blocklet, options = {}) {
|
|
113
127
|
const {
|
|
114
128
|
meta: { name, did },
|
|
115
129
|
} = blocklet;
|
|
116
130
|
|
|
117
131
|
this.logger.info('Download Blocklet', { name, did });
|
|
118
132
|
|
|
119
|
-
const { preDownload = () => {}, postDownload = () => {} } =
|
|
133
|
+
const { preDownload = () => {}, postDownload = () => {}, skipCheckIntegrity } = options;
|
|
120
134
|
|
|
121
135
|
const { downloadComponentIds, downloadList } = await this.getDownloadList({
|
|
122
136
|
blocklet,
|
|
137
|
+
skipCheckIntegrity,
|
|
123
138
|
});
|
|
124
139
|
|
|
125
140
|
await preDownload({ downloadList, downloadComponentIds });
|
|
@@ -133,13 +148,15 @@ class BlockletDownloader extends EventEmitter {
|
|
|
133
148
|
const tasks = [];
|
|
134
149
|
for (const meta of downloadList) {
|
|
135
150
|
const url = meta.dist.tarball;
|
|
136
|
-
tasks.push(this.bundleDownloader.download(meta, did, url,
|
|
151
|
+
tasks.push(this.bundleDownloader.download(meta, did, url, options));
|
|
137
152
|
}
|
|
138
153
|
const results = await Promise.all(tasks);
|
|
139
154
|
|
|
140
|
-
|
|
155
|
+
const isCancelled = results.some((x) => x.isCancelled);
|
|
156
|
+
|
|
157
|
+
await postDownload({ downloadList, downloadComponentIds, isCancelled });
|
|
141
158
|
|
|
142
|
-
if (
|
|
159
|
+
if (isCancelled) {
|
|
143
160
|
return { isCancelled: true };
|
|
144
161
|
}
|
|
145
162
|
} catch (error) {
|
|
@@ -160,11 +177,11 @@ class BlockletDownloader extends EventEmitter {
|
|
|
160
177
|
* blocklet;
|
|
161
178
|
* }}
|
|
162
179
|
* @returns {{
|
|
163
|
-
* downloadList: Array<
|
|
164
|
-
* downloadComponentIds: Array<string>;
|
|
180
|
+
* downloadList: Array<import('@abtnode/client').BlockletMeta>;
|
|
181
|
+
* downloadComponentIds: Array<string>; // like: "z8ia1i2yq67x39vruqQTbkVcwCnqRGx8zSPsJ/z8iZwubkNdA1BfEUwc5NJpY2Jnfm7yEbyvmKS"
|
|
165
182
|
* }}
|
|
166
183
|
*/
|
|
167
|
-
async getDownloadList({ blocklet }) {
|
|
184
|
+
async getDownloadList({ blocklet, skipCheckIntegrity }) {
|
|
168
185
|
const downloadComponentIds = [];
|
|
169
186
|
const metas = {};
|
|
170
187
|
|
|
@@ -178,7 +195,11 @@ class BlockletDownloader extends EventEmitter {
|
|
|
178
195
|
return;
|
|
179
196
|
}
|
|
180
197
|
|
|
181
|
-
const needComponentDownload = needDownload(component, {
|
|
198
|
+
const needComponentDownload = needDownload(component, {
|
|
199
|
+
installDir: this.installDir,
|
|
200
|
+
cachedBundles,
|
|
201
|
+
skipCheckIntegrity,
|
|
202
|
+
});
|
|
182
203
|
if (!needComponentDownload) {
|
|
183
204
|
this.logger.info(`skip download existed bundle ${bundleId}`, { source: component.source });
|
|
184
205
|
return;
|