@blocklet/did-space-js 1.0.39 → 1.0.41
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/dist/commands/incremental-sync/sync-base.d.ts +1 -1
- package/dist/commands/incremental-sync/sync-base.js +8 -6
- package/dist/commands/incremental-sync/sync-push.js +1 -1
- package/dist/commands/sync/sync-folder-base.d.ts +15 -2
- package/dist/commands/sync/sync-folder-base.js +29 -10
- package/dist/commands/sync/sync-folder-push.d.ts +12 -4
- package/dist/commands/sync/sync-folder-push.js +173 -73
- package/dist/libs/data.d.ts +2 -0
- package/dist/libs/data.js +14 -0
- package/dist/libs/index.d.ts +2 -0
- package/dist/libs/index.js +2 -0
- package/dist/libs/types.d.ts +2 -0
- package/dist/libs/types.js +7 -0
- package/dist/meta/index.d.ts +1 -1
- package/dist/meta/index.js +1 -1
- package/dist/meta/object/preview-object-command.d.ts +33 -31
- package/dist/meta/object/put-object-command.d.ts +2 -2
- package/dist/meta/sync/sync-base-command.d.ts +6 -0
- package/dist/meta/sync/sync-folder-base-command.d.ts +13 -1
- package/dist/meta/sync/sync-folder-base-command.js +9 -0
- package/dist/meta/sync/sync-folder-pull-command.d.ts +1 -0
- package/dist/meta/sync/sync-folder-push-command.d.ts +5 -1
- package/dist/security/request-signature.js +3 -3
- package/package.json +4 -3
- /package/dist/meta/{incremental-backup → incremental}/backup-blocklet-command.d.ts +0 -0
- /package/dist/meta/{incremental-backup → incremental}/backup-blocklet-command.js +0 -0
- /package/dist/meta/{incremental-backup → incremental}/index.d.ts +0 -0
- /package/dist/meta/{incremental-backup → incremental}/index.js +0 -0
|
@@ -23,7 +23,7 @@ export declare abstract class IncrementalSyncBaseCommand<CommandInput extends In
|
|
|
23
23
|
SYNC_AFTER: string;
|
|
24
24
|
};
|
|
25
25
|
private retryCount;
|
|
26
|
-
constructor(input:
|
|
26
|
+
constructor(input: CommandInput, context?: SpaceClientOptions);
|
|
27
27
|
private initialize;
|
|
28
28
|
abstract getLocalObjectsMap(): Promise<ObjectsMap>;
|
|
29
29
|
abstract getRemoteObjectsMap(): Promise<ObjectsMap>;
|
|
@@ -41,7 +41,6 @@ class IncrementalSyncBaseCommand extends base_1.BaseCommand {
|
|
|
41
41
|
};
|
|
42
42
|
retryCount = 0;
|
|
43
43
|
constructor(input, context) {
|
|
44
|
-
// @ts-expect-error
|
|
45
44
|
super(input, context);
|
|
46
45
|
this.initialize(input);
|
|
47
46
|
this.queue = new p_queue_1.default({ concurrency: this.input.concurrency });
|
|
@@ -171,11 +170,14 @@ class IncrementalSyncBaseCommand extends base_1.BaseCommand {
|
|
|
171
170
|
}
|
|
172
171
|
// 本地不存在 && 远程存在, 则删除远程的
|
|
173
172
|
if (!fromObject && toObject) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
if (this.input.strictSync) {
|
|
174
|
+
return {
|
|
175
|
+
...toObject,
|
|
176
|
+
action: 'DELETE',
|
|
177
|
+
key,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
179
181
|
}
|
|
180
182
|
// 本地存在的文件 && 在远程存在 && 两者文件大小不一致, 则修改远程的
|
|
181
183
|
if (fromObject.size !== toObject.size) {
|
|
@@ -12,10 +12,10 @@ const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
|
12
12
|
const keyBy_1 = __importDefault(require("lodash/keyBy"));
|
|
13
13
|
const debug_1 = __importDefault(require("debug"));
|
|
14
14
|
const xbytes_1 = __importDefault(require("xbytes"));
|
|
15
|
-
const pick_1 = __importDefault(require("lodash/pick"));
|
|
16
15
|
const fs_extra_1 = require("fs-extra");
|
|
17
16
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
18
17
|
const promises_1 = require("node:stream/promises");
|
|
18
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
19
19
|
const object_1 = require("../object");
|
|
20
20
|
const logger_1 = require("../../libs/logger");
|
|
21
21
|
const delete_object_1 = require("../object/delete-object");
|
|
@@ -10,6 +10,7 @@ export interface ObjectsMap {
|
|
|
10
10
|
export interface SyncObject extends Object {
|
|
11
11
|
action: 'PUT' | 'DELETE';
|
|
12
12
|
tempAbsolutePath?: string;
|
|
13
|
+
reason?: 'localNotExists' | 'remoteNotExists' | 'sizeMismatch' | 'lastModifiedMismatch' | 'hashMismatch';
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* @see s3 sync https://stackoverflow.com/questions/27932345/downloading-folders-from-aws-s3-cp-or-sync
|
|
@@ -26,7 +27,19 @@ export declare abstract class SyncFolderBaseCommand<CommandInput extends SyncFol
|
|
|
26
27
|
static readonly DEFAULT_CONCURRENCY: number;
|
|
27
28
|
static readonly MAX_CONCURRENCY: number;
|
|
28
29
|
private retryCount;
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @description 本地对象
|
|
32
|
+
*/
|
|
33
|
+
protected localObjectsMap: ObjectsMap;
|
|
34
|
+
/**
|
|
35
|
+
* @description 远程对象
|
|
36
|
+
*/
|
|
37
|
+
protected remoteObjectsMap: ObjectsMap;
|
|
38
|
+
/**
|
|
39
|
+
* @description 保存待同步的对象,避免重复计算,可优化性能
|
|
40
|
+
*/
|
|
41
|
+
protected waitSyncObjects: SyncObject[];
|
|
42
|
+
constructor(input: CommandInput, context?: SpaceClientOptions);
|
|
30
43
|
abstract getLocalObjectsMap(): Promise<ObjectsMap>;
|
|
31
44
|
abstract getRemoteObjectsMap(): Promise<ObjectsMap>;
|
|
32
45
|
/**
|
|
@@ -60,7 +73,7 @@ export declare abstract class SyncFolderBaseCommand<CommandInput extends SyncFol
|
|
|
60
73
|
* @memberof SyncFolderBaseCommand
|
|
61
74
|
*/
|
|
62
75
|
protected retryRequest(error: Error | AxiosError): Promise<SyncFolderPullCommandOutput>;
|
|
63
|
-
protected
|
|
76
|
+
protected onFailed?(error: Error): Promise<void>;
|
|
64
77
|
/**
|
|
65
78
|
*
|
|
66
79
|
* @description 比较双方的文件到底谁更新鲜,更新鲜的数据才需要被同步上去
|
|
@@ -38,8 +38,19 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
38
38
|
static DEFAULT_CONCURRENCY = 4;
|
|
39
39
|
static MAX_CONCURRENCY = (0, os_1.cpus)().length;
|
|
40
40
|
retryCount = 0;
|
|
41
|
+
/**
|
|
42
|
+
* @description 本地对象
|
|
43
|
+
*/
|
|
44
|
+
localObjectsMap = {};
|
|
45
|
+
/**
|
|
46
|
+
* @description 远程对象
|
|
47
|
+
*/
|
|
48
|
+
remoteObjectsMap = {};
|
|
49
|
+
/**
|
|
50
|
+
* @description 保存待同步的对象,避免重复计算,可优化性能
|
|
51
|
+
*/
|
|
52
|
+
waitSyncObjects = [];
|
|
41
53
|
constructor(input, context) {
|
|
42
|
-
// @ts-expect-error why?暂时没想通报错的原因
|
|
43
54
|
super(input, context);
|
|
44
55
|
if ((0, isUndefined_1.default)(input?.concurrency)) {
|
|
45
56
|
this.input.concurrency = SyncFolderBaseCommand.DEFAULT_CONCURRENCY;
|
|
@@ -59,7 +70,7 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
59
70
|
else {
|
|
60
71
|
this.input.retryCount = input.retryCount;
|
|
61
72
|
}
|
|
62
|
-
if (!this.input.source.endsWith('/')) {
|
|
73
|
+
if (typeof this.input.source === 'string' && !this.input.source.endsWith('/')) {
|
|
63
74
|
this.input.source = (0, path_1.join)(this.input.source, '/');
|
|
64
75
|
}
|
|
65
76
|
if (!this.input.target.endsWith('/')) {
|
|
@@ -122,7 +133,7 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
122
133
|
// FIXME: retryCount === 0 表示,重试次数刚好用完了,后续优化 server 显示错误的进度 @yejianchao
|
|
123
134
|
// 防呆控制,retryCount < 0 说明调用基础接口始终是失败的,遇到了预料之外的事情,因此需要停止运行
|
|
124
135
|
if (this.input.retryCount <= 0 || [400, 401, 403, 404, 413].includes(statusCode)) {
|
|
125
|
-
await this.
|
|
136
|
+
await this.onFailed?.(error);
|
|
126
137
|
await this.destroy();
|
|
127
138
|
return {
|
|
128
139
|
statusCode,
|
|
@@ -142,8 +153,6 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
142
153
|
await (0, libs_1.sleep)(retryDelayMs);
|
|
143
154
|
return this.request();
|
|
144
155
|
}
|
|
145
|
-
// eslint-disable-next-line
|
|
146
|
-
async retryReuqestError(error) { }
|
|
147
156
|
/**
|
|
148
157
|
*
|
|
149
158
|
* @description 比较双方的文件到底谁更新鲜,更新鲜的数据才需要被同步上去
|
|
@@ -154,6 +163,9 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
154
163
|
* @memberof SyncFolderBaseCommand
|
|
155
164
|
*/
|
|
156
165
|
async getWaitSyncObjects(fromObjectsMap, toObjectsMap) {
|
|
166
|
+
if (!(0, isEmpty_1.default)(this.waitSyncObjects)) {
|
|
167
|
+
return this.waitSyncObjects;
|
|
168
|
+
}
|
|
157
169
|
const intersectionKeys = [...new Set((0, keys_1.default)(fromObjectsMap).concat((0, keys_1.default)(toObjectsMap)))];
|
|
158
170
|
const actions = intersectionKeys.map((key) => {
|
|
159
171
|
return async () => {
|
|
@@ -167,15 +179,20 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
167
179
|
...fromObject,
|
|
168
180
|
action: 'PUT',
|
|
169
181
|
key,
|
|
182
|
+
reason: 'remoteNotExists',
|
|
170
183
|
};
|
|
171
184
|
}
|
|
172
185
|
// 本地不存在 && 远程存在, 则删除远程的
|
|
173
186
|
if (!fromObject && toObject) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
187
|
+
if (this.input.strictSync) {
|
|
188
|
+
return {
|
|
189
|
+
...toObject,
|
|
190
|
+
action: 'DELETE',
|
|
191
|
+
key,
|
|
192
|
+
reason: 'localNotExists',
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
179
196
|
}
|
|
180
197
|
// 本地存在的文件 && 在远程存在 && 两者文件大小不一致, 则修改远程的
|
|
181
198
|
if (fromObject.size !== toObject.size) {
|
|
@@ -183,6 +200,7 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
183
200
|
...fromObject,
|
|
184
201
|
action: 'PUT',
|
|
185
202
|
key,
|
|
203
|
+
reason: 'sizeMismatch',
|
|
186
204
|
};
|
|
187
205
|
}
|
|
188
206
|
// 本地存在的文件 && 在远程存在 && 本地日期不新鲜,则无需修改
|
|
@@ -202,6 +220,7 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
202
220
|
...fromObject,
|
|
203
221
|
action: 'PUT',
|
|
204
222
|
key,
|
|
223
|
+
reason: 'hashMismatch',
|
|
205
224
|
};
|
|
206
225
|
}
|
|
207
226
|
return null;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { PostObjectsSyncCommandOutput, SyncFolderPushCommandInput, SyncFolderPushCommandOutput } from '../../meta';
|
|
3
|
-
import { ObjectsMap, SyncFolderBaseCommand } from './sync-folder-base';
|
|
4
|
-
import type { SpaceClientOptions } from '../../protocol';
|
|
3
|
+
import { ObjectsMap, SyncFolderBaseCommand, SyncObject } from './sync-folder-base';
|
|
5
4
|
/**
|
|
6
5
|
* @see s3 sync https://stackoverflow.com/questions/27932345/downloading-folders-from-aws-s3-cp-or-sync
|
|
7
6
|
* @see 具有 Keep-alive 和连接重用的 NodeJS https://azureossd.github.io/2022/03/10/NodeJS-with-Keep-Alives-and-Connection-Reuse/index.html
|
|
@@ -12,13 +11,22 @@ import type { SpaceClientOptions } from '../../protocol';
|
|
|
12
11
|
export declare class SyncFolderPushCommand extends SyncFolderBaseCommand<SyncFolderPushCommandInput, SyncFolderPushCommandOutput> {
|
|
13
12
|
protected readonly startTime: number;
|
|
14
13
|
protected objectsSync: PostObjectsSyncCommandOutput['data'] | null;
|
|
15
|
-
constructor(input: SyncFolderPushCommandInput, context?: SpaceClientOptions);
|
|
16
14
|
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
17
15
|
request(): Promise<SyncFolderPushCommandOutput>;
|
|
18
16
|
getLocalObjectsMap(): Promise<ObjectsMap>;
|
|
19
17
|
getRemoteObjectsMap(): Promise<ObjectsMap>;
|
|
20
|
-
protected
|
|
18
|
+
protected onFailed(error: Error): Promise<void>;
|
|
21
19
|
private sync;
|
|
20
|
+
/**
|
|
21
|
+
* @see https://github.com/ArcBlock/did-spaces/issues/955#issuecomment-1873723050
|
|
22
|
+
* @description 备份的对象随时可能在进行写入操作,所以对于需要备份的文件,最佳实践是备份它们某一个时刻的副本,否则会引发错误 Error: Unexpected end of form
|
|
23
|
+
* @param {SyncObject[]} syncObject
|
|
24
|
+
* @return {*} {Promise<SyncObject[]>}
|
|
25
|
+
* @memberof IncrementalSyncPushCommand
|
|
26
|
+
*/
|
|
27
|
+
copyObjectToTmpDir(syncObject: SyncObject): Promise<SyncObject>;
|
|
28
|
+
destroyObject(syncObject: SyncObject): Promise<void>;
|
|
29
|
+
destroy(): Promise<void>;
|
|
22
30
|
private createObjectsSyncAuditLog;
|
|
23
31
|
private updateObjectsSyncAuditLog;
|
|
24
32
|
}
|
|
@@ -5,26 +5,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SyncFolderPushCommand = void 0;
|
|
7
7
|
/* eslint-disable @typescript-eslint/indent */
|
|
8
|
-
const core_1 = require("@did-space/core");
|
|
9
8
|
const fs_1 = require("fs");
|
|
9
|
+
const core_1 = require("@did-space/core");
|
|
10
10
|
const path_1 = require("path");
|
|
11
11
|
const filehound_1 = __importDefault(require("filehound"));
|
|
12
12
|
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
13
13
|
const keyBy_1 = __importDefault(require("lodash/keyBy"));
|
|
14
14
|
const fs_extra_1 = require("fs-extra");
|
|
15
|
-
const debug_1 = __importDefault(require("debug"));
|
|
16
15
|
const xbytes_1 = __importDefault(require("xbytes"));
|
|
17
|
-
const pick_1 = __importDefault(require("lodash/pick"));
|
|
18
16
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
17
|
+
const promises_1 = require("stream/promises");
|
|
18
|
+
const debug_1 = __importDefault(require("debug"));
|
|
19
|
+
const p_all_1 = __importDefault(require("p-all"));
|
|
20
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
21
|
+
const meta_1 = require("../../meta");
|
|
19
22
|
const object_1 = require("../object");
|
|
20
23
|
const sync_folder_base_1 = require("./sync-folder-base");
|
|
21
24
|
const logger_1 = require("../../libs/logger");
|
|
22
25
|
const delete_object_1 = require("../object/delete-object");
|
|
26
|
+
const preview_1 = require("../preview");
|
|
23
27
|
const libs_1 = require("../../libs");
|
|
24
28
|
const post_objects_sync_command_1 = require("../audit-log/post-objects-sync-command");
|
|
25
29
|
const put_objects_sync_command_1 = require("../audit-log/put-objects-sync-command");
|
|
26
30
|
const { name, version } = require('../../../package.json');
|
|
27
|
-
|
|
31
|
+
let debug = (0, debug_1.default)(`${name}@${version}:sync-folder-push`);
|
|
32
|
+
debug = console.error;
|
|
28
33
|
/**
|
|
29
34
|
* @see s3 sync https://stackoverflow.com/questions/27932345/downloading-folders-from-aws-s3-cp-or-sync
|
|
30
35
|
* @see 具有 Keep-alive 和连接重用的 NodeJS https://azureossd.github.io/2022/03/10/NodeJS-with-Keep-Alives-and-Connection-Reuse/index.html
|
|
@@ -35,11 +40,6 @@ const debug = (0, debug_1.default)(`${name}@${version}:sync-folder-push`);
|
|
|
35
40
|
class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
36
41
|
startTime = Date.now();
|
|
37
42
|
objectsSync = null;
|
|
38
|
-
constructor(input, context) {
|
|
39
|
-
super(input, context);
|
|
40
|
-
// 确保文件夹存在
|
|
41
|
-
(0, fs_extra_1.ensureDirSync)(this.input.source);
|
|
42
|
-
}
|
|
43
43
|
getAxiosRequestConfig() {
|
|
44
44
|
return Promise.resolve(null);
|
|
45
45
|
}
|
|
@@ -52,8 +52,8 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
52
52
|
}
|
|
53
53
|
const localObjectsMap = await this.getLocalObjectsMap();
|
|
54
54
|
const remoteObjectsMap = await this.getRemoteObjectsMap();
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const syncObjects = await this.getWaitSyncObjects(localObjectsMap, remoteObjectsMap);
|
|
56
|
+
debug('syncObjects', syncObjects);
|
|
57
57
|
debug(`[${(0, logger_1.now)()}] [waitUpload] waitUploadCount=${syncObjects.length}`);
|
|
58
58
|
debug(`[${(0, logger_1.now)()}] [context]`, { input: this.input, context: (0, pick_1.default)(this.context, ['endpoint']) });
|
|
59
59
|
const res = await this.sync(syncObjects);
|
|
@@ -77,23 +77,65 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
async getLocalObjectsMap() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
if (!(0, isEmpty_1.default)(this.localObjectsMap)) {
|
|
81
|
+
return this.localObjectsMap;
|
|
82
|
+
}
|
|
83
|
+
let objects = [];
|
|
84
|
+
if (Array.isArray(this.input.source)) {
|
|
85
|
+
objects = await (0, p_all_1.default)(this.input.source.map((x) => {
|
|
86
|
+
return async () => {
|
|
87
|
+
if ((0, meta_1.isSourceObjectWithPath)(x)) {
|
|
88
|
+
const { key, absolutePath } = x;
|
|
89
|
+
const stats = await (0, fs_extra_1.stat)(absolutePath);
|
|
90
|
+
return {
|
|
91
|
+
key: (0, path_1.join)('/', x.key),
|
|
92
|
+
name: (0, path_1.basename)(key),
|
|
93
|
+
isDir: key.endsWith('/'),
|
|
94
|
+
size: stats.size,
|
|
95
|
+
lastModified: new Date(stats.mtime).getTime(),
|
|
96
|
+
editable: true,
|
|
97
|
+
mimeType: null,
|
|
98
|
+
absolutePath,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const { key, data } = x;
|
|
102
|
+
const absolutePath = (0, path_1.join)(this.input.tmpDir, key);
|
|
103
|
+
await (0, libs_1.writeData)(absolutePath, data);
|
|
104
|
+
const stats = await (0, fs_extra_1.stat)(absolutePath);
|
|
105
|
+
return {
|
|
106
|
+
key: (0, path_1.join)('/', x.key),
|
|
107
|
+
name: (0, path_1.basename)(key),
|
|
108
|
+
isDir: key.endsWith('/'),
|
|
109
|
+
size: stats.size,
|
|
110
|
+
lastModified: new Date(stats.mtime).getTime(),
|
|
111
|
+
editable: true,
|
|
112
|
+
mimeType: null,
|
|
113
|
+
absolutePath,
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}), {
|
|
117
|
+
concurrency: this.input.concurrency,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const files = filehound_1.default.create()
|
|
122
|
+
.path(this.input.source)
|
|
123
|
+
.includeFileStats()
|
|
124
|
+
.findSync();
|
|
125
|
+
objects = await Promise.all(files.map((file) => {
|
|
126
|
+
const key = file.path.replace(this.input.source, '/');
|
|
127
|
+
return {
|
|
128
|
+
key,
|
|
129
|
+
name: (0, path_1.basename)(key),
|
|
130
|
+
isDir: key.endsWith('/'),
|
|
131
|
+
size: file.stats.size,
|
|
132
|
+
lastModified: new Date(file.stats.mtime).getTime(),
|
|
133
|
+
editable: true,
|
|
134
|
+
mimeType: null,
|
|
135
|
+
absolutePath: file.path,
|
|
136
|
+
};
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
97
139
|
if ((0, isFunction_1.default)(this.input.filter)) {
|
|
98
140
|
objects = objects.filter(this.input.filter);
|
|
99
141
|
}
|
|
@@ -101,13 +143,16 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
101
143
|
return map;
|
|
102
144
|
}
|
|
103
145
|
async getRemoteObjectsMap() {
|
|
146
|
+
if (!(0, isEmpty_1.default)(this.remoteObjectsMap)) {
|
|
147
|
+
return this.remoteObjectsMap;
|
|
148
|
+
}
|
|
104
149
|
const { data: objects } = await new object_1.ListObjectsCommand({
|
|
105
150
|
key: this.input.target,
|
|
106
151
|
}, this.context).request();
|
|
107
152
|
const map = (0, keyBy_1.default)(objects, (object) => object.key);
|
|
108
153
|
return map;
|
|
109
154
|
}
|
|
110
|
-
async
|
|
155
|
+
async onFailed(error) {
|
|
111
156
|
if (this.objectsSync) {
|
|
112
157
|
await this.updateObjectsSyncAuditLog({
|
|
113
158
|
id: this.objectsSync.id,
|
|
@@ -138,47 +183,56 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
138
183
|
});
|
|
139
184
|
const actions = syncObjects.map((x) => {
|
|
140
185
|
return async () => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
186
|
+
try {
|
|
187
|
+
await this.copyObjectToTmpDir(x);
|
|
188
|
+
const sourceKey = x.tempAbsolutePath;
|
|
189
|
+
if (!sourceKey) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const targetKey = (0, path_1.join)(this.input.target, x.key);
|
|
193
|
+
await this.triggerOnProgressHook({
|
|
194
|
+
completed: completedCount,
|
|
195
|
+
total: totalCount,
|
|
196
|
+
key: sourceKey,
|
|
197
|
+
});
|
|
198
|
+
// 开始上传
|
|
199
|
+
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.before] ${sourceKey} => ${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
200
|
+
iec: true,
|
|
201
|
+
})} completed=${completedCount} total=${totalCount}`);
|
|
202
|
+
if (x.action === 'PUT') {
|
|
203
|
+
await new object_1.PutObjectCommand({
|
|
204
|
+
key: targetKey,
|
|
205
|
+
data: (0, fs_1.createReadStream)(sourceKey),
|
|
206
|
+
hash: x.hash,
|
|
207
|
+
}, this.context).request();
|
|
208
|
+
totalSize += x.size;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
await new delete_object_1.DeleteObjectCommand({
|
|
212
|
+
key: targetKey,
|
|
213
|
+
}, this.context).request();
|
|
214
|
+
}
|
|
215
|
+
// progress
|
|
216
|
+
++completedCount;
|
|
217
|
+
await this.printDebugInfo({
|
|
218
|
+
direction: 'push',
|
|
219
|
+
completedCount,
|
|
220
|
+
errorCount,
|
|
221
|
+
totalCount,
|
|
222
|
+
});
|
|
223
|
+
await this.triggerOnAfterUploadHook({
|
|
224
|
+
completed: completedCount,
|
|
225
|
+
total: totalCount,
|
|
226
|
+
key: sourceKey,
|
|
227
|
+
});
|
|
228
|
+
// 结束上传
|
|
229
|
+
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.after] ${sourceKey}=>${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
230
|
+
iec: true,
|
|
231
|
+
})} completed=${completedCount} total=${totalCount}`);
|
|
159
232
|
}
|
|
160
|
-
|
|
161
|
-
await
|
|
162
|
-
key: targetKey,
|
|
163
|
-
}, this.context).request();
|
|
233
|
+
finally {
|
|
234
|
+
await this.destroyObject(x);
|
|
164
235
|
}
|
|
165
|
-
// progress
|
|
166
|
-
++completedCount;
|
|
167
|
-
await this.printDebugInfo({
|
|
168
|
-
direction: 'push',
|
|
169
|
-
completedCount,
|
|
170
|
-
errorCount,
|
|
171
|
-
totalCount,
|
|
172
|
-
});
|
|
173
|
-
await this.triggerOnAfterUploadHook({
|
|
174
|
-
completed: completedCount,
|
|
175
|
-
total: totalCount,
|
|
176
|
-
key: sourceKey,
|
|
177
|
-
});
|
|
178
|
-
// 结束上传
|
|
179
|
-
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.after] ${sourceKey}=>${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
180
|
-
iec: true,
|
|
181
|
-
})} completed=${completedCount} total=${totalCount}`);
|
|
182
236
|
};
|
|
183
237
|
});
|
|
184
238
|
if (!(0, isEmpty_1.default)(this.input.metadata)) {
|
|
@@ -189,6 +243,17 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
189
243
|
}, this.context).request();
|
|
190
244
|
});
|
|
191
245
|
}
|
|
246
|
+
if (!(0, isEmpty_1.default)(this.input.preview)) {
|
|
247
|
+
actions.unshift(async () => {
|
|
248
|
+
await new preview_1.PutPreviewObjectCommand({
|
|
249
|
+
key: this.input.target,
|
|
250
|
+
// @ts-ignore TODO: 这个问题是啥?
|
|
251
|
+
data: {
|
|
252
|
+
...this.input.preview,
|
|
253
|
+
},
|
|
254
|
+
}, this.context).request();
|
|
255
|
+
});
|
|
256
|
+
}
|
|
192
257
|
await this.queue.addAll(actions);
|
|
193
258
|
await this.queue.onIdle();
|
|
194
259
|
await this.destroy();
|
|
@@ -202,12 +267,47 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
202
267
|
},
|
|
203
268
|
};
|
|
204
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* @see https://github.com/ArcBlock/did-spaces/issues/955#issuecomment-1873723050
|
|
272
|
+
* @description 备份的对象随时可能在进行写入操作,所以对于需要备份的文件,最佳实践是备份它们某一个时刻的副本,否则会引发错误 Error: Unexpected end of form
|
|
273
|
+
* @param {SyncObject[]} syncObject
|
|
274
|
+
* @return {*} {Promise<SyncObject[]>}
|
|
275
|
+
* @memberof IncrementalSyncPushCommand
|
|
276
|
+
*/
|
|
277
|
+
async copyObjectToTmpDir(syncObject) {
|
|
278
|
+
const source = syncObject.absolutePath;
|
|
279
|
+
const tempAbsolutePath = (0, path_1.join)(this.input.tmpDir, syncObject.key);
|
|
280
|
+
if (syncObject.action !== 'PUT' || !(await (0, fs_extra_1.pathExists)(source))) {
|
|
281
|
+
return syncObject;
|
|
282
|
+
}
|
|
283
|
+
if (!(await (0, fs_extra_1.pathExists)(tempAbsolutePath))) {
|
|
284
|
+
await (0, fs_extra_1.ensureDir)((0, path_1.dirname)(tempAbsolutePath));
|
|
285
|
+
await (0, promises_1.pipeline)((0, fs_1.createReadStream)(source), (0, fs_1.createWriteStream)(tempAbsolutePath));
|
|
286
|
+
}
|
|
287
|
+
const tempObject = await this.getObject(tempAbsolutePath);
|
|
288
|
+
syncObject.size = tempObject.size;
|
|
289
|
+
syncObject.lastModified = tempObject.lastModified;
|
|
290
|
+
syncObject.hash = await (0, core_1.getHash)((0, fs_1.createReadStream)(tempObject.absolutePath));
|
|
291
|
+
syncObject.tempAbsolutePath = tempObject.absolutePath;
|
|
292
|
+
return syncObject;
|
|
293
|
+
}
|
|
294
|
+
async destroyObject(syncObject) {
|
|
295
|
+
if (syncObject.tempAbsolutePath && (await (0, fs_extra_1.pathExists)(syncObject.tempAbsolutePath))) {
|
|
296
|
+
await (0, fs_extra_1.remove)(syncObject.tempAbsolutePath);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async destroy() {
|
|
300
|
+
await super.destroy();
|
|
301
|
+
}
|
|
205
302
|
async createObjectsSyncAuditLog() {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
303
|
+
if (typeof this.input.source === 'string') {
|
|
304
|
+
return (await new post_objects_sync_command_1.PostObjectsSyncCommand({
|
|
305
|
+
source: this.input.source,
|
|
306
|
+
target: this.input.target,
|
|
307
|
+
metadata: this.input.metadata,
|
|
308
|
+
}, this.context).request()).data;
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
211
311
|
}
|
|
212
312
|
async updateObjectsSyncAuditLog(input) {
|
|
213
313
|
const { id, reason, status, errorCount, totalCount, ...rest } = input;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeData = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const promises_1 = require("stream/promises");
|
|
7
|
+
async function writeData(target, data) {
|
|
8
|
+
await (0, fs_extra_1.ensureDir)((0, path_1.dirname)(target));
|
|
9
|
+
if (typeof data === 'string' || data instanceof Buffer) {
|
|
10
|
+
return (0, fs_extra_1.outputFile)(target, data);
|
|
11
|
+
}
|
|
12
|
+
return (0, promises_1.pipeline)(data, (0, fs_extra_1.createWriteStream)(target));
|
|
13
|
+
}
|
|
14
|
+
exports.writeData = writeData;
|
package/dist/libs/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './api';
|
|
2
|
+
export * from './data';
|
|
2
3
|
export * from './did';
|
|
3
4
|
export * from './encoding';
|
|
4
5
|
export * from './error';
|
|
@@ -10,3 +11,4 @@ export * from './performance';
|
|
|
10
11
|
export * from './sleep';
|
|
11
12
|
export * from './space';
|
|
12
13
|
export * from './stream';
|
|
14
|
+
export * from './types';
|
package/dist/libs/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./api"), exports);
|
|
18
|
+
__exportStar(require("./data"), exports);
|
|
18
19
|
__exportStar(require("./did"), exports);
|
|
19
20
|
__exportStar(require("./encoding"), exports);
|
|
20
21
|
__exportStar(require("./error"), exports);
|
|
@@ -26,3 +27,4 @@ __exportStar(require("./performance"), exports);
|
|
|
26
27
|
__exportStar(require("./sleep"), exports);
|
|
27
28
|
__exportStar(require("./space"), exports);
|
|
28
29
|
__exportStar(require("./stream"), exports);
|
|
30
|
+
__exportStar(require("./types"), exports);
|
package/dist/meta/index.d.ts
CHANGED
package/dist/meta/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./backup"), exports);
|
|
18
|
-
__exportStar(require("./incremental
|
|
18
|
+
__exportStar(require("./incremental"), exports);
|
|
19
19
|
__exportStar(require("./nft"), exports);
|
|
20
20
|
__exportStar(require("./object"), exports);
|
|
21
21
|
__exportStar(require("./restore"), exports);
|
|
@@ -10,10 +10,12 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
10
10
|
* @description 预览模板的数据
|
|
11
11
|
*/
|
|
12
12
|
data: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
|
13
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
13
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
14
14
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
15
15
|
}, {
|
|
16
|
-
template: z.ZodLiteral<"app">;
|
|
16
|
+
template: z.ZodLiteral<"app">; /**
|
|
17
|
+
* @description 预览模板的数据
|
|
18
|
+
*/
|
|
17
19
|
name: z.ZodString;
|
|
18
20
|
logo: z.ZodString;
|
|
19
21
|
}>, "strip", z.ZodTypeAny, {
|
|
@@ -27,7 +29,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
27
29
|
name: string;
|
|
28
30
|
logo: string;
|
|
29
31
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
30
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
32
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
31
33
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
32
34
|
}, {
|
|
33
35
|
template: z.ZodLiteral<"nft">;
|
|
@@ -47,7 +49,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
47
49
|
image: string;
|
|
48
50
|
chainHost: string;
|
|
49
51
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
50
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
52
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
51
53
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
52
54
|
}, {
|
|
53
55
|
template: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"profile">>>;
|
|
@@ -67,7 +69,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
67
69
|
email: string;
|
|
68
70
|
template?: "profile" | undefined;
|
|
69
71
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
70
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
72
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
71
73
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
72
74
|
}, {
|
|
73
75
|
template: z.ZodLiteral<"passport">;
|
|
@@ -99,36 +101,36 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
99
101
|
issuedTo: string;
|
|
100
102
|
verified: boolean;
|
|
101
103
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
102
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
104
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
103
105
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
104
106
|
}, {
|
|
105
|
-
template: z.ZodLiteral<"
|
|
107
|
+
template: z.ZodLiteral<"post">;
|
|
106
108
|
title: z.ZodString;
|
|
107
|
-
tags: z.ZodArray<z.ZodString, "many"
|
|
109
|
+
tags: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
108
110
|
url: z.ZodString;
|
|
109
|
-
createdAt: z.ZodString
|
|
111
|
+
createdAt: z.ZodEffects<z.ZodString, string, string>;
|
|
110
112
|
}>, "strip", z.ZodTypeAny, {
|
|
111
|
-
template: "
|
|
113
|
+
template: "post";
|
|
112
114
|
did: string;
|
|
113
115
|
title: string;
|
|
114
116
|
tags: string[];
|
|
115
117
|
url: string;
|
|
116
118
|
createdAt: string;
|
|
117
119
|
}, {
|
|
118
|
-
template: "
|
|
120
|
+
template: "post";
|
|
119
121
|
did: string;
|
|
120
122
|
title: string;
|
|
121
|
-
tags: string[];
|
|
122
123
|
url: string;
|
|
123
124
|
createdAt: string;
|
|
125
|
+
tags?: string[] | undefined;
|
|
124
126
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
125
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
127
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
126
128
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
127
129
|
}, {
|
|
128
130
|
template: z.ZodLiteral<"blog">;
|
|
129
131
|
title: z.ZodString;
|
|
130
132
|
image: z.ZodString;
|
|
131
|
-
tags: z.ZodArray<z.ZodString, "many"
|
|
133
|
+
tags: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
132
134
|
url: z.ZodString;
|
|
133
135
|
createdAt: z.ZodEffects<z.ZodString, string, string>;
|
|
134
136
|
}>, "strip", z.ZodTypeAny, {
|
|
@@ -144,17 +146,17 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
144
146
|
did: string;
|
|
145
147
|
title: string;
|
|
146
148
|
image: string;
|
|
147
|
-
tags: string[];
|
|
148
149
|
url: string;
|
|
149
150
|
createdAt: string;
|
|
151
|
+
tags?: string[] | undefined;
|
|
150
152
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
151
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
153
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
152
154
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
153
155
|
}, {
|
|
154
156
|
template: z.ZodLiteral<"bookmark">;
|
|
155
157
|
title: z.ZodString;
|
|
156
158
|
image: z.ZodString;
|
|
157
|
-
tags: z.ZodArray<z.ZodString, "many"
|
|
159
|
+
tags: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
158
160
|
url: z.ZodString;
|
|
159
161
|
createdAt: z.ZodEffects<z.ZodString, string, string>;
|
|
160
162
|
}>, "strip", z.ZodTypeAny, {
|
|
@@ -170,11 +172,11 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
170
172
|
did: string;
|
|
171
173
|
title: string;
|
|
172
174
|
image: string;
|
|
173
|
-
tags: string[];
|
|
174
175
|
url: string;
|
|
175
176
|
createdAt: string;
|
|
177
|
+
tags?: string[] | undefined;
|
|
176
178
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
177
|
-
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"
|
|
179
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"post">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">, z.ZodLiteral<"app">]>;
|
|
178
180
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
179
181
|
}, {
|
|
180
182
|
template: z.ZodLiteral<"project">;
|
|
@@ -218,18 +220,16 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
218
220
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
219
221
|
}, "strip", z.ZodTypeAny, {
|
|
220
222
|
key: string;
|
|
221
|
-
metadata?: Record<string, any> | undefined;
|
|
222
223
|
data?: any;
|
|
224
|
+
metadata?: Record<string, any> | undefined;
|
|
223
225
|
hash?: string | undefined;
|
|
224
226
|
}, {
|
|
225
227
|
key: string;
|
|
226
|
-
metadata?: Record<string, any> | undefined;
|
|
227
228
|
data?: any;
|
|
229
|
+
metadata?: Record<string, any> | undefined;
|
|
228
230
|
hash?: string | undefined;
|
|
229
231
|
}>, "many">>>;
|
|
230
232
|
}, "strip", z.ZodTypeAny, {
|
|
231
|
-
metadata: Record<string, any>;
|
|
232
|
-
key: string;
|
|
233
233
|
data: {
|
|
234
234
|
template: "app";
|
|
235
235
|
did: string;
|
|
@@ -258,7 +258,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
258
258
|
issuedTo: string;
|
|
259
259
|
verified: boolean;
|
|
260
260
|
} | {
|
|
261
|
-
template: "
|
|
261
|
+
template: "post";
|
|
262
262
|
did: string;
|
|
263
263
|
title: string;
|
|
264
264
|
tags: string[];
|
|
@@ -289,15 +289,16 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
289
289
|
createdAt: string;
|
|
290
290
|
description?: string | undefined;
|
|
291
291
|
};
|
|
292
|
+
metadata: Record<string, any>;
|
|
293
|
+
key: string;
|
|
292
294
|
resources: {
|
|
293
295
|
key: string;
|
|
294
|
-
metadata?: Record<string, any> | undefined;
|
|
295
296
|
data?: any;
|
|
297
|
+
metadata?: Record<string, any> | undefined;
|
|
296
298
|
hash?: string | undefined;
|
|
297
299
|
}[];
|
|
298
300
|
hash?: string | undefined;
|
|
299
301
|
}, {
|
|
300
|
-
key: string;
|
|
301
302
|
data: {
|
|
302
303
|
template: "app";
|
|
303
304
|
did: string;
|
|
@@ -326,28 +327,28 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
326
327
|
issuedTo: string;
|
|
327
328
|
verified: boolean;
|
|
328
329
|
} | {
|
|
329
|
-
template: "
|
|
330
|
+
template: "post";
|
|
330
331
|
did: string;
|
|
331
332
|
title: string;
|
|
332
|
-
tags: string[];
|
|
333
333
|
url: string;
|
|
334
334
|
createdAt: string;
|
|
335
|
+
tags?: string[] | undefined;
|
|
335
336
|
} | {
|
|
336
337
|
template: "blog";
|
|
337
338
|
did: string;
|
|
338
339
|
title: string;
|
|
339
340
|
image: string;
|
|
340
|
-
tags: string[];
|
|
341
341
|
url: string;
|
|
342
342
|
createdAt: string;
|
|
343
|
+
tags?: string[] | undefined;
|
|
343
344
|
} | {
|
|
344
345
|
template: "bookmark";
|
|
345
346
|
did: string;
|
|
346
347
|
title: string;
|
|
347
348
|
image: string;
|
|
348
|
-
tags: string[];
|
|
349
349
|
url: string;
|
|
350
350
|
createdAt: string;
|
|
351
|
+
tags?: string[] | undefined;
|
|
351
352
|
} | {
|
|
352
353
|
template: "project";
|
|
353
354
|
did: string;
|
|
@@ -357,12 +358,13 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
357
358
|
createdAt: string;
|
|
358
359
|
description?: string | undefined;
|
|
359
360
|
};
|
|
361
|
+
key: string;
|
|
360
362
|
metadata?: Record<string, any> | undefined;
|
|
361
363
|
hash?: string | undefined;
|
|
362
364
|
resources?: {
|
|
363
365
|
key: string;
|
|
364
|
-
metadata?: Record<string, any> | undefined;
|
|
365
366
|
data?: any;
|
|
367
|
+
metadata?: Record<string, any> | undefined;
|
|
366
368
|
hash?: string | undefined;
|
|
367
369
|
}[] | undefined;
|
|
368
370
|
}>;
|
|
@@ -20,13 +20,13 @@ export declare const PutObjectCommandInputSchema: z.ZodObject<{
|
|
|
20
20
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
22
|
key: string;
|
|
23
|
-
metadata?: Record<string, any> | undefined;
|
|
24
23
|
data?: any;
|
|
24
|
+
metadata?: Record<string, any> | undefined;
|
|
25
25
|
hash?: string | undefined;
|
|
26
26
|
}, {
|
|
27
27
|
key: string;
|
|
28
|
-
metadata?: Record<string, any> | undefined;
|
|
29
28
|
data?: any;
|
|
29
|
+
metadata?: Record<string, any> | undefined;
|
|
30
30
|
hash?: string | undefined;
|
|
31
31
|
}>;
|
|
32
32
|
export interface PutObjectCommandInput extends z.infer<typeof PutObjectCommandInputSchema>, CommandInput {
|
|
@@ -93,6 +93,12 @@ export interface SyncBaseCommandInput extends CommandInput {
|
|
|
93
93
|
* @memberof SyncBaseCommandInput
|
|
94
94
|
*/
|
|
95
95
|
tmpDir?: string;
|
|
96
|
+
/**
|
|
97
|
+
* @description 是否启用严格同步, 默认是 false。如果为 true, 则会从 target 中删除多余的文件(删除 target 中存在的文件但在 source 中不存在的文件)
|
|
98
|
+
* @type {boolean}
|
|
99
|
+
* @memberof SyncBaseCommandInput
|
|
100
|
+
*/
|
|
101
|
+
strictSync?: boolean;
|
|
96
102
|
}
|
|
97
103
|
export interface SyncBaseCommandOutputData {
|
|
98
104
|
/**
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import type { Data } from '@did-space/core';
|
|
1
2
|
import { SyncBaseCommandInput, SyncBaseCommandOutput } from './sync-base-command';
|
|
3
|
+
export interface SourceObjectWithPath {
|
|
4
|
+
key: string;
|
|
5
|
+
absolutePath: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SourceObjectWithData {
|
|
8
|
+
key: string;
|
|
9
|
+
data: Data;
|
|
10
|
+
}
|
|
11
|
+
export type SourceObject = SourceObjectWithPath | SourceObjectWithData;
|
|
2
12
|
export interface SyncFolderBaseCommandInput extends SyncBaseCommandInput {
|
|
3
13
|
/**
|
|
4
14
|
*
|
|
@@ -6,7 +16,9 @@ export interface SyncFolderBaseCommandInput extends SyncBaseCommandInput {
|
|
|
6
16
|
* @type {string}
|
|
7
17
|
* @memberof SyncFolderBaseCommandInput
|
|
8
18
|
*/
|
|
9
|
-
source: string;
|
|
19
|
+
source: string | SourceObject[];
|
|
10
20
|
}
|
|
11
21
|
export interface SyncFolderBaseCommandOutput extends SyncBaseCommandOutput {
|
|
12
22
|
}
|
|
23
|
+
export declare function isSourceObjectWithPath(object: SourceObject): object is SourceObjectWithPath;
|
|
24
|
+
export declare function isSourceObjectWithData(object: SourceObject): object is SourceObjectWithData;
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSourceObjectWithData = exports.isSourceObjectWithPath = void 0;
|
|
4
|
+
function isSourceObjectWithPath(object) {
|
|
5
|
+
return typeof object === 'object' && 'absolutePath' in object;
|
|
6
|
+
}
|
|
7
|
+
exports.isSourceObjectWithPath = isSourceObjectWithPath;
|
|
8
|
+
function isSourceObjectWithData(object) {
|
|
9
|
+
return typeof object === 'object' && 'data' in object;
|
|
10
|
+
}
|
|
11
|
+
exports.isSourceObjectWithData = isSourceObjectWithData;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SyncFolderBaseCommandInput, SyncFolderBaseCommandOutput } from './sync-folder-base-command';
|
|
2
2
|
export interface SyncFolderPullCommandInput extends SyncFolderBaseCommandInput {
|
|
3
|
+
source: string;
|
|
3
4
|
}
|
|
4
5
|
export interface SyncFolderPullCommandOutput extends SyncFolderBaseCommandOutput {
|
|
5
6
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { ObjectMetadata } from '@did-space/core';
|
|
1
|
+
import type { ObjectMetadata, PreviewTemplate } from '@did-space/core';
|
|
2
2
|
import { SyncFolderBaseCommandInput, SyncFolderBaseCommandOutput } from './sync-folder-base-command';
|
|
3
3
|
export interface SyncFolderPushCommandInput extends SyncFolderBaseCommandInput {
|
|
4
4
|
metadata?: ObjectMetadata;
|
|
5
|
+
/**
|
|
6
|
+
* @description 预览模板
|
|
7
|
+
*/
|
|
8
|
+
preview?: PreviewTemplate;
|
|
5
9
|
}
|
|
6
10
|
export interface SyncFolderPushCommandOutput extends SyncFolderBaseCommandOutput {
|
|
7
11
|
}
|
|
@@ -15,7 +15,6 @@ const mcrypto_1 = require("@ocap/mcrypto");
|
|
|
15
15
|
const wallet_1 = require("@ocap/wallet");
|
|
16
16
|
const is_url_1 = __importDefault(require("is-url"));
|
|
17
17
|
const debug_1 = __importDefault(require("debug"));
|
|
18
|
-
const logger_1 = require("../libs/logger");
|
|
19
18
|
const debug = (0, debug_1.default)('request-signature');
|
|
20
19
|
// verifyDelegation to get actual appDid
|
|
21
20
|
async function verifyDelegation(delegation, delegatee) {
|
|
@@ -126,13 +125,14 @@ async function verifyRequest({ url, method, data, headers, }) {
|
|
|
126
125
|
data: verifyData,
|
|
127
126
|
}));
|
|
128
127
|
if (payload.digest !== expectedDigest) {
|
|
129
|
-
|
|
128
|
+
console.error('verifyRequest.payload.digest.error', {
|
|
130
129
|
url,
|
|
131
130
|
signUrl,
|
|
132
131
|
method,
|
|
133
|
-
data,
|
|
134
132
|
headers,
|
|
133
|
+
verifyData,
|
|
135
134
|
});
|
|
135
|
+
console.error('verifyRequest.payload.digest.data', data);
|
|
136
136
|
throw new Error('payload.digest do not match');
|
|
137
137
|
}
|
|
138
138
|
return appDid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/did-space-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@arcblock/jwt": "^1.19.17",
|
|
34
34
|
"@arcblock/validator": "^1.19.17",
|
|
35
35
|
"@blocklet/env": "^1.16.41",
|
|
36
|
-
"@did-space/core": "^1.0.
|
|
36
|
+
"@did-space/core": "^1.0.41",
|
|
37
37
|
"@ocap/mcrypto": "^1.19.17",
|
|
38
38
|
"@ocap/util": "^1.19.17",
|
|
39
39
|
"@ocap/wallet": "^1.19.17",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"json-stable-stringify": "^1.2.1",
|
|
54
54
|
"lodash": "^4.17.21",
|
|
55
55
|
"mime-types": "^2.1.35",
|
|
56
|
+
"nanoid": "^3.3.11",
|
|
56
57
|
"p-all": "3.0.0",
|
|
57
58
|
"p-queue": "6.6.2",
|
|
58
59
|
"ufo": "^1.5.4",
|
|
@@ -76,5 +77,5 @@
|
|
|
76
77
|
"ts-jest": "^28.0.8",
|
|
77
78
|
"typescript": "^4.9.5"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "7747108164c8e0cc847146ff34eb9bf289523cc1"
|
|
80
81
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|