@abtnode/core 1.16.8-beta-186fd5aa → 1.16.8-beta-56e84f3c

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.
@@ -2,6 +2,7 @@ const { EventEmitter } = require('events');
2
2
  const fs = require('fs-extra');
3
3
  const path = require('path');
4
4
  const get = require('lodash/get');
5
+ const pick = require('lodash/pick');
5
6
  const { toBase58 } = require('@ocap/util');
6
7
 
7
8
  const defaultLogger = require('@abtnode/logger')('@abtnode/core:blocklet-downloader');
@@ -119,6 +120,7 @@ class BlockletDownloader extends EventEmitter {
119
120
  * @param {{
120
121
  * preDownload: ({ downloadList: Array<meta>, downloadComponentIds: Array<string> }) => any
121
122
  * postDownload: ({ downloadList: Array<meta>, downloadComponentIds: Array<string>, isCancelled: boolean }) => any
123
+ * onProgress: ({ step?: string, ...extras }) => any
122
124
  * skipCheckIntegrity: boolean
123
125
  * }} [options={}]
124
126
  * @return {*}
@@ -130,7 +132,7 @@ class BlockletDownloader extends EventEmitter {
130
132
 
131
133
  this.logger.info('Download Blocklet', { name, did });
132
134
 
133
- const { preDownload = () => {}, postDownload = () => {}, skipCheckIntegrity } = options;
135
+ const { preDownload = () => {}, postDownload = () => {}, skipCheckIntegrity, onProgress = () => {} } = options;
134
136
 
135
137
  const { downloadComponentIds, downloadList } = await this.getDownloadList({
136
138
  blocklet,
@@ -148,7 +150,14 @@ class BlockletDownloader extends EventEmitter {
148
150
  const tasks = [];
149
151
  for (const meta of downloadList) {
150
152
  const url = meta.dist.tarball;
151
- tasks.push(this.bundleDownloader.download(meta, did, url, options));
153
+ tasks.push(
154
+ this.bundleDownloader.download(meta, did, url, {
155
+ ...options,
156
+ onProgress: (data) => {
157
+ onProgress({ ...data, component: pick(meta, ['title', 'name', 'did', 'version']) });
158
+ },
159
+ })
160
+ );
152
161
  }
153
162
  const results = await Promise.all(tasks);
154
163
 
@@ -66,12 +66,15 @@ class BundleDownloader extends EventEmitter {
66
66
  this.downloadLocks[lockName] = lock;
67
67
  }
68
68
 
69
+ const onProgress = context.onProgress || (() => {});
70
+
69
71
  try {
70
72
  await lock.acquire();
71
73
  this.logger.info('downloaded blocklet for installing', { name, version, tarball, integrity });
72
74
  const cwd = path.join(this.downloadDir, 'download', name);
73
75
  await fs.ensureDir(cwd);
74
76
  this.logger.info('start download blocklet', { name, version, cwd, tarball, integrity });
77
+ onProgress({ status: 'downloading' });
75
78
  const tarballPath = await this._downloadTarball({
76
79
  name,
77
80
  did,
@@ -84,6 +87,7 @@ class BundleDownloader extends EventEmitter {
84
87
  rootDid,
85
88
  url,
86
89
  context,
90
+ onProgress,
87
91
  });
88
92
  this.logger.info('downloaded blocklet tar file', { name, version, tarballPath });
89
93
  if (tarballPath === downloadFile.CANCEL) {
@@ -92,7 +96,13 @@ class BundleDownloader extends EventEmitter {
92
96
  }
93
97
 
94
98
  // resolve tarball and mv tarball to cache after resolved
95
- await resolveDownload(tarballPath, this.installDir, { removeTarFile: false });
99
+ await resolveDownload(tarballPath, this.installDir, {
100
+ removeTarFile: false,
101
+ onProgress: ({ name: _name }) => {
102
+ onProgress({ status: 'extracting', name: _name });
103
+ },
104
+ });
105
+ onProgress({ status: 'completed' });
96
106
  await this._addCacheTarFile(tarballPath, integrity, getComponentBundleId({ meta }));
97
107
 
98
108
  this.logger.info('resolved blocklet tar file to install dir', { name, version });
@@ -130,7 +140,18 @@ class BundleDownloader extends EventEmitter {
130
140
  * @return {*}
131
141
  * @memberof BlockletManager
132
142
  */
133
- async _downloadTarball({ url, cwd, tarball, did, integrity, verify = true, ctrlStore = {}, rootDid, context = {} }) {
143
+ async _downloadTarball({
144
+ url,
145
+ cwd,
146
+ tarball,
147
+ did,
148
+ integrity,
149
+ verify = true,
150
+ ctrlStore = {},
151
+ rootDid,
152
+ context = {},
153
+ onProgress = () => {},
154
+ }) {
134
155
  fs.mkdirSync(cwd, { recursive: true });
135
156
 
136
157
  const tarballName = url.split('/').slice(-1)[0];
@@ -172,7 +193,20 @@ class BundleDownloader extends EventEmitter {
172
193
  headers['x-download-token'] = exist.token;
173
194
  }
174
195
 
175
- await downloadFile(url, path.join(cwd, tarballName), { cancelCtrl }, { ...context, headers });
196
+ await downloadFile(
197
+ url,
198
+ path.join(cwd, tarballName),
199
+ {
200
+ cancelCtrl,
201
+ onProgress: ({ total, current }) => {
202
+ onProgress({ status: 'downloading', total, current });
203
+ },
204
+ },
205
+ {
206
+ ...context,
207
+ headers,
208
+ }
209
+ );
176
210
 
177
211
  if (ctrlStore[rootDid]) {
178
212
  ctrlStore[rootDid].delete(did);
@@ -26,7 +26,7 @@ const asyncFs = fs.promises;
26
26
  const resolveDownload = async (
27
27
  tarFile,
28
28
  dist,
29
- { cwd = '/', removeTarFile = true, logger = defaultLogger, originalMeta } = {}
29
+ { cwd = '/', removeTarFile = true, logger = defaultLogger, originalMeta, onProgress } = {}
30
30
  ) => {
31
31
  // eslint-disable-next-line no-param-reassign
32
32
  tarFile = path.join(cwd, tarFile);
@@ -36,6 +36,9 @@ const resolveDownload = async (
36
36
  const downloadDir = path.join(path.dirname(tarFile), path.basename(tarFile, path.extname(tarFile)));
37
37
  const tmp = `${downloadDir}-tmp`;
38
38
  try {
39
+ if (typeof onProgress === 'function') {
40
+ onProgress({ name: 'blocklet.tar.gz' });
41
+ }
39
42
  await expandTarball({ source: tarFile, dest: tmp, strip: 0 });
40
43
  } catch (error) {
41
44
  logger.error('expand blocklet tar file error', { error });
@@ -78,6 +81,9 @@ const resolveDownload = async (
78
81
  }
79
82
  await validateBlockletEntry(downloadDir, meta);
80
83
 
84
+ if (typeof onProgress === 'function') {
85
+ onProgress({ name: 'blocklet.zip' });
86
+ }
81
87
  await ensureBlockletExpanded(meta, downloadDir);
82
88
 
83
89
  installDir = getBundleDir(dist, meta);
@@ -2122,7 +2122,7 @@ class BlockletManager extends BaseBlockletManager {
2122
2122
 
2123
2123
  if (level === 0) {
2124
2124
  component.diskInfo = await getDiskInfo(component, {
2125
- useFakeDiskInfo: !diskInfo,
2125
+ useFakeDiskInfo: !diskInfo || isBeforeInstalled(component.status),
2126
2126
  });
2127
2127
  }
2128
2128
 
@@ -2508,6 +2508,7 @@ class BlockletManager extends BaseBlockletManager {
2508
2508
  */
2509
2509
  async _downloadBlocklet(blocklet, context = {}) {
2510
2510
  const {
2511
+ appDid,
2511
2512
  meta: { did },
2512
2513
  } = blocklet;
2513
2514
 
@@ -2520,6 +2521,9 @@ class BlockletManager extends BaseBlockletManager {
2520
2521
  });
2521
2522
  this.emit(BlockletEvents.statusChange, blocklet1);
2522
2523
  },
2524
+ onProgress: async (data) => {
2525
+ this.emit(BlockletEvents.downloadBundleProgress, { appDid: appDid || did, meta: { did }, ...data });
2526
+ },
2523
2527
  postDownload: async ({ isCancelled }) => {
2524
2528
  if (!isCancelled) {
2525
2529
  // since preferences only exist in blocklet bundle, we need to populate then after downloaded
@@ -196,7 +196,12 @@ const installApplicationFromBackup = async ({
196
196
  try {
197
197
  logger.info('start download blocklet', { did });
198
198
  // 从 store 下载 blocklet
199
- await manager.blockletDownloader.download(blockletState, { skipCheckIntegrity: true });
199
+ await manager.blockletDownloader.download(blockletState, {
200
+ skipCheckIntegrity: true,
201
+ onProgress: async (data) => {
202
+ manager.emit(BlockletEvents.downloadBundleProgress, { appDid: wallet.address, meta: { did }, ...data });
203
+ },
204
+ });
200
205
  } catch (error) {
201
206
  logger.error('download blocklet failed', { did, error });
202
207
 
@@ -205,6 +210,10 @@ const installApplicationFromBackup = async ({
205
210
  throw error;
206
211
  }
207
212
  logger.info('start install blocklet', { did });
213
+
214
+ const state = await states.blocklet.setBlockletStatus(did, BlockletStatus.installing);
215
+ manager.emit(BlockletEvents.statusChange, state);
216
+
208
217
  return manager._installBlocklet({ did, context });
209
218
  }
210
219
 
@@ -87,9 +87,8 @@ const installComponentFromUpload = async ({
87
87
  };
88
88
  const index = newBlocklet.children.findIndex((child) => child.meta.did === meta.did);
89
89
  if (index >= 0) {
90
- // if upgrade, do not update mountPoint and title
90
+ // if upgrade, do not update mountPoint
91
91
  newChild.mountPoint = newBlocklet.children[index].mountPoint;
92
- newChild.meta.title = newBlocklet.children[index].meta.title;
93
92
  newBlocklet.children.splice(index, 1, newChild);
94
93
  } else {
95
94
  newBlocklet.children.push(newChild);
package/lib/event.js CHANGED
@@ -367,6 +367,7 @@ module.exports = ({
367
367
 
368
368
  BlockletEvents.backupProgress,
369
369
  BlockletEvents.restoreProgress,
370
+ BlockletEvents.downloadBundleProgress,
370
371
 
371
372
  BlockletEvents.spaceConnected,
372
373
  BlockletEvents.nftConsumed,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.8-beta-186fd5aa",
6
+ "version": "1.16.8-beta-56e84f3c",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,36 +19,36 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.16.8-beta-186fd5aa",
23
- "@abtnode/certificate-manager": "1.16.8-beta-186fd5aa",
24
- "@abtnode/constant": "1.16.8-beta-186fd5aa",
25
- "@abtnode/cron": "1.16.8-beta-186fd5aa",
26
- "@abtnode/db": "1.16.8-beta-186fd5aa",
27
- "@abtnode/logger": "1.16.8-beta-186fd5aa",
28
- "@abtnode/queue": "1.16.8-beta-186fd5aa",
29
- "@abtnode/rbac": "1.16.8-beta-186fd5aa",
30
- "@abtnode/router-provider": "1.16.8-beta-186fd5aa",
31
- "@abtnode/static-server": "1.16.8-beta-186fd5aa",
32
- "@abtnode/timemachine": "1.16.8-beta-186fd5aa",
33
- "@abtnode/util": "1.16.8-beta-186fd5aa",
34
- "@arcblock/did": "1.18.78",
35
- "@arcblock/did-auth": "1.18.78",
36
- "@arcblock/did-ext": "^1.18.78",
22
+ "@abtnode/auth": "1.16.8-beta-56e84f3c",
23
+ "@abtnode/certificate-manager": "1.16.8-beta-56e84f3c",
24
+ "@abtnode/constant": "1.16.8-beta-56e84f3c",
25
+ "@abtnode/cron": "1.16.8-beta-56e84f3c",
26
+ "@abtnode/db": "1.16.8-beta-56e84f3c",
27
+ "@abtnode/logger": "1.16.8-beta-56e84f3c",
28
+ "@abtnode/queue": "1.16.8-beta-56e84f3c",
29
+ "@abtnode/rbac": "1.16.8-beta-56e84f3c",
30
+ "@abtnode/router-provider": "1.16.8-beta-56e84f3c",
31
+ "@abtnode/static-server": "1.16.8-beta-56e84f3c",
32
+ "@abtnode/timemachine": "1.16.8-beta-56e84f3c",
33
+ "@abtnode/util": "1.16.8-beta-56e84f3c",
34
+ "@arcblock/did": "1.18.80",
35
+ "@arcblock/did-auth": "1.18.80",
36
+ "@arcblock/did-ext": "^1.18.80",
37
37
  "@arcblock/did-motif": "^1.1.10",
38
- "@arcblock/did-util": "1.18.78",
39
- "@arcblock/event-hub": "1.18.78",
40
- "@arcblock/jwt": "^1.18.78",
38
+ "@arcblock/did-util": "1.18.80",
39
+ "@arcblock/event-hub": "1.18.80",
40
+ "@arcblock/jwt": "^1.18.80",
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
- "@arcblock/validator": "^1.18.78",
43
- "@arcblock/vc": "1.18.78",
44
- "@blocklet/constant": "1.16.8-beta-186fd5aa",
45
- "@blocklet/meta": "1.16.8-beta-186fd5aa",
46
- "@blocklet/sdk": "1.16.8-beta-186fd5aa",
42
+ "@arcblock/validator": "^1.18.80",
43
+ "@arcblock/vc": "1.18.80",
44
+ "@blocklet/constant": "1.16.8-beta-56e84f3c",
45
+ "@blocklet/meta": "1.16.8-beta-56e84f3c",
46
+ "@blocklet/sdk": "1.16.8-beta-56e84f3c",
47
47
  "@did-space/client": "^0.2.91",
48
48
  "@fidm/x509": "^1.2.1",
49
- "@ocap/mcrypto": "1.18.78",
50
- "@ocap/util": "1.18.78",
51
- "@ocap/wallet": "1.18.78",
49
+ "@ocap/mcrypto": "1.18.80",
50
+ "@ocap/util": "1.18.80",
51
+ "@ocap/wallet": "1.18.80",
52
52
  "@slack/webhook": "^5.0.4",
53
53
  "archiver": "^5.3.1",
54
54
  "axios": "^0.27.2",
@@ -95,5 +95,5 @@
95
95
  "express": "^4.18.2",
96
96
  "jest": "^27.5.1"
97
97
  },
98
- "gitHead": "3150c3a5c3e041fe7f5a3902418d9d62adee3173"
98
+ "gitHead": "2abfe83fcd951169a59719addb3dc3c1bbf8789f"
99
99
  }