@abtnode/core 1.16.15-beta-a635f48d → 1.16.15-beta-89b542d3

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.
@@ -2690,25 +2690,29 @@ class DiskBlockletManager extends BaseBlockletManager {
2690
2690
  await this._runPostInstallHook(blocklet, context);
2691
2691
 
2692
2692
  logger.info('start migration');
2693
- try {
2693
+ {
2694
2694
  const oldVersions = {};
2695
2695
  forEachBlockletSync(oldBlocklet, (b, { id }) => {
2696
2696
  oldVersions[id] = b.meta.version;
2697
2697
  });
2698
2698
  const nodeEnvironments = await states.node.getEnvironments();
2699
- const runMigration = (b, { id, ancestors }) => {
2700
- return runMigrationScripts({
2701
- blocklet: b,
2702
- appDir: b.env.appDir,
2703
- env: getRuntimeEnvironments(b, nodeEnvironments, ancestors),
2704
- oldVersion: oldVersions[id],
2705
- newVersion: b.meta.version,
2706
- });
2699
+ const runMigration = async (b, { id, ancestors }) => {
2700
+ try {
2701
+ await runMigrationScripts({
2702
+ blocklet: b,
2703
+ appDir: b.env.appDir,
2704
+ env: getRuntimeEnvironments(b, nodeEnvironments, ancestors),
2705
+ oldVersion: oldVersions[id],
2706
+ newVersion: b.meta.version,
2707
+ ...getHooksOutputFiles(b),
2708
+ });
2709
+ } catch (error) {
2710
+ logger.error('Failed to run migration scripts', { appDid: did, title: b.meta.title, error });
2711
+ error.message = `Failed to run migration scripts for ${b.meta.title}: ${error.message}`;
2712
+ throw error;
2713
+ }
2707
2714
  };
2708
2715
  await forEachBlocklet(blocklet, runMigration, { parallel: true });
2709
- } catch (error) {
2710
- logger.error('Failed to migrate blocklet', { did, error });
2711
- throw error;
2712
2716
  }
2713
2717
  logger.info('end migration');
2714
2718
 
@@ -2798,7 +2802,7 @@ class DiskBlockletManager extends BaseBlockletManager {
2798
2802
  : BlockletEvents.componentUpgradeFailed;
2799
2803
 
2800
2804
  this.emit(notificationEvent, {
2801
- blocklet: { ...oldBlocklet, componentDids, error: { message: err.message } },
2805
+ blocklet: { ...newBlocklet, componentDids, error: { message: err.message } },
2802
2806
  context,
2803
2807
  });
2804
2808
 
@@ -20,6 +20,8 @@ async function runScripts({
20
20
  printInfo,
21
21
  printSuccess,
22
22
  printError,
23
+ output,
24
+ error,
23
25
  }) {
24
26
  // 获取所有待执行的脚本
25
27
  let scripts = [];
@@ -57,6 +59,8 @@ async function runScripts({
57
59
  cwd: appDir,
58
60
  env: getSafeEnv(env),
59
61
  silent: false,
62
+ output,
63
+ error,
60
64
  });
61
65
  printInfo(`Migration script executed: ${scriptPath}`);
62
66
  } catch (migrationErr) {
@@ -101,6 +105,8 @@ module.exports = async ({
101
105
  printInfo = logger.info,
102
106
  printSuccess = logger.info,
103
107
  printError = logger.error,
108
+ output,
109
+ error,
104
110
  }) => {
105
111
  if (!oldVersion) {
106
112
  return;
@@ -128,6 +134,8 @@ module.exports = async ({
128
134
  printError,
129
135
  printInfo,
130
136
  printSuccess,
137
+ output,
138
+ error,
131
139
  });
132
140
 
133
141
  fs.removeSync(backupDir);
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const fs = require('fs');
1
+ const fs = require('fs-extra');
2
2
  const path = require('path');
3
3
  const get = require('lodash/get');
4
4
  const uniq = require('lodash/uniq');
@@ -37,6 +37,7 @@ const pm2Events = require('./blocklet/manager/pm2-events');
37
37
  const { createStateReadyQueue, createStateReadyHandler } = require('./util/ready');
38
38
  const { createDataArchive } = require('./util/blocklet');
39
39
  const { toStatus, fromStatus, ensureDataDirs, getQueueConcurrencyByMem, getStateCrons } = require('./util');
40
+ const { clearCache } = require('./util/cache');
40
41
  const getMetaFromUrl = require('./util/get-meta-from-url');
41
42
 
42
43
  /**
@@ -320,6 +321,7 @@ function ABTNode(options) {
320
321
 
321
322
  // Gateway
322
323
  updateGateway: nodeAPI.updateGateway.bind(nodeAPI),
324
+ clearCache: (params) => clearCache(params, instance, blockletManager),
323
325
 
324
326
  // Team && Access control
325
327
 
package/lib/locales/en.js CHANGED
@@ -13,7 +13,7 @@ module.exports = flat({
13
13
  },
14
14
  isFull: 'The current Space storage space is full, please expand the space and back up again',
15
15
  lackOfSpace:
16
- 'The current available space in the storage is insufficient. Please expand the space and perform the backup again',
16
+ 'The current available space in the storage is insufficient, Please expand the space and perform the backup again',
17
17
  },
18
18
  },
19
19
  });
package/lib/locales/zh.js CHANGED
@@ -11,7 +11,7 @@ module.exports = flat({
11
11
  forbidden: '你还没有权限执行备份操作,请尝试在 DID Spaces 上恢复应用授权或者重新连接 DID Spaces 后重试',
12
12
  },
13
13
  isFull: '当前的空间存储空间已满,请扩展空间并再次备份',
14
- lackOfSpace: '当前存储空间的可用空间不足。请扩展空间后再次进行备份',
14
+ lackOfSpace: '当前存储空间的可用空间不足, 请扩展空间后再次进行备份',
15
15
  },
16
16
  },
17
17
  });
@@ -173,6 +173,14 @@ class Router {
173
173
  getLogDir() {
174
174
  return this.provider.getLogDir();
175
175
  }
176
+
177
+ searchCache(pattern) {
178
+ return this.provider.searchCache(pattern);
179
+ }
180
+
181
+ clearCache() {
182
+ return this.provider.clearCache();
183
+ }
176
184
  }
177
185
 
178
186
  Router.formatSites = (sites = []) => {
@@ -124,7 +124,11 @@ const getLogContent = async (action, args, context, result, info, node) => {
124
124
  case 'upgradeBlocklet':
125
125
  const actionName = result.action || 'upgraded';
126
126
  if (result.resultStatus === 'failed') {
127
- return `${actionName} component failed: **${getComponentNamesWithVersion(result, result.componentDids)}**`;
127
+ const errMsg = result.error?.message ? `: ${result.error.message}` : '';
128
+ return `${actionName} component failed: **${getComponentNamesWithVersion(
129
+ result,
130
+ result.componentDids
131
+ )}**${errMsg}`;
128
132
  }
129
133
  return `${actionName} component: **${getComponentNamesWithVersion(result, result.componentDids)}**`;
130
134
  case 'deleteComponent':
@@ -283,6 +287,8 @@ const getLogContent = async (action, args, context, result, info, node) => {
283
287
  return `updated routing rule **${args.rule?.from?.pathPrefix}** from ${site}`; // prettier-ignore
284
288
  case 'deleteRoutingRule':
285
289
  return `deleted routing rule from ${site}`; // prettier-ignore
290
+ case 'clearCache':
291
+ return args.pattern ? `cleared cache with pattern ${args.pattern}` : 'cleared all cache';
286
292
  case 'updateGateway': {
287
293
  const changes = [
288
294
  args.requestLimit.enabled ? `rate limit: enabled, rate: ${args.requestLimit.rate}` : 'rate limit: disabled',
@@ -389,6 +395,7 @@ const getLogCategory = (action) => {
389
395
  case 'issueLetsEncryptCert':
390
396
  return 'certificates';
391
397
 
398
+ case 'clearCache':
392
399
  case 'updateGateway':
393
400
  return 'gateway';
394
401
 
@@ -1,4 +1,5 @@
1
1
  const { Joi } = require('@arcblock/validator');
2
+ const { BACKUPS } = require('@abtnode/constant');
2
3
  const BaseState = require('./base');
3
4
  const {
4
5
  validateBackupSuccess,
@@ -29,7 +30,7 @@ const validateBackup = Joi.object({
29
30
  updatedAt: Joi.string().optional().default('').allow(''),
30
31
 
31
32
  // 0 表示成功了,建议使用常量表示,默认是 1 表示错误的, null 表示备份中
32
- status: Joi.number().optional().allow(null),
33
+ status: Joi.number().optional().allow(BACKUPS.STATUS.PROGRESS),
33
34
  // 发生错误的时候可以用来存储错误下信息
34
35
  message: Joi.string().optional().default('').allow(''),
35
36
 
@@ -101,7 +102,7 @@ class BackupState extends BaseState {
101
102
  {
102
103
  $set: {
103
104
  ...value,
104
- status: 0,
105
+ status: BACKUPS.STATUS.SUCCEEDED,
105
106
  updatedAt: new Date().toISOString(),
106
107
  },
107
108
  }
@@ -127,7 +128,7 @@ class BackupState extends BaseState {
127
128
  {
128
129
  $set: {
129
130
  ...value,
130
- status: 1,
131
+ status: BACKUPS.STATUS.FAILED,
131
132
  updatedAt: new Date().toISOString(),
132
133
  },
133
134
  }
@@ -0,0 +1,71 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const { forEachComponentV2 } = require('@blocklet/meta/lib/util');
4
+ const { getAppImageCacheDir, getAppOgCacheDir } = require('@abtnode/util/lib/blocklet');
5
+
6
+ const clearCacheDir = (dir) => {
7
+ if (fs.existsSync(dir)) {
8
+ fs.rmSync(dir, { recursive: true, force: true });
9
+ fs.ensureDirSync(dir);
10
+ }
11
+ };
12
+
13
+ /**
14
+ * The `clearCache` function is used to clear cache files based on different
15
+ * parameters and directories.
16
+ * @param params - { teamDid: string, pattern: string }
17
+ * @param node - the server instance.
18
+ * @param blockletManager - the blocklet manager instance.
19
+ * @returns String[] list of files removed from the cache.
20
+ */
21
+ const clearCache = async (params, node, blockletManager) => {
22
+ const baseDir = path.dirname(node.dataDirs.core);
23
+
24
+ // reset cache by pattern
25
+ const info = await node.getNodeInfo({ useCache: true });
26
+ const provider = node.getRouterProvider(info.routing.provider);
27
+ if (params.pattern) {
28
+ const files = await provider.searchCache(params.pattern);
29
+ files.forEach((x) => fs.rmSync(x, { force: true }));
30
+ return files.map((x) => x.replace(baseDir, ''));
31
+ }
32
+
33
+ const removed = [];
34
+
35
+ // reset server cache
36
+ if (params.teamDid === info.did) {
37
+ // reset all router cache
38
+ const result = await provider.clearCache();
39
+ removed.push(...result);
40
+
41
+ // reset global cache for external images used for open graph
42
+ const cacheDir = getAppOgCacheDir(node.dataDirs.tmp);
43
+ clearCacheDir(cacheDir);
44
+ removed.push(cacheDir);
45
+
46
+ return removed.map((x) => x.replace(baseDir, ''));
47
+ }
48
+
49
+ // reset blocklet cache
50
+ const blocklet = await blockletManager.getBlocklet(params.teamDid);
51
+ [getAppImageCacheDir(blocklet.env.cacheDir), getAppOgCacheDir(blocklet.env.cacheDir)].forEach((x) => {
52
+ clearCacheDir(x);
53
+ removed.push(x);
54
+ });
55
+ await forEachComponentV2(
56
+ blocklet,
57
+ async (component) => {
58
+ const files = await provider.searchCache(component.meta.did);
59
+ files.forEach((x) => fs.rmSync(x, { force: true }));
60
+ removed.push(...files);
61
+ },
62
+ { parallel: true, sync: true }
63
+ );
64
+
65
+ // FIXME: @wangshijun can we bust cache for image-filter in nginx?
66
+ return removed.map((x) => x.replace(baseDir, ''));
67
+ };
68
+
69
+ module.exports = {
70
+ clearCache,
71
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.15-beta-a635f48d",
6
+ "version": "1.16.15-beta-89b542d3",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,19 +19,19 @@
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.15-beta-a635f48d",
23
- "@abtnode/auth": "1.16.15-beta-a635f48d",
24
- "@abtnode/certificate-manager": "1.16.15-beta-a635f48d",
25
- "@abtnode/constant": "1.16.15-beta-a635f48d",
26
- "@abtnode/cron": "1.16.15-beta-a635f48d",
27
- "@abtnode/logger": "1.16.15-beta-a635f48d",
28
- "@abtnode/models": "1.16.15-beta-a635f48d",
29
- "@abtnode/queue": "1.16.15-beta-a635f48d",
30
- "@abtnode/rbac": "1.16.15-beta-a635f48d",
31
- "@abtnode/router-provider": "1.16.15-beta-a635f48d",
32
- "@abtnode/static-server": "1.16.15-beta-a635f48d",
33
- "@abtnode/timemachine": "1.16.15-beta-a635f48d",
34
- "@abtnode/util": "1.16.15-beta-a635f48d",
22
+ "@abtnode/analytics": "1.16.15-beta-89b542d3",
23
+ "@abtnode/auth": "1.16.15-beta-89b542d3",
24
+ "@abtnode/certificate-manager": "1.16.15-beta-89b542d3",
25
+ "@abtnode/constant": "1.16.15-beta-89b542d3",
26
+ "@abtnode/cron": "1.16.15-beta-89b542d3",
27
+ "@abtnode/logger": "1.16.15-beta-89b542d3",
28
+ "@abtnode/models": "1.16.15-beta-89b542d3",
29
+ "@abtnode/queue": "1.16.15-beta-89b542d3",
30
+ "@abtnode/rbac": "1.16.15-beta-89b542d3",
31
+ "@abtnode/router-provider": "1.16.15-beta-89b542d3",
32
+ "@abtnode/static-server": "1.16.15-beta-89b542d3",
33
+ "@abtnode/timemachine": "1.16.15-beta-89b542d3",
34
+ "@abtnode/util": "1.16.15-beta-89b542d3",
35
35
  "@arcblock/did": "1.18.89",
36
36
  "@arcblock/did-auth": "1.18.89",
37
37
  "@arcblock/did-ext": "^1.18.89",
@@ -42,11 +42,11 @@
42
42
  "@arcblock/pm2-events": "^0.0.5",
43
43
  "@arcblock/validator": "^1.18.89",
44
44
  "@arcblock/vc": "1.18.89",
45
- "@blocklet/constant": "1.16.15-beta-a635f48d",
46
- "@blocklet/env": "1.16.15-beta-a635f48d",
47
- "@blocklet/meta": "1.16.15-beta-a635f48d",
48
- "@blocklet/resolver": "1.16.15-beta-a635f48d",
49
- "@blocklet/sdk": "1.16.15-beta-a635f48d",
45
+ "@blocklet/constant": "1.16.15-beta-89b542d3",
46
+ "@blocklet/env": "1.16.15-beta-89b542d3",
47
+ "@blocklet/meta": "1.16.15-beta-89b542d3",
48
+ "@blocklet/resolver": "1.16.15-beta-89b542d3",
49
+ "@blocklet/sdk": "1.16.15-beta-89b542d3",
50
50
  "@did-space/client": "^0.2.165",
51
51
  "@fidm/x509": "^1.2.1",
52
52
  "@ocap/mcrypto": "1.18.89",
@@ -100,5 +100,5 @@
100
100
  "jest": "^27.5.1",
101
101
  "unzipper": "^0.10.11"
102
102
  },
103
- "gitHead": "a42c00d339896a089694a6275cee988422ecef69"
103
+ "gitHead": "a5302e43c87e7f33a35b1293d7b55579cc36fcc8"
104
104
  }