@abtnode/core 1.16.15-beta-58d50c9a → 1.16.15-beta-e143b1cf
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/index.js +3 -1
- package/lib/router/index.js +8 -0
- package/lib/states/audit-log.js +3 -0
- package/lib/util/cache.js +71 -0
- package/package.json +20 -20
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/router/index.js
CHANGED
|
@@ -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 = []) => {
|
package/lib/states/audit-log.js
CHANGED
|
@@ -287,6 +287,8 @@ const getLogContent = async (action, args, context, result, info, node) => {
|
|
|
287
287
|
return `updated routing rule **${args.rule?.from?.pathPrefix}** from ${site}`; // prettier-ignore
|
|
288
288
|
case 'deleteRoutingRule':
|
|
289
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';
|
|
290
292
|
case 'updateGateway': {
|
|
291
293
|
const changes = [
|
|
292
294
|
args.requestLimit.enabled ? `rate limit: enabled, rate: ${args.requestLimit.rate}` : 'rate limit: disabled',
|
|
@@ -393,6 +395,7 @@ const getLogCategory = (action) => {
|
|
|
393
395
|
case 'issueLetsEncryptCert':
|
|
394
396
|
return 'certificates';
|
|
395
397
|
|
|
398
|
+
case 'clearCache':
|
|
396
399
|
case 'updateGateway':
|
|
397
400
|
return 'gateway';
|
|
398
401
|
|
|
@@ -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-
|
|
6
|
+
"version": "1.16.15-beta-e143b1cf",
|
|
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-
|
|
23
|
-
"@abtnode/auth": "1.16.15-beta-
|
|
24
|
-
"@abtnode/certificate-manager": "1.16.15-beta-
|
|
25
|
-
"@abtnode/constant": "1.16.15-beta-
|
|
26
|
-
"@abtnode/cron": "1.16.15-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.15-beta-
|
|
28
|
-
"@abtnode/models": "1.16.15-beta-
|
|
29
|
-
"@abtnode/queue": "1.16.15-beta-
|
|
30
|
-
"@abtnode/rbac": "1.16.15-beta-
|
|
31
|
-
"@abtnode/router-provider": "1.16.15-beta-
|
|
32
|
-
"@abtnode/static-server": "1.16.15-beta-
|
|
33
|
-
"@abtnode/timemachine": "1.16.15-beta-
|
|
34
|
-
"@abtnode/util": "1.16.15-beta-
|
|
22
|
+
"@abtnode/analytics": "1.16.15-beta-e143b1cf",
|
|
23
|
+
"@abtnode/auth": "1.16.15-beta-e143b1cf",
|
|
24
|
+
"@abtnode/certificate-manager": "1.16.15-beta-e143b1cf",
|
|
25
|
+
"@abtnode/constant": "1.16.15-beta-e143b1cf",
|
|
26
|
+
"@abtnode/cron": "1.16.15-beta-e143b1cf",
|
|
27
|
+
"@abtnode/logger": "1.16.15-beta-e143b1cf",
|
|
28
|
+
"@abtnode/models": "1.16.15-beta-e143b1cf",
|
|
29
|
+
"@abtnode/queue": "1.16.15-beta-e143b1cf",
|
|
30
|
+
"@abtnode/rbac": "1.16.15-beta-e143b1cf",
|
|
31
|
+
"@abtnode/router-provider": "1.16.15-beta-e143b1cf",
|
|
32
|
+
"@abtnode/static-server": "1.16.15-beta-e143b1cf",
|
|
33
|
+
"@abtnode/timemachine": "1.16.15-beta-e143b1cf",
|
|
34
|
+
"@abtnode/util": "1.16.15-beta-e143b1cf",
|
|
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-
|
|
46
|
-
"@blocklet/env": "1.16.15-beta-
|
|
47
|
-
"@blocklet/meta": "1.16.15-beta-
|
|
48
|
-
"@blocklet/resolver": "1.16.15-beta-
|
|
49
|
-
"@blocklet/sdk": "1.16.15-beta-
|
|
45
|
+
"@blocklet/constant": "1.16.15-beta-e143b1cf",
|
|
46
|
+
"@blocklet/env": "1.16.15-beta-e143b1cf",
|
|
47
|
+
"@blocklet/meta": "1.16.15-beta-e143b1cf",
|
|
48
|
+
"@blocklet/resolver": "1.16.15-beta-e143b1cf",
|
|
49
|
+
"@blocklet/sdk": "1.16.15-beta-e143b1cf",
|
|
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": "
|
|
103
|
+
"gitHead": "86dcc908f3cb7259d1ca92b9ae75160a6e43509a"
|
|
104
104
|
}
|