@abtnode/core 1.16.20-beta-ce2cd157 → 1.16.20-beta-20c7fb25
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/disk.js +24 -7
- package/lib/blocklet/storage/backup/base.js +2 -1
- package/lib/blocklet/storage/backup/blocklets.js +12 -7
- package/lib/blocklet/storage/backup/data.js +3 -11
- package/lib/blocklet/storage/utils/disk.js +41 -30
- package/lib/index.js +1 -0
- package/lib/util/ip.js +5 -0
- package/package.json +33 -32
|
@@ -15,6 +15,7 @@ const { sign } = require('@arcblock/jwt');
|
|
|
15
15
|
const sleep = require('@abtnode/util/lib/sleep');
|
|
16
16
|
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
17
17
|
const joinUrl = require('url-join');
|
|
18
|
+
const { sendToUser } = require('@blocklet/sdk/lib/util/send-notification');
|
|
18
19
|
|
|
19
20
|
const logger = require('@abtnode/logger')('@abtnode/core:blocklet:manager');
|
|
20
21
|
const {
|
|
@@ -191,7 +192,6 @@ const {
|
|
|
191
192
|
updateSelectedResources,
|
|
192
193
|
} = require('../project');
|
|
193
194
|
const { callFederated } = require('../../util/federated');
|
|
194
|
-
const { isDnsIpMappingCorrect } = require('../../util/ip');
|
|
195
195
|
|
|
196
196
|
const { formatEnvironments, getBlockletMeta, validateOwner, isCLI } = util;
|
|
197
197
|
|
|
@@ -1435,6 +1435,29 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1435
1435
|
return newState;
|
|
1436
1436
|
}
|
|
1437
1437
|
|
|
1438
|
+
async sendEmail({ did, receiver, email }) {
|
|
1439
|
+
const blocklet = await this.getBlocklet(did);
|
|
1440
|
+
const nodeInfo = await states.node.read();
|
|
1441
|
+
const { permanentWallet } = getBlockletInfo(blocklet, nodeInfo.sk);
|
|
1442
|
+
// HACK: 因为发送方法是按照数组来处理的
|
|
1443
|
+
|
|
1444
|
+
const [result] = await sendToUser(
|
|
1445
|
+
receiver,
|
|
1446
|
+
JSON.parse(email),
|
|
1447
|
+
{
|
|
1448
|
+
appDid: permanentWallet.address,
|
|
1449
|
+
appSk: permanentWallet.secretKey,
|
|
1450
|
+
},
|
|
1451
|
+
undefined,
|
|
1452
|
+
undefined,
|
|
1453
|
+
'send-to-mail'
|
|
1454
|
+
);
|
|
1455
|
+
if (result && result.status === 'fulfilled') {
|
|
1456
|
+
return result.value;
|
|
1457
|
+
}
|
|
1458
|
+
throw new Error(result?.reason || 'failed to send email');
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1438
1461
|
async configNotification({ did, notification = {} }, context) {
|
|
1439
1462
|
let newConfig = {};
|
|
1440
1463
|
try {
|
|
@@ -2379,12 +2402,6 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
2379
2402
|
return;
|
|
2380
2403
|
}
|
|
2381
2404
|
|
|
2382
|
-
const correct = await isDnsIpMappingCorrect(blocklet.meta.did); // dns/ip 映射错误就跳过本次备份
|
|
2383
|
-
if (!correct) {
|
|
2384
|
-
logger.warn('Skipping automatic backups due to dns mapping errors', { appPid });
|
|
2385
|
-
return;
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
2405
|
const {
|
|
2389
2406
|
user: { did: userDid, locale },
|
|
2390
2407
|
} = context;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
/**
|
|
2
3
|
* @typedef {{
|
|
3
4
|
* appDid: string
|
|
@@ -117,7 +118,7 @@ class BaseBackup {
|
|
|
117
118
|
|
|
118
119
|
/**
|
|
119
120
|
*
|
|
120
|
-
* @param {
|
|
121
|
+
* @param {import('./data').DataBackup} dataBackup
|
|
121
122
|
* @param {Array<BaseBackup>} storages
|
|
122
123
|
* @returns {Promise<SyncObject[]>}
|
|
123
124
|
* @memberof BaseBackup
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { join } = require('path');
|
|
2
2
|
const validUrl = require('valid-url');
|
|
3
|
+
const pAll = require('p-all');
|
|
3
4
|
const { BaseBackup } = require('./base');
|
|
4
5
|
const { dirToZip } = require('../utils/zip');
|
|
5
6
|
const { compareAndMove } = require('../utils/hash');
|
|
@@ -35,7 +36,6 @@ class BlockletsBackup extends BaseBackup {
|
|
|
35
36
|
const zipPath = join(this.backupDir, 'blocklets', blockletMeta.name, `${blockletMeta.version}.zip`);
|
|
36
37
|
dirs.push({ sourceDir, zipPath });
|
|
37
38
|
}
|
|
38
|
-
|
|
39
39
|
await this.dirsToZip(dirs);
|
|
40
40
|
|
|
41
41
|
return {
|
|
@@ -76,12 +76,17 @@ class BlockletsBackup extends BaseBackup {
|
|
|
76
76
|
* @memberof BlockletsBackup
|
|
77
77
|
*/
|
|
78
78
|
async dirsToZip(dirs) {
|
|
79
|
-
await
|
|
80
|
-
dirs.map(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
await pAll(
|
|
80
|
+
dirs.map((dir) => {
|
|
81
|
+
return async () => {
|
|
82
|
+
const tempZipPath = `${dir.zipPath}.bak`;
|
|
83
|
+
await dirToZip(dir.sourceDir, tempZipPath);
|
|
84
|
+
await compareAndMove(dir.zipPath, tempZipPath);
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
{
|
|
88
|
+
concurrency: 4,
|
|
89
|
+
}
|
|
85
90
|
);
|
|
86
91
|
}
|
|
87
92
|
|
|
@@ -3,10 +3,6 @@ const { join } = require('path');
|
|
|
3
3
|
const { BaseBackup } = require('./base');
|
|
4
4
|
const { getFolderObjects } = require('../utils/disk');
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {import('./base').FileIncludeStats} FileIncludeStats
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
6
|
class DataBackup extends BaseBackup {
|
|
11
7
|
/**
|
|
12
8
|
*
|
|
@@ -25,15 +21,11 @@ class DataBackup extends BaseBackup {
|
|
|
25
21
|
* @return {Promise<import('@did-space/core').Object[]>}
|
|
26
22
|
* @memberof DataBackup
|
|
27
23
|
*/
|
|
28
|
-
collectSyncObjects() {
|
|
24
|
+
async collectSyncObjects() {
|
|
29
25
|
const blockletDataDir = join(this.serverDir, 'data', this.blocklet.meta.name);
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...x,
|
|
34
|
-
key: join('/data', x.key),
|
|
35
|
-
};
|
|
36
|
-
});
|
|
27
|
+
// @note: 存储到 did-spaces 的应用的 /data 目录下
|
|
28
|
+
const objects = await getFolderObjects(blockletDataDir, '/data');
|
|
37
29
|
|
|
38
30
|
return objects;
|
|
39
31
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
1
3
|
const fs = require('fs-extra');
|
|
2
4
|
const { join, basename } = require('path');
|
|
3
5
|
const logger = require('@abtnode/logger')('@abtnode/core:storage:utils:disk');
|
|
6
|
+
const FastGlob = require('fast-glob');
|
|
7
|
+
const mapValues = require('lodash/mapValues');
|
|
8
|
+
const xbytes = require('xbytes');
|
|
4
9
|
|
|
5
10
|
const backupDirName = '_abtnode/backup';
|
|
6
11
|
const restoreDirName = 'tmp/restore-disk';
|
|
@@ -94,38 +99,38 @@ function getFolderSize(folderPath) {
|
|
|
94
99
|
/**
|
|
95
100
|
* @description
|
|
96
101
|
* @param {string} path
|
|
97
|
-
* @
|
|
102
|
+
* @param {string} [prefix='']
|
|
103
|
+
* @return {Promise<Array<import('@did-space/core').Object>>}
|
|
98
104
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
// eslint-disable-next-line require-await
|
|
106
|
+
async function getFolderObjects(path, prefix = '') {
|
|
107
|
+
const stream = FastGlob.stream('**', {
|
|
108
|
+
cwd: path,
|
|
109
|
+
objectMode: true,
|
|
110
|
+
stats: true,
|
|
111
|
+
onlyFiles: true,
|
|
112
|
+
absolute: true,
|
|
113
|
+
dot: true,
|
|
114
|
+
concurrency: 2,
|
|
115
|
+
});
|
|
109
116
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
}
|
|
117
|
+
const objects = [];
|
|
118
|
+
// eslint-disable-next-line no-unreachable-loop
|
|
119
|
+
for await (const element of stream) {
|
|
120
|
+
/**
|
|
121
|
+
* @type {import('fast-glob').Entry}
|
|
122
|
+
*/
|
|
123
|
+
const entry = element;
|
|
124
|
+
const key = entry.path.replace(path, prefix);
|
|
125
|
+
const { stats } = entry;
|
|
126
|
+
|
|
127
|
+
objects.push({
|
|
128
|
+
key,
|
|
129
|
+
name: basename(key),
|
|
130
|
+
size: stats.size,
|
|
131
|
+
lastModified: new Date(stats.mtime).getTime(),
|
|
132
|
+
absolutePath: entry.path,
|
|
133
|
+
});
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
return objects;
|
|
@@ -157,6 +162,11 @@ function getFileObject(absolutePath, prefix = '') {
|
|
|
157
162
|
};
|
|
158
163
|
}
|
|
159
164
|
|
|
165
|
+
function formatMemoryUsage() {
|
|
166
|
+
const memoryUsage = process.memoryUsage();
|
|
167
|
+
return mapValues(memoryUsage, (x) => xbytes(x));
|
|
168
|
+
}
|
|
169
|
+
|
|
160
170
|
module.exports = {
|
|
161
171
|
getBackupList,
|
|
162
172
|
removeBackup,
|
|
@@ -164,4 +174,5 @@ module.exports = {
|
|
|
164
174
|
getFolderSize,
|
|
165
175
|
getFolderObjects,
|
|
166
176
|
getFileObject,
|
|
177
|
+
formatMemoryUsage,
|
|
167
178
|
};
|
package/lib/index.js
CHANGED
|
@@ -278,6 +278,7 @@ function ABTNode(options) {
|
|
|
278
278
|
syncFederated: blockletManager.syncFederated.bind(blockletManager),
|
|
279
279
|
loginFederated: blockletManager.loginFederated.bind(blockletManager),
|
|
280
280
|
configNotification: blockletManager.configNotification.bind(blockletManager),
|
|
281
|
+
sendEmail: blockletManager.sendEmail.bind(blockletManager),
|
|
281
282
|
updateWhoCanAccess: blockletManager.updateWhoCanAccess.bind(blockletManager),
|
|
282
283
|
updateAppSessionConfig: blockletManager.updateAppSessionConfig.bind(blockletManager),
|
|
283
284
|
updateComponentTitle: blockletManager.updateComponentTitle.bind(blockletManager),
|
package/lib/util/ip.js
CHANGED
|
@@ -30,6 +30,11 @@ const cron = {
|
|
|
30
30
|
options: { runOnInit: true, runInService: true },
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @description
|
|
35
|
+
* @param {string} did
|
|
36
|
+
* @return {Promise<boolean>}
|
|
37
|
+
*/
|
|
33
38
|
async function isDnsIpMappingCorrect(did) {
|
|
34
39
|
try {
|
|
35
40
|
const { internal, external } = await getIP();
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.20-beta-
|
|
6
|
+
"version": "1.16.20-beta-20c7fb25",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,39 +19,39 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/analytics": "1.16.20-beta-
|
|
23
|
-
"@abtnode/auth": "1.16.20-beta-
|
|
24
|
-
"@abtnode/certificate-manager": "1.16.20-beta-
|
|
25
|
-
"@abtnode/constant": "1.16.20-beta-
|
|
26
|
-
"@abtnode/cron": "1.16.20-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.20-beta-
|
|
28
|
-
"@abtnode/models": "1.16.20-beta-
|
|
29
|
-
"@abtnode/queue": "1.16.20-beta-
|
|
30
|
-
"@abtnode/rbac": "1.16.20-beta-
|
|
31
|
-
"@abtnode/router-provider": "1.16.20-beta-
|
|
32
|
-
"@abtnode/static-server": "1.16.20-beta-
|
|
33
|
-
"@abtnode/timemachine": "1.16.20-beta-
|
|
34
|
-
"@abtnode/util": "1.16.20-beta-
|
|
35
|
-
"@arcblock/did": "1.18.
|
|
36
|
-
"@arcblock/did-auth": "1.18.
|
|
37
|
-
"@arcblock/did-ext": "^1.18.
|
|
22
|
+
"@abtnode/analytics": "1.16.20-beta-20c7fb25",
|
|
23
|
+
"@abtnode/auth": "1.16.20-beta-20c7fb25",
|
|
24
|
+
"@abtnode/certificate-manager": "1.16.20-beta-20c7fb25",
|
|
25
|
+
"@abtnode/constant": "1.16.20-beta-20c7fb25",
|
|
26
|
+
"@abtnode/cron": "1.16.20-beta-20c7fb25",
|
|
27
|
+
"@abtnode/logger": "1.16.20-beta-20c7fb25",
|
|
28
|
+
"@abtnode/models": "1.16.20-beta-20c7fb25",
|
|
29
|
+
"@abtnode/queue": "1.16.20-beta-20c7fb25",
|
|
30
|
+
"@abtnode/rbac": "1.16.20-beta-20c7fb25",
|
|
31
|
+
"@abtnode/router-provider": "1.16.20-beta-20c7fb25",
|
|
32
|
+
"@abtnode/static-server": "1.16.20-beta-20c7fb25",
|
|
33
|
+
"@abtnode/timemachine": "1.16.20-beta-20c7fb25",
|
|
34
|
+
"@abtnode/util": "1.16.20-beta-20c7fb25",
|
|
35
|
+
"@arcblock/did": "1.18.105",
|
|
36
|
+
"@arcblock/did-auth": "1.18.105",
|
|
37
|
+
"@arcblock/did-ext": "^1.18.105",
|
|
38
38
|
"@arcblock/did-motif": "^1.1.13",
|
|
39
|
-
"@arcblock/did-util": "1.18.
|
|
40
|
-
"@arcblock/event-hub": "1.18.
|
|
41
|
-
"@arcblock/jwt": "^1.18.
|
|
39
|
+
"@arcblock/did-util": "1.18.105",
|
|
40
|
+
"@arcblock/event-hub": "1.18.105",
|
|
41
|
+
"@arcblock/jwt": "^1.18.105",
|
|
42
42
|
"@arcblock/pm2-events": "^0.0.5",
|
|
43
|
-
"@arcblock/validator": "^1.18.
|
|
44
|
-
"@arcblock/vc": "1.18.
|
|
45
|
-
"@blocklet/constant": "1.16.20-beta-
|
|
46
|
-
"@blocklet/env": "1.16.20-beta-
|
|
47
|
-
"@blocklet/meta": "1.16.20-beta-
|
|
48
|
-
"@blocklet/resolver": "1.16.20-beta-
|
|
49
|
-
"@blocklet/sdk": "1.16.20-beta-
|
|
50
|
-
"@did-space/client": "^0.3.
|
|
43
|
+
"@arcblock/validator": "^1.18.105",
|
|
44
|
+
"@arcblock/vc": "1.18.105",
|
|
45
|
+
"@blocklet/constant": "1.16.20-beta-20c7fb25",
|
|
46
|
+
"@blocklet/env": "1.16.20-beta-20c7fb25",
|
|
47
|
+
"@blocklet/meta": "1.16.20-beta-20c7fb25",
|
|
48
|
+
"@blocklet/resolver": "1.16.20-beta-20c7fb25",
|
|
49
|
+
"@blocklet/sdk": "1.16.20-beta-20c7fb25",
|
|
50
|
+
"@did-space/client": "^0.3.43",
|
|
51
51
|
"@fidm/x509": "^1.2.1",
|
|
52
|
-
"@ocap/mcrypto": "1.18.
|
|
53
|
-
"@ocap/util": "1.18.
|
|
54
|
-
"@ocap/wallet": "1.18.
|
|
52
|
+
"@ocap/mcrypto": "1.18.105",
|
|
53
|
+
"@ocap/util": "1.18.105",
|
|
54
|
+
"@ocap/wallet": "1.18.105",
|
|
55
55
|
"@slack/webhook": "^5.0.4",
|
|
56
56
|
"archiver": "^5.3.1",
|
|
57
57
|
"axios": "^0.27.2",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"lodash": "^4.17.21",
|
|
77
77
|
"lru-cache": "^6.0.0",
|
|
78
78
|
"node-stream-zip": "^1.15.0",
|
|
79
|
+
"p-all": "3.0.0",
|
|
79
80
|
"p-limit": "^3.1.0",
|
|
80
81
|
"p-retry": "4.6.1",
|
|
81
82
|
"read-last-lines": "^1.8.0",
|
|
@@ -101,5 +102,5 @@
|
|
|
101
102
|
"jest": "^27.5.1",
|
|
102
103
|
"unzipper": "^0.10.11"
|
|
103
104
|
},
|
|
104
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "cb9c7d84ca84283ccc6bf21264dfbef705a83abb"
|
|
105
106
|
}
|