@blocklet/did-space-js 0.5.58
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/README.md +77 -0
- package/dist/client/index.d.ts +40 -0
- package/dist/client/index.js +110 -0
- package/dist/commands/backup/backup-blocklet.d.ts +14 -0
- package/dist/commands/backup/backup-blocklet.js +83 -0
- package/dist/commands/backup/index.d.ts +3 -0
- package/dist/commands/backup/index.js +19 -0
- package/dist/commands/backup/post-app-backup.d.ts +9 -0
- package/dist/commands/backup/post-app-backup.js +49 -0
- package/dist/commands/backup/put-app-backup.d.ts +9 -0
- package/dist/commands/backup/put-app-backup.js +49 -0
- package/dist/commands/base.d.ts +21 -0
- package/dist/commands/base.js +47 -0
- package/dist/commands/incremental-backup/backup-blocklet.d.ts +14 -0
- package/dist/commands/incremental-backup/backup-blocklet.js +90 -0
- package/dist/commands/incremental-backup/index.d.ts +1 -0
- package/dist/commands/incremental-backup/index.js +17 -0
- package/dist/commands/incremental-sync/index.d.ts +2 -0
- package/dist/commands/incremental-sync/index.js +18 -0
- package/dist/commands/incremental-sync/sync-base.d.ts +76 -0
- package/dist/commands/incremental-sync/sync-base.js +236 -0
- package/dist/commands/incremental-sync/sync-push.d.ts +30 -0
- package/dist/commands/incremental-sync/sync-push.js +202 -0
- package/dist/commands/index.d.ts +9 -0
- package/dist/commands/index.js +25 -0
- package/dist/commands/nft/index.d.ts +1 -0
- package/dist/commands/nft/index.js +17 -0
- package/dist/commands/nft/put-nft-object.d.ts +20 -0
- package/dist/commands/nft/put-nft-object.js +143 -0
- package/dist/commands/object/delete-object.d.ts +7 -0
- package/dist/commands/object/delete-object.js +38 -0
- package/dist/commands/object/get-object.d.ts +7 -0
- package/dist/commands/object/get-object.js +43 -0
- package/dist/commands/object/index.d.ts +5 -0
- package/dist/commands/object/index.js +21 -0
- package/dist/commands/object/list-object.d.ts +7 -0
- package/dist/commands/object/list-object.js +31 -0
- package/dist/commands/object/list-objects.d.ts +7 -0
- package/dist/commands/object/list-objects.js +44 -0
- package/dist/commands/object/put-object.d.ts +7 -0
- package/dist/commands/object/put-object.js +61 -0
- package/dist/commands/restore/index.d.ts +3 -0
- package/dist/commands/restore/index.js +19 -0
- package/dist/commands/restore/post-app-restore.d.ts +7 -0
- package/dist/commands/restore/post-app-restore.js +45 -0
- package/dist/commands/restore/put-app-restore.d.ts +9 -0
- package/dist/commands/restore/put-app-restore.js +49 -0
- package/dist/commands/restore/restore-blocklet.d.ts +14 -0
- package/dist/commands/restore/restore-blocklet.js +80 -0
- package/dist/commands/space/head.d.ts +8 -0
- package/dist/commands/space/head.js +52 -0
- package/dist/commands/space/index.d.ts +1 -0
- package/dist/commands/space/index.js +17 -0
- package/dist/commands/sync/index.d.ts +3 -0
- package/dist/commands/sync/index.js +19 -0
- package/dist/commands/sync/sync-folder-base.d.ts +105 -0
- package/dist/commands/sync/sync-folder-base.js +319 -0
- package/dist/commands/sync/sync-folder-pull.d.ts +13 -0
- package/dist/commands/sync/sync-folder-pull.js +151 -0
- package/dist/commands/sync/sync-folder-push.d.ts +20 -0
- package/dist/commands/sync/sync-folder-push.js +166 -0
- package/dist/did-document/did-document.d.ts +29 -0
- package/dist/did-document/did-document.js +2 -0
- package/dist/did-document/index.d.ts +3 -0
- package/dist/did-document/index.js +19 -0
- package/dist/did-document/sign-document.d.ts +3 -0
- package/dist/did-document/sign-document.js +13 -0
- package/dist/did-document/verify-document.d.ts +10 -0
- package/dist/did-document/verify-document.js +35 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/libs/api.d.ts +3 -0
- package/dist/libs/api.js +65 -0
- package/dist/libs/did.d.ts +9 -0
- package/dist/libs/did.js +34 -0
- package/dist/libs/encoding.d.ts +7 -0
- package/dist/libs/encoding.js +17 -0
- package/dist/libs/error.d.ts +4 -0
- package/dist/libs/error.js +27 -0
- package/dist/libs/hash.d.ts +1 -0
- package/dist/libs/hash.js +5 -0
- package/dist/libs/index.d.ts +11 -0
- package/dist/libs/index.js +27 -0
- package/dist/libs/logger.d.ts +2 -0
- package/dist/libs/logger.js +12 -0
- package/dist/libs/object-integrality.d.ts +1 -0
- package/dist/libs/object-integrality.js +13 -0
- package/dist/libs/performance.d.ts +7 -0
- package/dist/libs/performance.js +13 -0
- package/dist/libs/sleep.d.ts +1 -0
- package/dist/libs/sleep.js +9 -0
- package/dist/libs/space.d.ts +16 -0
- package/dist/libs/space.js +56 -0
- package/dist/libs/stream.d.ts +3 -0
- package/dist/libs/stream.js +10 -0
- package/dist/meta/backup/backup-blocklet-command.d.ts +50 -0
- package/dist/meta/backup/backup-blocklet-command.js +2 -0
- package/dist/meta/backup/index.d.ts +3 -0
- package/dist/meta/backup/index.js +19 -0
- package/dist/meta/backup/post-app-backup-command.d.ts +8 -0
- package/dist/meta/backup/post-app-backup-command.js +16 -0
- package/dist/meta/backup/put-app-backup-command.d.ts +7 -0
- package/dist/meta/backup/put-app-backup-command.js +18 -0
- package/dist/meta/incremental-backup/backup-blocklet-command.d.ts +50 -0
- package/dist/meta/incremental-backup/backup-blocklet-command.js +2 -0
- package/dist/meta/incremental-backup/index.d.ts +1 -0
- package/dist/meta/incremental-backup/index.js +17 -0
- package/dist/meta/index.d.ts +7 -0
- package/dist/meta/index.js +23 -0
- package/dist/meta/nft/index.d.ts +1 -0
- package/dist/meta/nft/index.js +17 -0
- package/dist/meta/nft/put-nft-object-command.d.ts +51 -0
- package/dist/meta/nft/put-nft-object-command.js +2 -0
- package/dist/meta/object/delete-object-command.d.ts +6 -0
- package/dist/meta/object/delete-object-command.js +2 -0
- package/dist/meta/object/get-object-command.d.ts +10 -0
- package/dist/meta/object/get-object-command.js +2 -0
- package/dist/meta/object/head-object-command.d.ts +13 -0
- package/dist/meta/object/head-object-command.js +2 -0
- package/dist/meta/object/index.d.ts +5 -0
- package/dist/meta/object/index.js +21 -0
- package/dist/meta/object/list-object-command.d.ts +6 -0
- package/dist/meta/object/list-object-command.js +2 -0
- package/dist/meta/object/list-objects-command.d.ts +8 -0
- package/dist/meta/object/list-objects-command.js +2 -0
- package/dist/meta/object/put-object-command.d.ts +29 -0
- package/dist/meta/object/put-object-command.js +2 -0
- package/dist/meta/restore/index.d.ts +3 -0
- package/dist/meta/restore/index.js +19 -0
- package/dist/meta/restore/post-app-restore-command.d.ts +8 -0
- package/dist/meta/restore/post-app-restore-command.js +13 -0
- package/dist/meta/restore/put-app-restore-command.d.ts +7 -0
- package/dist/meta/restore/put-app-restore-command.js +18 -0
- package/dist/meta/restore/restore-blocklet-command.d.ts +28 -0
- package/dist/meta/restore/restore-blocklet-command.js +2 -0
- package/dist/meta/spaces-client-options.d.ts +5 -0
- package/dist/meta/spaces-client-options.js +2 -0
- package/dist/meta/sync/incremental-sync-base-command.d.ts +7 -0
- package/dist/meta/sync/incremental-sync-base-command.js +2 -0
- package/dist/meta/sync/incremental-sync-push-command.d.ts +8 -0
- package/dist/meta/sync/incremental-sync-push-command.js +2 -0
- package/dist/meta/sync/index.d.ts +6 -0
- package/dist/meta/sync/index.js +22 -0
- package/dist/meta/sync/sync-base-command.d.ts +121 -0
- package/dist/meta/sync/sync-base-command.js +2 -0
- package/dist/meta/sync/sync-folder-base-command.d.ts +12 -0
- package/dist/meta/sync/sync-folder-base-command.js +2 -0
- package/dist/meta/sync/sync-folder-pull-command.d.ts +5 -0
- package/dist/meta/sync/sync-folder-pull-command.js +2 -0
- package/dist/meta/sync/sync-folder-push-command.d.ts +7 -0
- package/dist/meta/sync/sync-folder-push-command.js +2 -0
- package/dist/protocol/command.protocol.d.ts +68 -0
- package/dist/protocol/command.protocol.js +2 -0
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +17 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.js +17 -0
- package/dist/security/request-signature.d.ts +32 -0
- package/dist/security/request-signature.js +140 -0
- package/package.json +78 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SyncFolderPullCommand = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const fs_extra_1 = require("fs-extra");
|
|
10
|
+
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
11
|
+
const keyBy_1 = __importDefault(require("lodash/keyBy"));
|
|
12
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
13
|
+
const filehound_1 = __importDefault(require("filehound"));
|
|
14
|
+
const debug_1 = __importDefault(require("debug"));
|
|
15
|
+
const xbytes_1 = __importDefault(require("xbytes"));
|
|
16
|
+
const get_object_1 = require("../object/get-object");
|
|
17
|
+
const object_1 = require("../object");
|
|
18
|
+
const libs_1 = require("../../libs");
|
|
19
|
+
const sync_folder_base_1 = require("./sync-folder-base");
|
|
20
|
+
const logger_1 = require("../../libs/logger");
|
|
21
|
+
const { name, version } = require('../../../package.json');
|
|
22
|
+
const debug = (0, debug_1.default)(`${name}@${version}:sync-folder-pull`);
|
|
23
|
+
class SyncFolderPullCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
24
|
+
startTime = Date.now();
|
|
25
|
+
constructor(input, context) {
|
|
26
|
+
super(input, context);
|
|
27
|
+
// 确保文件夹存在
|
|
28
|
+
(0, fs_extra_1.ensureDirSync)(this.input.target);
|
|
29
|
+
}
|
|
30
|
+
getAxiosRequestConfig() {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
async request() {
|
|
34
|
+
try {
|
|
35
|
+
const remoteObjectsMap = await this.getRemoteObjectsMap();
|
|
36
|
+
const localObjectsMap = await this.getLocalObjectsMap();
|
|
37
|
+
const waitSyncObjects = await this.getWaitSyncObjects(remoteObjectsMap, localObjectsMap);
|
|
38
|
+
debug(`[${(0, logger_1.now)()}] [waitDownload]`, `waitDownloadCount=${waitSyncObjects.length}`);
|
|
39
|
+
debug(`[${(0, logger_1.now)()}] [context]`, { input: this.input, context: (0, pick_1.default)(this.context, ['endpoint']) });
|
|
40
|
+
return await this.sync(waitSyncObjects);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(error);
|
|
44
|
+
return this.retryRequest(error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async getRemoteObjectsMap() {
|
|
48
|
+
let { data: objects } = await new object_1.ListObjectsCommand({ key: (0, path_1.join)(this.input.source) }, this.context).request();
|
|
49
|
+
if ((0, isFunction_1.default)(this.input.filter)) {
|
|
50
|
+
objects = objects.filter(this.input.filter);
|
|
51
|
+
}
|
|
52
|
+
const map = (0, keyBy_1.default)(objects, (object) => object.key);
|
|
53
|
+
return map;
|
|
54
|
+
}
|
|
55
|
+
getLocalObjectsMap() {
|
|
56
|
+
const files = filehound_1.default.create()
|
|
57
|
+
.path(this.input.target)
|
|
58
|
+
.includeFileStats()
|
|
59
|
+
.findSync();
|
|
60
|
+
const objects = files.map((file) => {
|
|
61
|
+
const key = file.path.replace(this.input.target, '');
|
|
62
|
+
return {
|
|
63
|
+
key,
|
|
64
|
+
name: (0, path_1.basename)(key),
|
|
65
|
+
isDir: key.endsWith('/'),
|
|
66
|
+
size: file.stats.size,
|
|
67
|
+
lastModified: new Date(file.stats.mtime).getTime(),
|
|
68
|
+
editable: true,
|
|
69
|
+
mimeType: 'unknown',
|
|
70
|
+
absolutePath: file.path,
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
const map = (0, keyBy_1.default)(objects, (object) => object.key);
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
return map;
|
|
76
|
+
}
|
|
77
|
+
async sync(syncObjects) {
|
|
78
|
+
this.queue.removeAllListeners();
|
|
79
|
+
let errorCount = 0;
|
|
80
|
+
let completedCount = 0;
|
|
81
|
+
const totalCount = syncObjects.length;
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
this.queue.on('error', async () => {
|
|
84
|
+
errorCount += 1;
|
|
85
|
+
await this.printDebugInfo({
|
|
86
|
+
direction: 'pull',
|
|
87
|
+
completedCount,
|
|
88
|
+
errorCount,
|
|
89
|
+
totalCount,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
const actions = syncObjects.map((x) => {
|
|
93
|
+
return async () => {
|
|
94
|
+
// FIXME: 目前还是不要支持删除比较好,之后做到双向同步可以再改进即可
|
|
95
|
+
if (x.action === 'DELETE') {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const sourceKey = (0, path_1.join)(this.input.source, x.key);
|
|
99
|
+
const targetKey = (0, path_1.join)(this.input.target, x.key);
|
|
100
|
+
await this.triggerOnProgressHook({
|
|
101
|
+
completed: completedCount,
|
|
102
|
+
total: totalCount,
|
|
103
|
+
key: sourceKey,
|
|
104
|
+
});
|
|
105
|
+
// 开始下载
|
|
106
|
+
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.before] ${sourceKey} => ${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
107
|
+
iec: true,
|
|
108
|
+
})} completed=${completedCount} total=${totalCount}`);
|
|
109
|
+
const { data: stream, headers } = await new get_object_1.GetObjectCommand({
|
|
110
|
+
key: sourceKey,
|
|
111
|
+
}, this.context).request();
|
|
112
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(targetKey));
|
|
113
|
+
const writeStream = (0, fs_1.createWriteStream)(targetKey);
|
|
114
|
+
stream.pipe(writeStream);
|
|
115
|
+
await (0, libs_1.streamToFile)(writeStream);
|
|
116
|
+
// 验证文件的完整性
|
|
117
|
+
if (headers['x-hash']) {
|
|
118
|
+
await (0, libs_1.verifyObjectHash)(targetKey, headers['x-hash']);
|
|
119
|
+
}
|
|
120
|
+
// progress
|
|
121
|
+
++completedCount;
|
|
122
|
+
await this.printDebugInfo({
|
|
123
|
+
direction: 'pull',
|
|
124
|
+
completedCount,
|
|
125
|
+
errorCount,
|
|
126
|
+
totalCount,
|
|
127
|
+
});
|
|
128
|
+
await this.triggerOnAfterUploadHook({
|
|
129
|
+
completed: completedCount,
|
|
130
|
+
total: totalCount,
|
|
131
|
+
key: sourceKey,
|
|
132
|
+
});
|
|
133
|
+
// 下载完成
|
|
134
|
+
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.after] ${sourceKey} => ${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
135
|
+
iec: true,
|
|
136
|
+
})} completed=${completedCount} total=${totalCount}`);
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
await this.queue.addAll(actions);
|
|
140
|
+
await this.queue.onIdle();
|
|
141
|
+
return {
|
|
142
|
+
statusCode: 200,
|
|
143
|
+
data: {
|
|
144
|
+
errorCount,
|
|
145
|
+
count: actions.length,
|
|
146
|
+
duration: (Date.now() - this.startTime) / 1000,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.SyncFolderPullCommand = SyncFolderPullCommand;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { SyncFolderPushCommandInput, SyncFolderPushCommandOutput } from '../../meta';
|
|
3
|
+
import { ObjectsMap, SyncFolderBaseCommand } from './sync-folder-base';
|
|
4
|
+
import type { SpaceClientOptions } from '../../protocol';
|
|
5
|
+
/**
|
|
6
|
+
* @see s3 sync https://stackoverflow.com/questions/27932345/downloading-folders-from-aws-s3-cp-or-sync
|
|
7
|
+
* @see 具有 Keep-alive 和连接重用的 NodeJS https://azureossd.github.io/2022/03/10/NodeJS-with-Keep-Alives-and-Connection-Reuse/index.html
|
|
8
|
+
* @export
|
|
9
|
+
* @class SyncFolderPushCommand
|
|
10
|
+
* @extends {BaseCommand<SyncFolderCommandInput, SyncFolderPushCommandOutput>}
|
|
11
|
+
*/
|
|
12
|
+
export declare class SyncFolderPushCommand extends SyncFolderBaseCommand<SyncFolderPushCommandInput, SyncFolderPushCommandOutput> {
|
|
13
|
+
protected readonly startTime: number;
|
|
14
|
+
constructor(input: SyncFolderPushCommandInput, context?: SpaceClientOptions);
|
|
15
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any>>;
|
|
16
|
+
request(): Promise<SyncFolderPushCommandOutput>;
|
|
17
|
+
getLocalObjectsMap(): Promise<ObjectsMap>;
|
|
18
|
+
getRemoteObjectsMap(): Promise<ObjectsMap>;
|
|
19
|
+
private sync;
|
|
20
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SyncFolderPushCommand = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const filehound_1 = __importDefault(require("filehound"));
|
|
10
|
+
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
11
|
+
const keyBy_1 = __importDefault(require("lodash/keyBy"));
|
|
12
|
+
const fs_extra_1 = require("fs-extra");
|
|
13
|
+
const debug_1 = __importDefault(require("debug"));
|
|
14
|
+
const xbytes_1 = __importDefault(require("xbytes"));
|
|
15
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
16
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
17
|
+
const object_1 = require("../object");
|
|
18
|
+
const sync_folder_base_1 = require("./sync-folder-base");
|
|
19
|
+
const logger_1 = require("../../libs/logger");
|
|
20
|
+
const delete_object_1 = require("../object/delete-object");
|
|
21
|
+
const { name, version } = require('../../../package.json');
|
|
22
|
+
const debug = (0, debug_1.default)(`${name}@${version}:sync-folder-push`);
|
|
23
|
+
/**
|
|
24
|
+
* @see s3 sync https://stackoverflow.com/questions/27932345/downloading-folders-from-aws-s3-cp-or-sync
|
|
25
|
+
* @see 具有 Keep-alive 和连接重用的 NodeJS https://azureossd.github.io/2022/03/10/NodeJS-with-Keep-Alives-and-Connection-Reuse/index.html
|
|
26
|
+
* @export
|
|
27
|
+
* @class SyncFolderPushCommand
|
|
28
|
+
* @extends {BaseCommand<SyncFolderCommandInput, SyncFolderPushCommandOutput>}
|
|
29
|
+
*/
|
|
30
|
+
class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
31
|
+
startTime = Date.now();
|
|
32
|
+
constructor(input, context) {
|
|
33
|
+
super(input, context);
|
|
34
|
+
// 确保文件夹存在
|
|
35
|
+
(0, fs_extra_1.ensureDirSync)(this.input.source);
|
|
36
|
+
}
|
|
37
|
+
getAxiosRequestConfig() {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
async request() {
|
|
41
|
+
try {
|
|
42
|
+
const localObjectsMap = await this.getLocalObjectsMap();
|
|
43
|
+
const remoteObjectsMap = await this.getRemoteObjectsMap();
|
|
44
|
+
const waitSyncObjects = await this.getWaitSyncObjects(localObjectsMap, remoteObjectsMap);
|
|
45
|
+
const syncObjects = await this.copyObjects(waitSyncObjects);
|
|
46
|
+
debug(`[${(0, logger_1.now)()}] [waitUpload] waitUploadCount=${syncObjects.length}`);
|
|
47
|
+
debug(`[${(0, logger_1.now)()}] [context]`, { input: this.input, context: (0, pick_1.default)(this.context, ['endpoint']) });
|
|
48
|
+
return await this.sync(syncObjects);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(error);
|
|
52
|
+
return this.retryRequest(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async getLocalObjectsMap() {
|
|
56
|
+
const files = filehound_1.default.create()
|
|
57
|
+
.path(this.input.source)
|
|
58
|
+
.includeFileStats()
|
|
59
|
+
.findSync();
|
|
60
|
+
let objects = await Promise.all(files.map((file) => {
|
|
61
|
+
const key = file.path.replace(this.input.source, '/');
|
|
62
|
+
return {
|
|
63
|
+
key,
|
|
64
|
+
name: (0, path_1.basename)(key),
|
|
65
|
+
isDir: key.endsWith('/'),
|
|
66
|
+
size: file.stats.size,
|
|
67
|
+
lastModified: new Date(file.stats.mtime).getTime(),
|
|
68
|
+
editable: true,
|
|
69
|
+
mimeType: null,
|
|
70
|
+
absolutePath: file.path,
|
|
71
|
+
};
|
|
72
|
+
}));
|
|
73
|
+
if ((0, isFunction_1.default)(this.input.filter)) {
|
|
74
|
+
objects = objects.filter(this.input.filter);
|
|
75
|
+
}
|
|
76
|
+
const map = (0, keyBy_1.default)(objects, (object) => object.key);
|
|
77
|
+
return map;
|
|
78
|
+
}
|
|
79
|
+
async getRemoteObjectsMap() {
|
|
80
|
+
const { data: objects } = await new object_1.ListObjectsCommand({
|
|
81
|
+
key: this.input.target,
|
|
82
|
+
}, this.context).request();
|
|
83
|
+
const map = (0, keyBy_1.default)(objects, (object) => object.key);
|
|
84
|
+
return map;
|
|
85
|
+
}
|
|
86
|
+
async sync(syncObjects) {
|
|
87
|
+
this.queue.removeAllListeners();
|
|
88
|
+
let errorCount = 0;
|
|
89
|
+
let completedCount = 0;
|
|
90
|
+
const totalCount = syncObjects.length;
|
|
91
|
+
// @ts-expect-error
|
|
92
|
+
this.queue.on('error', async () => {
|
|
93
|
+
errorCount += 1;
|
|
94
|
+
await this.printDebugInfo({
|
|
95
|
+
direction: 'push',
|
|
96
|
+
completedCount,
|
|
97
|
+
errorCount,
|
|
98
|
+
totalCount,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
const actions = syncObjects.map((x) => {
|
|
102
|
+
return async () => {
|
|
103
|
+
const sourceKey = (0, path_1.join)(this.input.source, x.key);
|
|
104
|
+
const targetKey = (0, path_1.join)(this.input.target, x.key);
|
|
105
|
+
await this.triggerOnProgressHook({
|
|
106
|
+
completed: completedCount,
|
|
107
|
+
total: totalCount,
|
|
108
|
+
key: sourceKey,
|
|
109
|
+
});
|
|
110
|
+
// 开始上传
|
|
111
|
+
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.before] ${sourceKey} => ${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
112
|
+
iec: true,
|
|
113
|
+
})} completed=${completedCount} total=${totalCount}`);
|
|
114
|
+
if (x.action === 'PUT') {
|
|
115
|
+
await new object_1.PutObjectCommand({
|
|
116
|
+
key: targetKey,
|
|
117
|
+
data: (0, fs_1.createReadStream)(sourceKey),
|
|
118
|
+
hash: x.hash,
|
|
119
|
+
}, this.context).request();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
await new delete_object_1.DeleteObjectCommand({
|
|
123
|
+
key: targetKey,
|
|
124
|
+
}, this.context).request();
|
|
125
|
+
}
|
|
126
|
+
// progress
|
|
127
|
+
++completedCount;
|
|
128
|
+
await this.printDebugInfo({
|
|
129
|
+
direction: 'push',
|
|
130
|
+
completedCount,
|
|
131
|
+
errorCount,
|
|
132
|
+
totalCount,
|
|
133
|
+
});
|
|
134
|
+
await this.triggerOnAfterUploadHook({
|
|
135
|
+
completed: completedCount,
|
|
136
|
+
total: totalCount,
|
|
137
|
+
key: sourceKey,
|
|
138
|
+
});
|
|
139
|
+
// 结束上传
|
|
140
|
+
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.after] ${sourceKey}=>${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
141
|
+
iec: true,
|
|
142
|
+
})} completed=${completedCount} total=${totalCount}`);
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
if (!(0, isEmpty_1.default)(this.input.metadata)) {
|
|
146
|
+
actions.unshift(async () => {
|
|
147
|
+
await new object_1.PutObjectCommand({
|
|
148
|
+
key: this.input.target,
|
|
149
|
+
metadata: this.input.metadata,
|
|
150
|
+
}, this.context).request();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
await this.queue.addAll(actions);
|
|
154
|
+
await this.queue.onIdle();
|
|
155
|
+
await this.destroy();
|
|
156
|
+
return {
|
|
157
|
+
statusCode: 200,
|
|
158
|
+
data: {
|
|
159
|
+
errorCount,
|
|
160
|
+
count: actions.length,
|
|
161
|
+
duration: (Date.now() - this.startTime) / 1000,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.SyncFolderPushCommand = SyncFolderPushCommand;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type ContextV0Dot1 = 'https://www.w3.org/ns/did/v1';
|
|
2
|
+
export interface DidDocument {
|
|
3
|
+
'@context': ContextV0Dot1;
|
|
4
|
+
id: string;
|
|
5
|
+
controller: string;
|
|
6
|
+
service: Array<{
|
|
7
|
+
id: string;
|
|
8
|
+
type: string;
|
|
9
|
+
key?: string;
|
|
10
|
+
serviceEndpoint: string;
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}>;
|
|
13
|
+
verificationMethod: Array<{
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
controller: string;
|
|
17
|
+
publicKeyMultibase: string;
|
|
18
|
+
}>;
|
|
19
|
+
proof: {
|
|
20
|
+
type: string;
|
|
21
|
+
created: string;
|
|
22
|
+
verificationMethod: string;
|
|
23
|
+
jws?: string;
|
|
24
|
+
};
|
|
25
|
+
authentication: string[];
|
|
26
|
+
created: string;
|
|
27
|
+
updated: string;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./did-document"), exports);
|
|
18
|
+
__exportStar(require("./sign-document"), exports);
|
|
19
|
+
__exportStar(require("./verify-document"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.signDidDocument = void 0;
|
|
7
|
+
const util_1 = require("@ocap/util");
|
|
8
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
9
|
+
function signDidDocument(didDocument, wallet) {
|
|
10
|
+
didDocument.proof.jws = (0, util_1.toBase64)(wallet.sign((0, json_stable_stringify_1.default)(didDocument)));
|
|
11
|
+
return didDocument;
|
|
12
|
+
}
|
|
13
|
+
exports.signDidDocument = signDidDocument;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DidDocument } from './did-document';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* @see https://github.com/blocklet/did-services/blob/6a3546f16f0458115e0e81f9a66a70fbe24649c3/packages/did-document/lib/index.js#L8-L27
|
|
6
|
+
* @export
|
|
7
|
+
* @param {DidDocument} didDocument
|
|
8
|
+
* @return {*} {Promise<boolean>}
|
|
9
|
+
*/
|
|
10
|
+
export declare function verifyDidDocument(didDocument: DidDocument): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.verifyDidDocument = void 0;
|
|
7
|
+
const did_1 = require("@arcblock/did");
|
|
8
|
+
const wallet_1 = require("@ocap/wallet");
|
|
9
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
10
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
11
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
12
|
+
const util_1 = require("@ocap/util");
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @see https://github.com/blocklet/did-services/blob/6a3546f16f0458115e0e81f9a66a70fbe24649c3/packages/did-document/lib/index.js#L8-L27
|
|
17
|
+
* @export
|
|
18
|
+
* @param {DidDocument} didDocument
|
|
19
|
+
* @return {*} {Promise<boolean>}
|
|
20
|
+
*/
|
|
21
|
+
function verifyDidDocument(didDocument) {
|
|
22
|
+
const verificationMethod = (0, get_1.default)(didDocument, 'proof.verificationMethod');
|
|
23
|
+
const verifyInfo = didDocument.verificationMethod.find((item) => item.id === verificationMethod);
|
|
24
|
+
const owner = (0, wallet_1.fromPublicKey)(verifyInfo.publicKeyMultibase, (0, did_1.toTypeInfo)(didDocument.controller));
|
|
25
|
+
const cloned = (0, cloneDeep_1.default)(didDocument);
|
|
26
|
+
const signature = cloned.proof.jws;
|
|
27
|
+
delete cloned.proof.jws;
|
|
28
|
+
if (owner.verify((0, json_stable_stringify_1.default)(cloned), (0, util_1.fromBase64)(signature)) !== true) {
|
|
29
|
+
throw new Error('DID Document signature not valid');
|
|
30
|
+
}
|
|
31
|
+
if (!(0, did_1.isFromPublicKey)(didDocument.controller, verifyInfo.publicKeyMultibase)) {
|
|
32
|
+
throw new Error('document controller and public key are not match');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.verifyDidDocument = verifyDidDocument;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("./commands"), exports);
|
|
19
|
+
__exportStar(require("./did-document"), exports);
|
|
20
|
+
__exportStar(require("./libs"), exports);
|
|
21
|
+
__exportStar(require("./meta"), exports);
|
|
22
|
+
__exportStar(require("./protocol"), exports);
|
|
23
|
+
__exportStar(require("./security"), exports);
|
package/dist/libs/api.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.gotApi = exports.api = exports.MIN = void 0;
|
|
30
|
+
const axios_1 = __importDefault(require("axios"));
|
|
31
|
+
const agentkeepalive_1 = __importStar(require("agentkeepalive"));
|
|
32
|
+
const got_1 = __importDefault(require("got"));
|
|
33
|
+
exports.MIN = 60 * 1000;
|
|
34
|
+
const httpAgent = new agentkeepalive_1.default({
|
|
35
|
+
maxSockets: 64,
|
|
36
|
+
maxFreeSockets: 16,
|
|
37
|
+
timeout: exports.MIN,
|
|
38
|
+
freeSocketTimeout: exports.MIN,
|
|
39
|
+
keepAliveMsecs: exports.MIN,
|
|
40
|
+
keepAlive: true,
|
|
41
|
+
});
|
|
42
|
+
const httpsAgent = new agentkeepalive_1.HttpsAgent({
|
|
43
|
+
maxSockets: 64,
|
|
44
|
+
maxFreeSockets: 16,
|
|
45
|
+
timeout: exports.MIN,
|
|
46
|
+
freeSocketTimeout: exports.MIN,
|
|
47
|
+
keepAliveMsecs: exports.MIN,
|
|
48
|
+
keepAlive: true,
|
|
49
|
+
});
|
|
50
|
+
exports.api = axios_1.default.create({
|
|
51
|
+
// @see Getting Axios Error: connect ETIMEDOUT when making high volume of calls https://stackoverflow.com/a/63585550
|
|
52
|
+
httpAgent,
|
|
53
|
+
httpsAgent,
|
|
54
|
+
});
|
|
55
|
+
// @see https://github.com/sindresorhus/got/blob/main/documentation/tips.md#retries
|
|
56
|
+
exports.gotApi = got_1.default.extend({
|
|
57
|
+
agent: {
|
|
58
|
+
http: httpAgent,
|
|
59
|
+
https: httpsAgent,
|
|
60
|
+
},
|
|
61
|
+
timeout: 1000 * 60 * 60,
|
|
62
|
+
retry: {
|
|
63
|
+
limit: 3,
|
|
64
|
+
},
|
|
65
|
+
});
|
package/dist/libs/did.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toDid = exports.toABTDid = void 0;
|
|
4
|
+
const did_1 = require("@arcblock/did");
|
|
5
|
+
const ABT_PREFIX = 'did:abt:';
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @description 将 did 转化为 abt did
|
|
9
|
+
* @export
|
|
10
|
+
* @param {string} did
|
|
11
|
+
* @return {*} {string}
|
|
12
|
+
*/
|
|
13
|
+
function toABTDid(did) {
|
|
14
|
+
if (!(0, did_1.isValid)(did)) {
|
|
15
|
+
throw new Error(`did(${did}) is not a valid did`);
|
|
16
|
+
}
|
|
17
|
+
return `did:abt:${did}`;
|
|
18
|
+
}
|
|
19
|
+
exports.toABTDid = toABTDid;
|
|
20
|
+
function toDid(did) {
|
|
21
|
+
const $did = did.trim();
|
|
22
|
+
if (!$did.startsWith(ABT_PREFIX) && (0, did_1.isValid)($did)) {
|
|
23
|
+
return $did;
|
|
24
|
+
}
|
|
25
|
+
if (!$did.startsWith(ABT_PREFIX)) {
|
|
26
|
+
throw new Error(`The format of did(${$did}) should be: ${ABT_PREFIX}{did}`);
|
|
27
|
+
}
|
|
28
|
+
const didNotPrefix = $did.replace(ABT_PREFIX, '');
|
|
29
|
+
if (!(0, did_1.isValid)(didNotPrefix)) {
|
|
30
|
+
throw new Error(`did(${didNotPrefix}) is not a valid did`);
|
|
31
|
+
}
|
|
32
|
+
return didNotPrefix;
|
|
33
|
+
}
|
|
34
|
+
exports.toDid = toDid;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.encode = void 0;
|
|
7
|
+
const base64_url_1 = __importDefault(require("base64-url"));
|
|
8
|
+
/**
|
|
9
|
+
* @description 将存储文件的路径编码成 base64 url
|
|
10
|
+
* @export
|
|
11
|
+
* @param {string} key
|
|
12
|
+
* @return {*} {string}
|
|
13
|
+
*/
|
|
14
|
+
function encode(key) {
|
|
15
|
+
return base64_url_1.default.encode(key);
|
|
16
|
+
}
|
|
17
|
+
exports.encode = encode;
|