@abtnode/core 1.16.11-next-470e8c41 → 1.16.11

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.
@@ -140,7 +140,7 @@ const UpgradeComponents = require('./helper/upgrade-components');
140
140
  const BlockletDownloader = require('../downloader/blocklet-downloader');
141
141
  const RollbackCache = require('./helper/rollback-cache');
142
142
  const { migrateApplicationToStructV2 } = require('./helper/migrate-application-to-struct-v2');
143
- const { getBackupFilesUrlFromEndpoint, getBackupEndpoint } = require('../../util/spaces');
143
+ const { getBackupFilesUrlFromEndpoint, getBackupEndpoint, getSpaceNameByEndpoint } = require('../../util/spaces');
144
144
  const { validateAddSpaceGateway, validateUpdateSpaceGateway } = require('../../validators/space-gateway');
145
145
 
146
146
  const { formatEnvironments, getBlockletMeta, validateOwner } = util;
@@ -694,7 +694,6 @@ class BlockletManager extends BaseBlockletManager {
694
694
  logger.info('restart blocklet', { did });
695
695
  const blocklet = await this.getBlocklet(did);
696
696
  await this.checkControllerStatus(blocklet, 'restart');
697
-
698
697
  await states.blocklet.setBlockletStatus(did, BlockletStatus.stopping, { componentDids });
699
698
  const result = await states.blocklet.getBlocklet(did);
700
699
  this.emit(BlockletEvents.statusChange, result);
@@ -728,7 +727,6 @@ class BlockletManager extends BaseBlockletManager {
728
727
  // eslint-disable-next-line no-unused-vars
729
728
  async reload({ did, componentDids: list }, context) {
730
729
  const blocklet = await this.getBlocklet(did);
731
-
732
730
  await this.checkControllerStatus(blocklet, 'reload');
733
731
 
734
732
  const componentDids = (blocklet.children || [])
@@ -1686,7 +1684,7 @@ class BlockletManager extends BaseBlockletManager {
1686
1684
  const spaceGateways = await this.getBlockletSpaceGateways({ did });
1687
1685
 
1688
1686
  for (const s of spaceGateways) {
1689
- if (s.url === where?.url) {
1687
+ if (s.did === where?.did) {
1690
1688
  Object.assign(s, value);
1691
1689
  break;
1692
1690
  }
@@ -3134,32 +3132,39 @@ class BlockletManager extends BaseBlockletManager {
3134
3132
  */
3135
3133
  // eslint-disable-next-line no-unused-vars
3136
3134
  async _backupToSpaces({ blocklet, context }) {
3137
- const {
3138
- user: { did: userDid },
3139
- } = context;
3140
- const {
3141
- appDid,
3142
- meta: { did: appPid },
3143
- } = blocklet;
3144
-
3145
- const backup = await states.backup.start({
3146
- appPid,
3147
- userDid,
3148
- strategy: 1,
3149
- sourceUrl: path.join(this.dataDirs.tmp, 'backup', appDid),
3150
- });
3135
+ try {
3136
+ const {
3137
+ user: { did: userDid },
3138
+ } = context;
3139
+ const {
3140
+ appDid,
3141
+ meta: { did: appPid },
3142
+ } = blocklet;
3143
+ const endpoint = getBackupEndpoint(blocklet.environments);
3144
+
3145
+ const backup = await states.backup.start({
3146
+ appPid,
3147
+ userDid,
3148
+ strategy: 1,
3149
+ sourceUrl: path.join(this.dataDirs.tmp, 'backup', appDid),
3150
+ targetName: await getSpaceNameByEndpoint(endpoint, 'DID Space'),
3151
+ });
3151
3152
 
3152
- this.backupQueue.push(
3153
- {
3154
- entity: 'blocklet',
3155
- action: 'backupToSpaces',
3156
- id: appDid,
3157
- blocklet,
3158
- context,
3159
- backup,
3160
- },
3161
- appDid
3162
- );
3153
+ this.backupQueue.push(
3154
+ {
3155
+ entity: 'blocklet',
3156
+ action: 'backupToSpaces',
3157
+ id: appDid,
3158
+ blocklet,
3159
+ context,
3160
+ backup,
3161
+ },
3162
+ appDid
3163
+ );
3164
+ } catch (error) {
3165
+ logger.error(error);
3166
+ throw error;
3167
+ }
3163
3168
  }
3164
3169
 
3165
3170
  /**
@@ -15,6 +15,7 @@ const validateBackup = Joi.object({
15
15
  // 如果存储在 Spaces, 形如: https://bbqaw5mgxc6fnihrwqcejcxvukkdgkk4anwxwk5msvm.did.abtnet.io/app/space/zNKhe8jwgNZX2z7ZUfwNddNECxSe3wyg7VtS
16
16
  // 如果存储在 Local,形如: /User/allen/discuss-kit
17
17
  target: Joi.string().valid('Spaces', 'Local').optional().default('Spaces'),
18
+ targetName: Joi.string().required(),
18
19
  targetUrl: Joi.string().optional().allow('').default(''),
19
20
 
20
21
  createdAt: Joi.string()
@@ -1,4 +1,5 @@
1
1
  const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/constant');
2
+ const { default: axios } = require('axios');
2
3
  const isUrl = require('is-url');
3
4
  const isArray = require('lodash/isArray');
4
5
  const isEmpty = require('lodash/isEmpty');
@@ -45,8 +46,33 @@ function getDIDSpacesUrlFromEndpoint(endpoint) {
45
46
  return endpoint.replace(/\/api\/space\/.+/, '');
46
47
  }
47
48
 
49
+ /**
50
+ * @description
51
+ * @export
52
+ * @param {string} endpoint
53
+ * @param {string} [defaultValue='DID Space']
54
+ * @return {Promise<string >}
55
+ */
56
+ async function getSpaceNameByEndpoint(endpoint, defaultValue = '') {
57
+ try {
58
+ if (!isUrl(endpoint)) {
59
+ return '';
60
+ }
61
+
62
+ const { headers } = await axios.head(endpoint, {
63
+ timeout: 3000,
64
+ });
65
+
66
+ return headers['x-space-name'] ?? defaultValue;
67
+ } catch (error) {
68
+ console.error(error);
69
+ return defaultValue;
70
+ }
71
+ }
72
+
48
73
  module.exports = {
49
74
  getBackupEndpoint,
50
75
  getBackupFilesUrlFromEndpoint,
51
76
  getDIDSpacesUrlFromEndpoint,
77
+ getSpaceNameByEndpoint,
52
78
  };
@@ -7,6 +7,7 @@ const validateBackupStart = Joi.object({
7
7
 
8
8
  sourceUrl: Joi.string().required(),
9
9
  target: Joi.string().valid('Spaces', 'Local').optional().default('Spaces'),
10
+ targetName: Joi.string().required(),
10
11
  });
11
12
 
12
13
  const validateBackupSuccess = Joi.object({
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-next-470e8c41",
6
+ "version": "1.16.11",
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": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.16.11-next-470e8c41",
23
- "@abtnode/certificate-manager": "1.16.11-next-470e8c41",
24
- "@abtnode/constant": "1.16.11-next-470e8c41",
25
- "@abtnode/cron": "1.16.11-next-470e8c41",
26
- "@abtnode/logger": "1.16.11-next-470e8c41",
27
- "@abtnode/models": "1.16.11-next-470e8c41",
28
- "@abtnode/queue": "1.16.11-next-470e8c41",
29
- "@abtnode/rbac": "1.16.11-next-470e8c41",
30
- "@abtnode/router-provider": "1.16.11-next-470e8c41",
31
- "@abtnode/static-server": "1.16.11-next-470e8c41",
32
- "@abtnode/timemachine": "1.16.11-next-470e8c41",
33
- "@abtnode/util": "1.16.11-next-470e8c41",
34
- "@arcblock/did": "1.18.80",
35
- "@arcblock/did-auth": "1.18.80",
36
- "@arcblock/did-ext": "^1.18.80",
22
+ "@abtnode/auth": "1.16.11",
23
+ "@abtnode/certificate-manager": "1.16.11",
24
+ "@abtnode/constant": "1.16.11",
25
+ "@abtnode/cron": "1.16.11",
26
+ "@abtnode/logger": "1.16.11",
27
+ "@abtnode/models": "1.16.11",
28
+ "@abtnode/queue": "1.16.11",
29
+ "@abtnode/rbac": "1.16.11",
30
+ "@abtnode/router-provider": "1.16.11",
31
+ "@abtnode/static-server": "1.16.11",
32
+ "@abtnode/timemachine": "1.16.11",
33
+ "@abtnode/util": "1.16.11",
34
+ "@arcblock/did": "1.18.84",
35
+ "@arcblock/did-auth": "1.18.84",
36
+ "@arcblock/did-ext": "^1.18.84",
37
37
  "@arcblock/did-motif": "^1.1.10",
38
- "@arcblock/did-util": "1.18.80",
39
- "@arcblock/event-hub": "1.18.80",
40
- "@arcblock/jwt": "^1.18.80",
38
+ "@arcblock/did-util": "1.18.84",
39
+ "@arcblock/event-hub": "1.18.84",
40
+ "@arcblock/jwt": "^1.18.84",
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
- "@arcblock/validator": "^1.18.80",
43
- "@arcblock/vc": "1.18.80",
44
- "@blocklet/constant": "1.16.11-next-470e8c41",
45
- "@blocklet/meta": "1.16.11-next-470e8c41",
46
- "@blocklet/sdk": "1.16.11-next-470e8c41",
47
- "@did-space/client": "^0.2.113",
42
+ "@arcblock/validator": "^1.18.84",
43
+ "@arcblock/vc": "1.18.84",
44
+ "@blocklet/constant": "1.16.11",
45
+ "@blocklet/meta": "1.16.11",
46
+ "@blocklet/sdk": "1.16.11",
47
+ "@did-space/client": "^0.2.117",
48
48
  "@fidm/x509": "^1.2.1",
49
- "@ocap/mcrypto": "1.18.80",
50
- "@ocap/util": "1.18.80",
51
- "@ocap/wallet": "1.18.80",
49
+ "@ocap/mcrypto": "1.18.84",
50
+ "@ocap/util": "1.18.84",
51
+ "@ocap/wallet": "1.18.84",
52
52
  "@slack/webhook": "^5.0.4",
53
53
  "archiver": "^5.3.1",
54
54
  "axios": "^0.27.2",
@@ -96,5 +96,5 @@
96
96
  "express": "^4.18.2",
97
97
  "jest": "^27.5.1"
98
98
  },
99
- "gitHead": "2f27bfc6522fdf0db1e9b6df717144c98ae30390"
99
+ "gitHead": "bf1a5bd70ed2ee7cd044c6b629c18bbc900f1598"
100
100
  }