@blocklet/did-space-js 1.0.9 → 1.0.11
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/api/index.d.ts +1 -0
- package/dist/api/index.js +17 -0
- package/dist/api/routes/audit-log-list.d.ts +5 -0
- package/dist/api/routes/audit-log-list.js +57 -0
- package/dist/api/routes/index.d.ts +1 -0
- package/dist/api/routes/index.js +17 -0
- package/dist/client/index.js +2 -2
- package/dist/commands/audit-log/post-objects-sync-command.d.ts +9 -0
- package/dist/commands/audit-log/post-objects-sync-command.js +58 -0
- package/dist/commands/audit-log/put-objects-sync-command.d.ts +9 -0
- package/dist/commands/audit-log/put-objects-sync-command.js +57 -0
- package/dist/commands/backup/backup-blocklet.d.ts +1 -1
- package/dist/commands/backup/backup-blocklet.js +3 -2
- package/dist/commands/backup/post-app-backup.d.ts +1 -1
- package/dist/commands/backup/post-app-backup.js +1 -1
- package/dist/commands/backup/put-app-backup.d.ts +1 -1
- package/dist/commands/backup/put-app-backup.js +1 -1
- package/dist/commands/base.d.ts +1 -1
- package/dist/commands/base.js +2 -2
- package/dist/commands/incremental-backup/backup-blocklet.d.ts +1 -1
- package/dist/commands/incremental-backup/backup-blocklet.js +4 -3
- package/dist/commands/incremental-sync/sync-base.js +2 -1
- package/dist/commands/incremental-sync/sync-push.d.ts +1 -1
- package/dist/commands/incremental-sync/sync-push.js +4 -1
- package/dist/commands/object/put-object.d.ts +1 -1
- package/dist/commands/object/put-object.js +2 -3
- package/dist/commands/preview/delete-preview-object.d.ts +1 -1
- package/dist/commands/preview/get-preview-object.d.ts +1 -1
- package/dist/commands/preview/put-preview-object.d.ts +1 -1
- package/dist/commands/restore/post-app-restore.d.ts +1 -1
- package/dist/commands/restore/post-app-restore.js +1 -1
- package/dist/commands/restore/put-app-restore.d.ts +1 -1
- package/dist/commands/restore/put-app-restore.js +1 -1
- package/dist/commands/restore/restore-blocklet.d.ts +1 -1
- package/dist/commands/restore/restore-blocklet.js +3 -2
- package/dist/commands/space/head.d.ts +1 -1
- package/dist/commands/space/head.js +1 -1
- package/dist/commands/sync/sync-folder-base.d.ts +2 -1
- package/dist/commands/sync/sync-folder-base.js +5 -1
- package/dist/commands/sync/sync-folder-pull.d.ts +1 -1
- package/dist/commands/sync/sync-folder-pull.js +4 -1
- package/dist/commands/sync/sync-folder-push.d.ts +6 -2
- package/dist/commands/sync/sync-folder-push.js +66 -2
- package/dist/did-document/did-document.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/meta/object/preview-object-command.d.ts +32 -32
- package/dist/meta/object/put-object-command.d.ts +6 -6
- package/dist/meta/sync/index.d.ts +2 -0
- package/dist/meta/sync/index.js +2 -0
- package/dist/meta/sync/post-objects-sync-command.d.ts +20 -0
- package/dist/meta/sync/post-objects-sync-command.js +9 -0
- package/dist/meta/sync/put-objects-sync-command.d.ts +35 -0
- package/dist/meta/sync/put-objects-sync-command.js +15 -0
- package/dist/meta/sync/sync-base-command.d.ts +6 -0
- package/package.json +12 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './routes';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./routes"), exports);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.auditLogList = void 0;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const core_1 = require("@did-space/core");
|
|
7
|
+
const libs_1 = require("../../libs");
|
|
8
|
+
const security_1 = require("../../security");
|
|
9
|
+
const QuerySchema = zod_1.z.object({
|
|
10
|
+
endpoint: zod_1.z.string(),
|
|
11
|
+
size: zod_1.z
|
|
12
|
+
.string()
|
|
13
|
+
.default('10')
|
|
14
|
+
.transform((val) => parseInt(val, 10)),
|
|
15
|
+
page: zod_1.z
|
|
16
|
+
.string()
|
|
17
|
+
.default('0')
|
|
18
|
+
.transform((val) => parseInt(val, 10)),
|
|
19
|
+
sort: zod_1.z.string().default(''),
|
|
20
|
+
order: zod_1.z
|
|
21
|
+
.string()
|
|
22
|
+
.default('0')
|
|
23
|
+
.transform((val) => parseInt(val, 10)),
|
|
24
|
+
status: zod_1.z.union([zod_1.z.nativeEnum(core_1.AuditLogStatus), zod_1.z.array(zod_1.z.nativeEnum(core_1.AuditLogStatus))]).optional(),
|
|
25
|
+
actionType: zod_1.z.union([zod_1.z.nativeEnum(core_1.AuditLogAction), zod_1.z.array(zod_1.z.nativeEnum(core_1.AuditLogAction))]).optional(),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* @route /.well-known/service/api/did-space/audit-log/list 借助 service 查询 space 审计日志
|
|
29
|
+
*/
|
|
30
|
+
async function auditLogList(req, res) {
|
|
31
|
+
const { endpoint, ...data } = QuerySchema.parse(req.query);
|
|
32
|
+
// @ts-ignore 依赖 service 请求上下文
|
|
33
|
+
const { wallet } = await req.getBlockletInfo();
|
|
34
|
+
const baseUrl = endpoint.replace(/\/object\/?$/, '');
|
|
35
|
+
const url = (0, ufo_1.withQuery)((0, ufo_1.joinURL)(baseUrl, 'audit-log/list'), data);
|
|
36
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
37
|
+
url,
|
|
38
|
+
method: req.method,
|
|
39
|
+
data,
|
|
40
|
+
headers: {},
|
|
41
|
+
wallet,
|
|
42
|
+
});
|
|
43
|
+
const response = await (0, libs_1.gotApi)({
|
|
44
|
+
url,
|
|
45
|
+
method: 'GET',
|
|
46
|
+
responseType: 'json',
|
|
47
|
+
headers: {
|
|
48
|
+
...headers,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
res.send({
|
|
52
|
+
statusCode: response.statusCode,
|
|
53
|
+
statusMessage: response.statusMessage,
|
|
54
|
+
data: response.body,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.auditLogList = auditLogList;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-log-list';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./audit-log-list"), exports);
|
package/dist/client/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { PostObjectsSyncCommandInput, PostObjectsSyncCommandOutput } from '../../meta/sync';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
import type { SpaceClientOptions } from '../../protocol';
|
|
5
|
+
export declare class PostObjectsSyncCommand extends BaseCommand<PostObjectsSyncCommandInput, PostObjectsSyncCommandOutput> {
|
|
6
|
+
constructor(input: PostObjectsSyncCommandInput, context?: SpaceClientOptions);
|
|
7
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
8
|
+
resolveMiddleware(): Promise<PostObjectsSyncCommandOutput>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostObjectsSyncCommand = void 0;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
const core_1 = require("@did-space/core");
|
|
6
|
+
const libs_1 = require("../../libs");
|
|
7
|
+
const sync_1 = require("../../meta/sync");
|
|
8
|
+
const security_1 = require("../../security");
|
|
9
|
+
const base_1 = require("../base");
|
|
10
|
+
class PostObjectsSyncCommand extends base_1.BaseCommand {
|
|
11
|
+
constructor(input, context) {
|
|
12
|
+
super(input, context);
|
|
13
|
+
const { error, data } = sync_1.PostObjectsSyncCommandInputSchema.safeParse(input);
|
|
14
|
+
if (error) {
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
this.input = data;
|
|
18
|
+
}
|
|
19
|
+
getAxiosRequestConfig() {
|
|
20
|
+
return Promise.resolve(null);
|
|
21
|
+
}
|
|
22
|
+
async resolveMiddleware() {
|
|
23
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'audit-log');
|
|
24
|
+
const data = {
|
|
25
|
+
actionType: core_1.AuditLogAction.APP_OBJECTS_SYNC,
|
|
26
|
+
data: {
|
|
27
|
+
...this.input,
|
|
28
|
+
totalCount: 0,
|
|
29
|
+
errorCount: 0,
|
|
30
|
+
successCount: 0,
|
|
31
|
+
size: 0,
|
|
32
|
+
duration: 0,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const method = 'POST';
|
|
36
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
37
|
+
url,
|
|
38
|
+
method,
|
|
39
|
+
data,
|
|
40
|
+
headers: {},
|
|
41
|
+
wallet: this.context.wallet,
|
|
42
|
+
delegation: this.context.delegation,
|
|
43
|
+
});
|
|
44
|
+
const response = await (0, libs_1.gotApi)({
|
|
45
|
+
url,
|
|
46
|
+
method,
|
|
47
|
+
json: data,
|
|
48
|
+
responseType: 'json',
|
|
49
|
+
headers,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
statusCode: response.statusCode,
|
|
53
|
+
statusMessage: response.statusMessage,
|
|
54
|
+
data: response.body,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.PostObjectsSyncCommand = PostObjectsSyncCommand;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { PutObjectsSyncCommandInput, PutObjectsSyncCommandOutput } from '../../meta';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
import type { SpaceClientOptions } from '../../protocol';
|
|
5
|
+
export declare class PutObjectsSyncCommand extends BaseCommand<PutObjectsSyncCommandInput, PutObjectsSyncCommandOutput> {
|
|
6
|
+
constructor(input: PutObjectsSyncCommandInput, context?: SpaceClientOptions);
|
|
7
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
8
|
+
resolveMiddleware(): Promise<PutObjectsSyncCommandOutput>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PutObjectsSyncCommand = void 0;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
const core_1 = require("@did-space/core");
|
|
6
|
+
const libs_1 = require("../../libs");
|
|
7
|
+
const meta_1 = require("../../meta");
|
|
8
|
+
const security_1 = require("../../security");
|
|
9
|
+
const base_1 = require("../base");
|
|
10
|
+
class PutObjectsSyncCommand extends base_1.BaseCommand {
|
|
11
|
+
constructor(input, context) {
|
|
12
|
+
super(input, context);
|
|
13
|
+
const { error, data } = meta_1.PutObjectsSyncCommandInputSchema.safeParse(input);
|
|
14
|
+
if (error) {
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
this.input = data;
|
|
18
|
+
}
|
|
19
|
+
getAxiosRequestConfig() {
|
|
20
|
+
return Promise.resolve(null);
|
|
21
|
+
}
|
|
22
|
+
async resolveMiddleware() {
|
|
23
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'audit-log');
|
|
24
|
+
const { id, status, reason, ...rest } = this.input;
|
|
25
|
+
const body = {
|
|
26
|
+
id,
|
|
27
|
+
status,
|
|
28
|
+
reason,
|
|
29
|
+
actionType: core_1.AuditLogAction.APP_OBJECTS_SYNC,
|
|
30
|
+
data: rest,
|
|
31
|
+
};
|
|
32
|
+
const method = 'PUT';
|
|
33
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
34
|
+
url,
|
|
35
|
+
method,
|
|
36
|
+
data: body,
|
|
37
|
+
headers: {},
|
|
38
|
+
wallet: this.context.wallet,
|
|
39
|
+
delegation: this.context.delegation,
|
|
40
|
+
});
|
|
41
|
+
const response = await (0, libs_1.gotApi)({
|
|
42
|
+
url,
|
|
43
|
+
method,
|
|
44
|
+
json: body,
|
|
45
|
+
responseType: 'json',
|
|
46
|
+
headers: {
|
|
47
|
+
...headers,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
statusCode: response.statusCode,
|
|
52
|
+
statusMessage: response.statusMessage,
|
|
53
|
+
data: response.body,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.PutObjectsSyncCommand = PutObjectsSyncCommand;
|
|
@@ -9,6 +9,6 @@ import { BaseCommand } from '../base';
|
|
|
9
9
|
* @extends {BaseCommand<BackupBlockletCommandInput, BackupBlockletCommandOutput>}
|
|
10
10
|
*/
|
|
11
11
|
export declare class BackupBlockletCommand extends BaseCommand<BackupBlockletCommandInput, BackupBlockletCommandOutput> {
|
|
12
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
12
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
13
13
|
resolveMiddleware(): Promise<BackupBlockletCommandOutput>;
|
|
14
14
|
}
|
|
@@ -18,10 +18,10 @@ const space_1 = require("../../libs/space");
|
|
|
18
18
|
*/
|
|
19
19
|
class BackupBlockletCommand extends base_1.BaseCommand {
|
|
20
20
|
getAxiosRequestConfig() {
|
|
21
|
-
return null;
|
|
21
|
+
return Promise.resolve(null);
|
|
22
22
|
}
|
|
23
23
|
async resolveMiddleware() {
|
|
24
|
-
let appBackup;
|
|
24
|
+
let appBackup = null;
|
|
25
25
|
try {
|
|
26
26
|
// @note: 备份还原的时候我们希望使用 service url 来完成,不希望走 CDN
|
|
27
27
|
this.context.endpoint = await (0, space_1.getSpaceServiceEndpoint)(this.context.endpoint);
|
|
@@ -75,6 +75,7 @@ class BackupBlockletCommand extends base_1.BaseCommand {
|
|
|
75
75
|
errorCount: -1,
|
|
76
76
|
count: -1,
|
|
77
77
|
duration: -1,
|
|
78
|
+
size: -1,
|
|
78
79
|
},
|
|
79
80
|
};
|
|
80
81
|
}
|
|
@@ -4,6 +4,6 @@ import { BaseCommand } from '../base';
|
|
|
4
4
|
import type { SpaceClientOptions } from '../../protocol';
|
|
5
5
|
export declare class PostAppBackupCommand extends BaseCommand<PostAppBackupCommandInput, PostAppBackupCommandOutput> {
|
|
6
6
|
constructor(input: PostAppBackupCommandInput, context?: SpaceClientOptions);
|
|
7
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
7
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
8
8
|
resolveMiddleware(): Promise<PostAppBackupCommandOutput>;
|
|
9
9
|
}
|
|
@@ -16,7 +16,7 @@ class PostAppBackupCommand extends base_1.BaseCommand {
|
|
|
16
16
|
this.input = value;
|
|
17
17
|
}
|
|
18
18
|
getAxiosRequestConfig() {
|
|
19
|
-
return null;
|
|
19
|
+
return Promise.resolve(null);
|
|
20
20
|
}
|
|
21
21
|
async resolveMiddleware() {
|
|
22
22
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'backup');
|
|
@@ -4,6 +4,6 @@ import { BaseCommand } from '../base';
|
|
|
4
4
|
import type { SpaceClientOptions } from '../../protocol';
|
|
5
5
|
export declare class PutAppBackupCommand extends BaseCommand<PutAppBackupCommandInput, PutAppBackupCommandOutput> {
|
|
6
6
|
constructor(input: PutAppBackupCommandInput, context?: SpaceClientOptions);
|
|
7
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
7
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
8
8
|
resolveMiddleware(): Promise<PutAppBackupCommandOutput>;
|
|
9
9
|
}
|
|
@@ -16,7 +16,7 @@ class PutAppBackupCommand extends base_1.BaseCommand {
|
|
|
16
16
|
this.input = value;
|
|
17
17
|
}
|
|
18
18
|
getAxiosRequestConfig() {
|
|
19
|
-
return null;
|
|
19
|
+
return Promise.resolve(null);
|
|
20
20
|
}
|
|
21
21
|
async resolveMiddleware() {
|
|
22
22
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'backup');
|
package/dist/commands/base.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare abstract class BaseCommand<BaseCommandInput extends CommandInput,
|
|
|
14
14
|
input: BaseCommandInput;
|
|
15
15
|
context: SpaceClientOptions;
|
|
16
16
|
constructor(input: BaseCommandInput, context?: SpaceClientOptions);
|
|
17
|
-
abstract getAxiosRequestConfig(): Promise<AxiosRequestConfig>;
|
|
17
|
+
abstract getAxiosRequestConfig(): Promise<AxiosRequestConfig | null>;
|
|
18
18
|
getKey(key: string, options?: GetKeyOptions): string;
|
|
19
19
|
request(): Promise<BaseCommandOutput>;
|
|
20
20
|
resolveMiddleware(res?: AxiosResponse<BaseCommandOutput['data'], any>): Promise<BaseCommandOutput>;
|
package/dist/commands/base.js
CHANGED
|
@@ -9,6 +9,6 @@ import { BaseCommand } from '../base';
|
|
|
9
9
|
* @extends {BaseCommand<BackupBlockletCommandInput, BackupBlockletCommandOutput>}
|
|
10
10
|
*/
|
|
11
11
|
export declare class IncrementalBackupBlockletCommand extends BaseCommand<IncrementalBackupBlockletCommandInput, IncrementalBackupBlockletCommandOutput> {
|
|
12
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
12
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
13
13
|
resolveMiddleware(): Promise<BackupBlockletCommandOutput>;
|
|
14
14
|
}
|
|
@@ -17,11 +17,11 @@ const incremental_sync_1 = require("../incremental-sync");
|
|
|
17
17
|
*/
|
|
18
18
|
class IncrementalBackupBlockletCommand extends base_1.BaseCommand {
|
|
19
19
|
getAxiosRequestConfig() {
|
|
20
|
-
return null;
|
|
20
|
+
return Promise.resolve(null);
|
|
21
21
|
}
|
|
22
22
|
async resolveMiddleware() {
|
|
23
|
-
let appBackup;
|
|
24
|
-
let incrementalSyncPushInstance;
|
|
23
|
+
let appBackup = null;
|
|
24
|
+
let incrementalSyncPushInstance = null;
|
|
25
25
|
try {
|
|
26
26
|
// @note: 备份还原的时候我们希望使用 service url 来完成,不希望走 CDN
|
|
27
27
|
this.context.endpoint = await (0, space_1.getSpaceServiceEndpoint)(this.context.endpoint);
|
|
@@ -76,6 +76,7 @@ class IncrementalBackupBlockletCommand extends base_1.BaseCommand {
|
|
|
76
76
|
errorCount: -1,
|
|
77
77
|
count: -1,
|
|
78
78
|
duration: -1,
|
|
79
|
+
size: -1,
|
|
79
80
|
},
|
|
80
81
|
};
|
|
81
82
|
}
|
|
@@ -104,7 +104,7 @@ class IncrementalSyncBaseCommand extends base_1.BaseCommand {
|
|
|
104
104
|
*/
|
|
105
105
|
async retryRequest(error) {
|
|
106
106
|
// 减少重试次数
|
|
107
|
-
|
|
107
|
+
this.input.retryCount = this.input.retryCount - 1;
|
|
108
108
|
// clear queue
|
|
109
109
|
this.queue.clear();
|
|
110
110
|
// 输出错误
|
|
@@ -128,6 +128,7 @@ class IncrementalSyncBaseCommand extends base_1.BaseCommand {
|
|
|
128
128
|
errorCount: -1,
|
|
129
129
|
count: -1,
|
|
130
130
|
duration: (Date.now() - this.startTime) / 1000,
|
|
131
|
+
size: -1,
|
|
131
132
|
},
|
|
132
133
|
};
|
|
133
134
|
}
|
|
@@ -12,7 +12,7 @@ import { IncrementalSyncBaseCommand } from './sync-base';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class IncrementalSyncPushCommand extends IncrementalSyncBaseCommand<IncrementalSyncPushCommandInput, IncrementalSyncPushCommandOutput> {
|
|
14
14
|
protected readonly startTime: number;
|
|
15
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
15
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
16
16
|
request(): Promise<IncrementalSyncPushCommandOutput>;
|
|
17
17
|
getLocalObjectsMap(): Promise<ObjectsMap>;
|
|
18
18
|
getRemoteObjectsMap(): Promise<ObjectsMap>;
|
|
@@ -33,7 +33,7 @@ const debug = (0, debug_1.default)(`${name}@${version}:sync-folder-push`);
|
|
|
33
33
|
class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand {
|
|
34
34
|
startTime = Date.now();
|
|
35
35
|
getAxiosRequestConfig() {
|
|
36
|
-
return null;
|
|
36
|
+
return Promise.resolve(null);
|
|
37
37
|
}
|
|
38
38
|
async request() {
|
|
39
39
|
try {
|
|
@@ -125,6 +125,7 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
|
|
|
125
125
|
this.registerEvents();
|
|
126
126
|
let errorCount = 0;
|
|
127
127
|
let completedCount = 0;
|
|
128
|
+
let totalSize = 0;
|
|
128
129
|
const totalCount = syncObjects.length;
|
|
129
130
|
// @ts-expect-error
|
|
130
131
|
this.queue.on('error', async () => {
|
|
@@ -162,6 +163,7 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
|
|
|
162
163
|
data: (0, fs_1.createReadStream)(sourceKey),
|
|
163
164
|
hash: x.hash,
|
|
164
165
|
}, this.context).request();
|
|
166
|
+
totalSize += x.size;
|
|
165
167
|
}
|
|
166
168
|
else {
|
|
167
169
|
await new delete_object_1.DeleteObjectCommand({
|
|
@@ -195,6 +197,7 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
|
|
|
195
197
|
count: actions.length,
|
|
196
198
|
errorCount,
|
|
197
199
|
duration: (Date.now() - this.startTime) / 1000,
|
|
200
|
+
size: totalSize,
|
|
198
201
|
},
|
|
199
202
|
};
|
|
200
203
|
}
|
|
@@ -2,6 +2,6 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { PutObjectCommandInput, PutObjectCommandOutput } from '../../meta';
|
|
3
3
|
import { BaseCommand } from '../base';
|
|
4
4
|
export declare class PutObjectCommand extends BaseCommand<PutObjectCommandInput, PutObjectCommandOutput> {
|
|
5
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
6
6
|
resolveMiddleware(): Promise<PutObjectCommandOutput>;
|
|
7
7
|
}
|
|
@@ -12,9 +12,8 @@ const libs_1 = require("../../libs");
|
|
|
12
12
|
const security_1 = require("../../security");
|
|
13
13
|
const base_1 = require("../base");
|
|
14
14
|
class PutObjectCommand extends base_1.BaseCommand {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return null;
|
|
15
|
+
getAxiosRequestConfig() {
|
|
16
|
+
return Promise.resolve(null);
|
|
18
17
|
}
|
|
19
18
|
async resolveMiddleware() {
|
|
20
19
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey(this.input.key));
|
|
@@ -2,6 +2,6 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { type DeletePreviewObjectCommandInput, type DeletePreviewObjectCommandOutput } from '../../meta';
|
|
3
3
|
import { BaseCommand } from '../base';
|
|
4
4
|
export declare class DeletePreviewObjectCommand extends BaseCommand<DeletePreviewObjectCommandInput, DeletePreviewObjectCommandOutput> {
|
|
5
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
6
6
|
resolveMiddleware(): Promise<DeletePreviewObjectCommandOutput>;
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { GetPreviewObjectCommandInput, GetPreviewObjectCommandOutput } from '../../meta';
|
|
3
3
|
import { BaseCommand } from '../base';
|
|
4
4
|
export declare class GetPreviewObjectCommand extends BaseCommand<GetPreviewObjectCommandInput, GetPreviewObjectCommandOutput> {
|
|
5
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
6
6
|
resolveMiddleware(): Promise<GetPreviewObjectCommandOutput>;
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { PutPreviewObjectCommandInput, PutPreviewObjectCommandOutput } from '../../meta';
|
|
3
3
|
import { BaseCommand } from '../base';
|
|
4
4
|
export declare class PutPreviewObjectCommand extends BaseCommand<PutPreviewObjectCommandInput, PutPreviewObjectCommandOutput> {
|
|
5
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
6
6
|
normalize(): Promise<void>;
|
|
7
7
|
resolveMiddleware(): Promise<PutPreviewObjectCommandOutput>;
|
|
8
8
|
}
|
|
@@ -2,6 +2,6 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { PostAppRestoreCommandInput, PostAppRestoreCommandOutput } from '../../meta';
|
|
3
3
|
import { BaseCommand } from '../base';
|
|
4
4
|
export declare class PostAppRestoreCommand extends BaseCommand<PostAppRestoreCommandInput, PostAppRestoreCommandOutput> {
|
|
5
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
6
6
|
resolveMiddleware(): Promise<PostAppRestoreCommandOutput>;
|
|
7
7
|
}
|
|
@@ -8,7 +8,7 @@ const security_1 = require("../../security");
|
|
|
8
8
|
const base_1 = require("../base");
|
|
9
9
|
class PostAppRestoreCommand extends base_1.BaseCommand {
|
|
10
10
|
getAxiosRequestConfig() {
|
|
11
|
-
return null;
|
|
11
|
+
return Promise.resolve(null);
|
|
12
12
|
}
|
|
13
13
|
async resolveMiddleware() {
|
|
14
14
|
const { error } = meta_1.PostAppRestoreCommandInputSchema.validate(this.input);
|
|
@@ -4,6 +4,6 @@ import { BaseCommand } from '../base';
|
|
|
4
4
|
import type { SpaceClientOptions } from '../../protocol';
|
|
5
5
|
export declare class PutAppRestoreCommand extends BaseCommand<PutAppRestoreCommandInput, PutAppRestoreCommandOutput> {
|
|
6
6
|
constructor(input: PutAppRestoreCommandInput, context?: SpaceClientOptions);
|
|
7
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
7
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
8
8
|
resolveMiddleware(): Promise<PutAppRestoreCommandOutput>;
|
|
9
9
|
}
|
|
@@ -16,7 +16,7 @@ class PutAppRestoreCommand extends base_1.BaseCommand {
|
|
|
16
16
|
this.input = value;
|
|
17
17
|
}
|
|
18
18
|
getAxiosRequestConfig() {
|
|
19
|
-
return null;
|
|
19
|
+
return Promise.resolve(null);
|
|
20
20
|
}
|
|
21
21
|
async resolveMiddleware() {
|
|
22
22
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'restore');
|
|
@@ -9,6 +9,6 @@ import { BaseCommand } from '../base';
|
|
|
9
9
|
* @extends {BaseCommand<RestoreBlockletCommandInput, RestoreBlockletCommandOutput>}
|
|
10
10
|
*/
|
|
11
11
|
export declare class RestoreBlockletCommand extends BaseCommand<RestoreBlockletCommandInput, RestoreBlockletCommandOutput> {
|
|
12
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
12
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
13
13
|
resolveMiddleware(): Promise<RestoreBlockletCommandOutput>;
|
|
14
14
|
}
|
|
@@ -18,10 +18,10 @@ const space_1 = require("../../libs/space");
|
|
|
18
18
|
*/
|
|
19
19
|
class RestoreBlockletCommand extends base_1.BaseCommand {
|
|
20
20
|
getAxiosRequestConfig() {
|
|
21
|
-
return null;
|
|
21
|
+
return Promise.resolve(null);
|
|
22
22
|
}
|
|
23
23
|
async resolveMiddleware() {
|
|
24
|
-
let appRestore;
|
|
24
|
+
let appRestore = null;
|
|
25
25
|
try {
|
|
26
26
|
// @note: 备份还原的时候我们希望使用 service url 来完成,不希望走 CDN
|
|
27
27
|
this.context.endpoint = await (0, space_1.getSpaceServiceEndpoint)(this.context.endpoint);
|
|
@@ -72,6 +72,7 @@ class RestoreBlockletCommand extends base_1.BaseCommand {
|
|
|
72
72
|
errorCount: -1,
|
|
73
73
|
count: -1,
|
|
74
74
|
duration: -1,
|
|
75
|
+
size: -1,
|
|
75
76
|
},
|
|
76
77
|
};
|
|
77
78
|
}
|
|
@@ -2,7 +2,7 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { BaseCommand } from '../base';
|
|
3
3
|
import type { HeadSpaceCommandInput, HeadSpaceCommandOutput } from '../../meta/object/head-object-command';
|
|
4
4
|
export declare class HeadSpaceCommand extends BaseCommand<HeadSpaceCommandInput, HeadSpaceCommandOutput> {
|
|
5
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
6
6
|
private getUrl;
|
|
7
7
|
resolveMiddleware(): Promise<HeadSpaceCommandOutput>;
|
|
8
8
|
}
|
|
@@ -9,7 +9,7 @@ const base_1 = require("../base");
|
|
|
9
9
|
class HeadSpaceCommand extends base_1.BaseCommand {
|
|
10
10
|
// eslint-disable-next-line require-await
|
|
11
11
|
async getAxiosRequestConfig() {
|
|
12
|
-
return null;
|
|
12
|
+
return Promise.resolve(null);
|
|
13
13
|
}
|
|
14
14
|
getUrl() {
|
|
15
15
|
const array = this.context.endpoint.split('/');
|
|
@@ -49,7 +49,7 @@ export declare abstract class SyncFolderBaseCommand<CommandInput extends SyncFol
|
|
|
49
49
|
completedCount: number;
|
|
50
50
|
errorCount: number;
|
|
51
51
|
totalCount: number;
|
|
52
|
-
}):
|
|
52
|
+
}): void;
|
|
53
53
|
/**
|
|
54
54
|
*
|
|
55
55
|
*
|
|
@@ -59,6 +59,7 @@ export declare abstract class SyncFolderBaseCommand<CommandInput extends SyncFol
|
|
|
59
59
|
* @memberof SyncFolderBaseCommand
|
|
60
60
|
*/
|
|
61
61
|
protected retryRequest(error: Error | AxiosError): Promise<SyncFolderPullCommandOutput>;
|
|
62
|
+
protected retryReuqestError(error: Error): Promise<void>;
|
|
62
63
|
/**
|
|
63
64
|
*
|
|
64
65
|
* @description 比较双方的文件到底谁更新鲜,更新鲜的数据才需要被同步上去
|
|
@@ -106,7 +106,7 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
106
106
|
*/
|
|
107
107
|
async retryRequest(error) {
|
|
108
108
|
// 减少重试次数
|
|
109
|
-
|
|
109
|
+
this.input.retryCount = this.input.retryCount - 1;
|
|
110
110
|
// clear queue
|
|
111
111
|
this.queue.clear();
|
|
112
112
|
// 输出错误
|
|
@@ -122,6 +122,7 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
122
122
|
// FIXME: retryCount === 0 表示,重试次数刚好用完了,后续优化 server 显示错误的进度 @yejianchao
|
|
123
123
|
// 防呆控制,retryCount < 0 说明调用基础接口始终是失败的,遇到了预料之外的事情,因此需要停止运行
|
|
124
124
|
if (this.input.retryCount <= 0 || [400, 401, 403, 404, 413].includes(statusCode)) {
|
|
125
|
+
await this.retryReuqestError(error);
|
|
125
126
|
await this.destroy();
|
|
126
127
|
return {
|
|
127
128
|
statusCode,
|
|
@@ -131,6 +132,7 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
131
132
|
errorCount: -1,
|
|
132
133
|
count: -1,
|
|
133
134
|
duration: (Date.now() - this.startTime) / 1000,
|
|
135
|
+
size: -1,
|
|
134
136
|
},
|
|
135
137
|
};
|
|
136
138
|
}
|
|
@@ -140,6 +142,8 @@ class SyncFolderBaseCommand extends base_1.BaseCommand {
|
|
|
140
142
|
await (0, libs_1.sleep)(retryDelayMs);
|
|
141
143
|
return this.request();
|
|
142
144
|
}
|
|
145
|
+
// eslint-disable-next-line
|
|
146
|
+
async retryReuqestError(error) { }
|
|
143
147
|
/**
|
|
144
148
|
*
|
|
145
149
|
* @description 比较双方的文件到底谁更新鲜,更新鲜的数据才需要被同步上去
|
|
@@ -5,7 +5,7 @@ import type { SpaceClientOptions } from '../../protocol';
|
|
|
5
5
|
export declare class SyncFolderPullCommand extends SyncFolderBaseCommand<SyncFolderPullCommandInput, SyncFolderPullCommandOutput> {
|
|
6
6
|
protected readonly startTime: number;
|
|
7
7
|
constructor(input: SyncFolderPullCommandInput, context?: SpaceClientOptions);
|
|
8
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
8
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
9
9
|
request(): Promise<SyncFolderPullCommandOutput>;
|
|
10
10
|
getRemoteObjectsMap(): Promise<ObjectsMap>;
|
|
11
11
|
getLocalObjectsMap(): Promise<ObjectsMap>;
|
|
@@ -28,7 +28,7 @@ class SyncFolderPullCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
28
28
|
(0, fs_extra_1.ensureDirSync)(this.input.target);
|
|
29
29
|
}
|
|
30
30
|
getAxiosRequestConfig() {
|
|
31
|
-
return null;
|
|
31
|
+
return Promise.resolve(null);
|
|
32
32
|
}
|
|
33
33
|
async request() {
|
|
34
34
|
try {
|
|
@@ -78,6 +78,7 @@ class SyncFolderPullCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
78
78
|
this.queue.removeAllListeners();
|
|
79
79
|
let errorCount = 0;
|
|
80
80
|
let completedCount = 0;
|
|
81
|
+
let totalSize = 0;
|
|
81
82
|
const totalCount = syncObjects.length;
|
|
82
83
|
// @ts-expect-error
|
|
83
84
|
this.queue.on('error', async () => {
|
|
@@ -131,6 +132,7 @@ class SyncFolderPullCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
131
132
|
key: sourceKey,
|
|
132
133
|
});
|
|
133
134
|
// 下载完成
|
|
135
|
+
totalSize += x.size;
|
|
134
136
|
debug(`[${(0, logger_1.now)()}] [sync:${x.action}.after] ${sourceKey} => ${targetKey} size=${(0, xbytes_1.default)(x.size, {
|
|
135
137
|
iec: true,
|
|
136
138
|
})} completed=${completedCount} total=${totalCount}`);
|
|
@@ -144,6 +146,7 @@ class SyncFolderPullCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
144
146
|
errorCount,
|
|
145
147
|
count: actions.length,
|
|
146
148
|
duration: (Date.now() - this.startTime) / 1000,
|
|
149
|
+
size: totalSize,
|
|
147
150
|
},
|
|
148
151
|
};
|
|
149
152
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { SyncFolderPushCommandInput, SyncFolderPushCommandOutput } from '../../meta';
|
|
2
|
+
import { PostObjectsSyncCommandOutput, SyncFolderPushCommandInput, SyncFolderPushCommandOutput } from '../../meta';
|
|
3
3
|
import { ObjectsMap, SyncFolderBaseCommand } from './sync-folder-base';
|
|
4
4
|
import type { SpaceClientOptions } from '../../protocol';
|
|
5
5
|
/**
|
|
@@ -11,10 +11,14 @@ import type { SpaceClientOptions } from '../../protocol';
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class SyncFolderPushCommand extends SyncFolderBaseCommand<SyncFolderPushCommandInput, SyncFolderPushCommandOutput> {
|
|
13
13
|
protected readonly startTime: number;
|
|
14
|
+
protected objectsSync: PostObjectsSyncCommandOutput['data'] | null;
|
|
14
15
|
constructor(input: SyncFolderPushCommandInput, context?: SpaceClientOptions);
|
|
15
|
-
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any
|
|
16
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any> | null>;
|
|
16
17
|
request(): Promise<SyncFolderPushCommandOutput>;
|
|
17
18
|
getLocalObjectsMap(): Promise<ObjectsMap>;
|
|
18
19
|
getRemoteObjectsMap(): Promise<ObjectsMap>;
|
|
20
|
+
protected retryReuqestError(error: Error): Promise<void>;
|
|
19
21
|
private sync;
|
|
22
|
+
private createObjectsSyncAuditLog;
|
|
23
|
+
private updateObjectsSyncAuditLog;
|
|
20
24
|
}
|
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SyncFolderPushCommand = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/indent */
|
|
8
|
+
const core_1 = require("@did-space/core");
|
|
7
9
|
const fs_1 = require("fs");
|
|
8
10
|
const path_1 = require("path");
|
|
9
11
|
const filehound_1 = __importDefault(require("filehound"));
|
|
@@ -18,6 +20,9 @@ const object_1 = require("../object");
|
|
|
18
20
|
const sync_folder_base_1 = require("./sync-folder-base");
|
|
19
21
|
const logger_1 = require("../../libs/logger");
|
|
20
22
|
const delete_object_1 = require("../object/delete-object");
|
|
23
|
+
const libs_1 = require("../../libs");
|
|
24
|
+
const post_objects_sync_command_1 = require("../audit-log/post-objects-sync-command");
|
|
25
|
+
const put_objects_sync_command_1 = require("../audit-log/put-objects-sync-command");
|
|
21
26
|
const { name, version } = require('../../../package.json');
|
|
22
27
|
const debug = (0, debug_1.default)(`${name}@${version}:sync-folder-push`);
|
|
23
28
|
/**
|
|
@@ -29,23 +34,42 @@ const debug = (0, debug_1.default)(`${name}@${version}:sync-folder-push`);
|
|
|
29
34
|
*/
|
|
30
35
|
class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
31
36
|
startTime = Date.now();
|
|
37
|
+
objectsSync = null;
|
|
32
38
|
constructor(input, context) {
|
|
33
39
|
super(input, context);
|
|
34
40
|
// 确保文件夹存在
|
|
35
41
|
(0, fs_extra_1.ensureDirSync)(this.input.source);
|
|
36
42
|
}
|
|
37
43
|
getAxiosRequestConfig() {
|
|
38
|
-
return null;
|
|
44
|
+
return Promise.resolve(null);
|
|
39
45
|
}
|
|
40
46
|
async request() {
|
|
41
47
|
try {
|
|
48
|
+
// @note: 备份还原的时候我们希望使用 service url 来完成,不希望走 CDN
|
|
49
|
+
this.context.endpoint = await (0, libs_1.getSpaceServiceEndpoint)(this.context.endpoint);
|
|
50
|
+
if (!this.objectsSync) {
|
|
51
|
+
this.objectsSync = await this.createObjectsSyncAuditLog();
|
|
52
|
+
}
|
|
42
53
|
const localObjectsMap = await this.getLocalObjectsMap();
|
|
43
54
|
const remoteObjectsMap = await this.getRemoteObjectsMap();
|
|
44
55
|
const waitSyncObjects = await this.getWaitSyncObjects(localObjectsMap, remoteObjectsMap);
|
|
45
56
|
const syncObjects = await this.copyObjects(waitSyncObjects);
|
|
46
57
|
debug(`[${(0, logger_1.now)()}] [waitUpload] waitUploadCount=${syncObjects.length}`);
|
|
47
58
|
debug(`[${(0, logger_1.now)()}] [context]`, { input: this.input, context: (0, pick_1.default)(this.context, ['endpoint']) });
|
|
48
|
-
|
|
59
|
+
const res = await this.sync(syncObjects);
|
|
60
|
+
if (this.objectsSync) {
|
|
61
|
+
const { errorCount, count: totalCount, duration, size } = res.data;
|
|
62
|
+
await this.updateObjectsSyncAuditLog({
|
|
63
|
+
id: this.objectsSync.id,
|
|
64
|
+
status: errorCount === 0 ? core_1.AuditLogStatus.SUCCEEDED : core_1.AuditLogStatus.FAILED,
|
|
65
|
+
reason: res.statusMessage,
|
|
66
|
+
errorCount,
|
|
67
|
+
totalCount,
|
|
68
|
+
duration,
|
|
69
|
+
size,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return res;
|
|
49
73
|
}
|
|
50
74
|
catch (error) {
|
|
51
75
|
console.error(error);
|
|
@@ -83,10 +107,24 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
83
107
|
const map = (0, keyBy_1.default)(objects, (object) => object.key);
|
|
84
108
|
return map;
|
|
85
109
|
}
|
|
110
|
+
async retryReuqestError(error) {
|
|
111
|
+
if (this.objectsSync) {
|
|
112
|
+
await this.updateObjectsSyncAuditLog({
|
|
113
|
+
id: this.objectsSync.id,
|
|
114
|
+
status: core_1.AuditLogStatus.FAILED,
|
|
115
|
+
reason: (0, libs_1.getErrorMessage)(error),
|
|
116
|
+
totalCount: 0,
|
|
117
|
+
errorCount: 0,
|
|
118
|
+
size: 0,
|
|
119
|
+
duration: 0,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
86
123
|
async sync(syncObjects) {
|
|
87
124
|
this.queue.removeAllListeners();
|
|
88
125
|
let errorCount = 0;
|
|
89
126
|
let completedCount = 0;
|
|
127
|
+
let totalSize = 0;
|
|
90
128
|
const totalCount = syncObjects.length;
|
|
91
129
|
// @ts-expect-error
|
|
92
130
|
this.queue.on('error', async () => {
|
|
@@ -117,6 +155,7 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
117
155
|
data: (0, fs_1.createReadStream)(sourceKey),
|
|
118
156
|
hash: x.hash,
|
|
119
157
|
}, this.context).request();
|
|
158
|
+
totalSize += x.size;
|
|
120
159
|
}
|
|
121
160
|
else {
|
|
122
161
|
await new delete_object_1.DeleteObjectCommand({
|
|
@@ -156,11 +195,36 @@ class SyncFolderPushCommand extends sync_folder_base_1.SyncFolderBaseCommand {
|
|
|
156
195
|
return {
|
|
157
196
|
statusCode: 200,
|
|
158
197
|
data: {
|
|
198
|
+
size: totalSize,
|
|
159
199
|
errorCount,
|
|
160
200
|
count: actions.length,
|
|
161
201
|
duration: (Date.now() - this.startTime) / 1000,
|
|
162
202
|
},
|
|
163
203
|
};
|
|
164
204
|
}
|
|
205
|
+
async createObjectsSyncAuditLog() {
|
|
206
|
+
return (await new post_objects_sync_command_1.PostObjectsSyncCommand({
|
|
207
|
+
source: this.input.source,
|
|
208
|
+
target: this.input.target,
|
|
209
|
+
metadata: this.input.metadata,
|
|
210
|
+
}, this.context).request()).data;
|
|
211
|
+
}
|
|
212
|
+
async updateObjectsSyncAuditLog(input) {
|
|
213
|
+
const { id, reason, status, errorCount, totalCount, ...rest } = input;
|
|
214
|
+
const stats = {
|
|
215
|
+
totalCount,
|
|
216
|
+
errorCount,
|
|
217
|
+
successCount: totalCount - errorCount,
|
|
218
|
+
...rest,
|
|
219
|
+
};
|
|
220
|
+
return await new put_objects_sync_command_1.PutObjectsSyncCommand({
|
|
221
|
+
id,
|
|
222
|
+
status,
|
|
223
|
+
reason,
|
|
224
|
+
...stats,
|
|
225
|
+
}, this.context)
|
|
226
|
+
.request()
|
|
227
|
+
.catch(console.error);
|
|
228
|
+
}
|
|
165
229
|
}
|
|
166
230
|
exports.SyncFolderPushCommand = SyncFolderPushCommand;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -65,7 +65,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
65
65
|
avatar: string;
|
|
66
66
|
fullname: string;
|
|
67
67
|
email: string;
|
|
68
|
-
template?: "profile";
|
|
68
|
+
template?: "profile" | undefined;
|
|
69
69
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
70
70
|
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
71
71
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -190,7 +190,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
190
190
|
image: string;
|
|
191
191
|
url: string;
|
|
192
192
|
createdAt: string;
|
|
193
|
-
description?: string;
|
|
193
|
+
description?: string | undefined;
|
|
194
194
|
}, {
|
|
195
195
|
template: "project";
|
|
196
196
|
did: string;
|
|
@@ -198,7 +198,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
198
198
|
image: string;
|
|
199
199
|
url: string;
|
|
200
200
|
createdAt: string;
|
|
201
|
-
description?: string;
|
|
201
|
+
description?: string | undefined;
|
|
202
202
|
}>]>;
|
|
203
203
|
/**
|
|
204
204
|
* @description 存储元数据
|
|
@@ -217,19 +217,20 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
217
217
|
hash: z.ZodOptional<z.ZodString>;
|
|
218
218
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
219
219
|
}, "strip", z.ZodTypeAny, {
|
|
220
|
-
key
|
|
220
|
+
key: string;
|
|
221
|
+
metadata?: Record<string, any> | undefined;
|
|
221
222
|
data?: any;
|
|
222
|
-
hash?: string;
|
|
223
|
-
metadata?: Record<string, any>;
|
|
223
|
+
hash?: string | undefined;
|
|
224
224
|
}, {
|
|
225
|
-
key
|
|
225
|
+
key: string;
|
|
226
|
+
metadata?: Record<string, any> | undefined;
|
|
226
227
|
data?: any;
|
|
227
|
-
hash?: string;
|
|
228
|
-
metadata?: Record<string, any>;
|
|
228
|
+
hash?: string | undefined;
|
|
229
229
|
}>, "many">>>;
|
|
230
230
|
}, "strip", z.ZodTypeAny, {
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
metadata: Record<string, any>;
|
|
232
|
+
key: string;
|
|
233
|
+
data: {
|
|
233
234
|
template: "app";
|
|
234
235
|
did: string;
|
|
235
236
|
name: string;
|
|
@@ -286,19 +287,18 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
286
287
|
image: string;
|
|
287
288
|
url: string;
|
|
288
289
|
createdAt: string;
|
|
289
|
-
description?: string;
|
|
290
|
+
description?: string | undefined;
|
|
290
291
|
};
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
key?: string;
|
|
292
|
+
resources: {
|
|
293
|
+
key: string;
|
|
294
|
+
metadata?: Record<string, any> | undefined;
|
|
295
295
|
data?: any;
|
|
296
|
-
hash?: string;
|
|
297
|
-
metadata?: Record<string, any>;
|
|
296
|
+
hash?: string | undefined;
|
|
298
297
|
}[];
|
|
298
|
+
hash?: string | undefined;
|
|
299
299
|
}, {
|
|
300
|
-
key
|
|
301
|
-
data
|
|
300
|
+
key: string;
|
|
301
|
+
data: {
|
|
302
302
|
template: "app";
|
|
303
303
|
did: string;
|
|
304
304
|
name: string;
|
|
@@ -314,7 +314,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
314
314
|
avatar: string;
|
|
315
315
|
fullname: string;
|
|
316
316
|
email: string;
|
|
317
|
-
template?: "profile";
|
|
317
|
+
template?: "profile" | undefined;
|
|
318
318
|
} | {
|
|
319
319
|
template: "passport";
|
|
320
320
|
type: string[];
|
|
@@ -355,16 +355,16 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
355
355
|
image: string;
|
|
356
356
|
url: string;
|
|
357
357
|
createdAt: string;
|
|
358
|
-
description?: string;
|
|
358
|
+
description?: string | undefined;
|
|
359
359
|
};
|
|
360
|
-
|
|
361
|
-
|
|
360
|
+
metadata?: Record<string, any> | undefined;
|
|
361
|
+
hash?: string | undefined;
|
|
362
362
|
resources?: {
|
|
363
|
-
key
|
|
363
|
+
key: string;
|
|
364
|
+
metadata?: Record<string, any> | undefined;
|
|
364
365
|
data?: any;
|
|
365
|
-
hash?: string;
|
|
366
|
-
|
|
367
|
-
}[];
|
|
366
|
+
hash?: string | undefined;
|
|
367
|
+
}[] | undefined;
|
|
368
368
|
}>;
|
|
369
369
|
export interface PutPreviewObjectCommandInput extends z.infer<typeof PutPreviewObjectCommandInputSchema> {
|
|
370
370
|
}
|
|
@@ -372,9 +372,9 @@ export type PutPreviewObjectCommandOutput = CommandOutput<void>;
|
|
|
372
372
|
export declare const GetPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
373
373
|
key: z.ZodString;
|
|
374
374
|
}, "strip", z.ZodTypeAny, {
|
|
375
|
-
key
|
|
375
|
+
key: string;
|
|
376
376
|
}, {
|
|
377
|
-
key
|
|
377
|
+
key: string;
|
|
378
378
|
}>;
|
|
379
379
|
export interface GetPreviewObjectCommandInput extends z.infer<typeof GetPreviewObjectCommandInputSchema> {
|
|
380
380
|
}
|
|
@@ -382,9 +382,9 @@ export type GetPreviewObjectCommandOutput = CommandOutput<PreviewTemplate>;
|
|
|
382
382
|
export declare const DeletePreviewObjectCommandInputSchema: z.ZodObject<{
|
|
383
383
|
key: z.ZodString;
|
|
384
384
|
}, "strip", z.ZodTypeAny, {
|
|
385
|
-
key
|
|
385
|
+
key: string;
|
|
386
386
|
}, {
|
|
387
|
-
key
|
|
387
|
+
key: string;
|
|
388
388
|
}>;
|
|
389
389
|
export interface DeletePreviewObjectCommandInput extends z.infer<typeof DeletePreviewObjectCommandInputSchema> {
|
|
390
390
|
}
|
|
@@ -19,15 +19,15 @@ export declare const PutObjectCommandInputSchema: z.ZodObject<{
|
|
|
19
19
|
*/
|
|
20
20
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
key
|
|
22
|
+
key: string;
|
|
23
|
+
metadata?: Record<string, any> | undefined;
|
|
23
24
|
data?: any;
|
|
24
|
-
hash?: string;
|
|
25
|
-
metadata?: Record<string, any>;
|
|
25
|
+
hash?: string | undefined;
|
|
26
26
|
}, {
|
|
27
|
-
key
|
|
27
|
+
key: string;
|
|
28
|
+
metadata?: Record<string, any> | undefined;
|
|
28
29
|
data?: any;
|
|
29
|
-
hash?: string;
|
|
30
|
-
metadata?: Record<string, any>;
|
|
30
|
+
hash?: string | undefined;
|
|
31
31
|
}>;
|
|
32
32
|
export interface PutObjectCommandInput extends z.infer<typeof PutObjectCommandInputSchema> {
|
|
33
33
|
data?: Data;
|
package/dist/meta/sync/index.js
CHANGED
|
@@ -20,3 +20,5 @@ __exportStar(require("./sync-base-command"), exports);
|
|
|
20
20
|
__exportStar(require("./sync-folder-base-command"), exports);
|
|
21
21
|
__exportStar(require("./sync-folder-pull-command"), exports);
|
|
22
22
|
__exportStar(require("./sync-folder-push-command"), exports);
|
|
23
|
+
__exportStar(require("./post-objects-sync-command"), exports);
|
|
24
|
+
__exportStar(require("./put-objects-sync-command"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuditLogModel, AuditLogAction } from '@did-space/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { CommandOutput } from '../../protocol';
|
|
4
|
+
export declare const PostObjectsSyncCommandInputSchema: z.ZodObject<{
|
|
5
|
+
source: z.ZodString;
|
|
6
|
+
target: z.ZodString;
|
|
7
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
target: string;
|
|
10
|
+
source: string;
|
|
11
|
+
metadata?: Record<string, any> | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
target: string;
|
|
14
|
+
source: string;
|
|
15
|
+
metadata?: Record<string, any> | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export interface PostObjectsSyncCommandInput extends z.infer<typeof PostObjectsSyncCommandInputSchema> {
|
|
18
|
+
}
|
|
19
|
+
export interface PostObjectsSyncCommandOutput extends CommandOutput<AuditLogModel<AuditLogAction.APP_OBJECTS_SYNC>> {
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostObjectsSyncCommandInputSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.PostObjectsSyncCommandInputSchema = zod_1.z.object({
|
|
6
|
+
source: zod_1.z.string().min(1),
|
|
7
|
+
target: zod_1.z.string().min(1),
|
|
8
|
+
metadata: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
9
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AuditLogModel, AuditLogAction, AuditLogStatus } from '@did-space/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { CommandOutput } from '../../protocol';
|
|
4
|
+
export declare const PutObjectsSyncCommandInputSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
status: z.ZodNativeEnum<typeof AuditLogStatus>;
|
|
7
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
8
|
+
totalCount: z.ZodNumber;
|
|
9
|
+
errorCount: z.ZodNumber;
|
|
10
|
+
successCount: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
size: z.ZodNumber;
|
|
12
|
+
duration: z.ZodNumber;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
id: string;
|
|
15
|
+
status: AuditLogStatus;
|
|
16
|
+
totalCount: number;
|
|
17
|
+
errorCount: number;
|
|
18
|
+
size: number;
|
|
19
|
+
duration: number;
|
|
20
|
+
reason?: string | undefined;
|
|
21
|
+
successCount?: number | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
id: string;
|
|
24
|
+
status: AuditLogStatus;
|
|
25
|
+
totalCount: number;
|
|
26
|
+
errorCount: number;
|
|
27
|
+
size: number;
|
|
28
|
+
duration: number;
|
|
29
|
+
reason?: string | undefined;
|
|
30
|
+
successCount?: number | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export interface PutObjectsSyncCommandInput extends z.infer<typeof PutObjectsSyncCommandInputSchema> {
|
|
33
|
+
}
|
|
34
|
+
export interface PutObjectsSyncCommandOutput extends CommandOutput<AuditLogModel<AuditLogAction.APP_OBJECTS_SYNC>> {
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PutObjectsSyncCommandInputSchema = void 0;
|
|
4
|
+
const core_1 = require("@did-space/core");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.PutObjectsSyncCommandInputSchema = zod_1.z.object({
|
|
7
|
+
id: zod_1.z.string().min(1),
|
|
8
|
+
status: zod_1.z.nativeEnum(core_1.AuditLogStatus),
|
|
9
|
+
reason: zod_1.z.string().optional(),
|
|
10
|
+
totalCount: zod_1.z.number(),
|
|
11
|
+
errorCount: zod_1.z.number(),
|
|
12
|
+
successCount: zod_1.z.number().optional(),
|
|
13
|
+
size: zod_1.z.number(),
|
|
14
|
+
duration: zod_1.z.number(),
|
|
15
|
+
});
|
|
@@ -116,6 +116,12 @@ export interface SyncBaseCommandOutputData {
|
|
|
116
116
|
* @memberof SyncFolderBaseCommandOutput
|
|
117
117
|
*/
|
|
118
118
|
duration: number;
|
|
119
|
+
/**
|
|
120
|
+
* @description 通过网络传输的对象大小
|
|
121
|
+
* @type {number}
|
|
122
|
+
* @memberof SyncFolderBaseCommandOutput
|
|
123
|
+
*/
|
|
124
|
+
size: number;
|
|
119
125
|
}
|
|
120
126
|
export interface SyncBaseCommandOutput extends CommandOutput<SyncBaseCommandOutputData> {
|
|
121
127
|
}
|
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.11",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"link": "yarn link"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@arcblock/did": "^1.19.
|
|
33
|
-
"@arcblock/jwt": "^1.19.
|
|
34
|
-
"@arcblock/validator": "^1.19.
|
|
35
|
-
"@blocklet/env": "^1.16.38
|
|
36
|
-
"@did-space/core": "^1.0.
|
|
37
|
-
"@ocap/mcrypto": "^1.19.
|
|
38
|
-
"@ocap/util": "^1.19.
|
|
39
|
-
"@ocap/wallet": "^1.19.
|
|
32
|
+
"@arcblock/did": "^1.19.9",
|
|
33
|
+
"@arcblock/jwt": "^1.19.9",
|
|
34
|
+
"@arcblock/validator": "^1.19.9",
|
|
35
|
+
"@blocklet/env": "^1.16.38",
|
|
36
|
+
"@did-space/core": "^1.0.11",
|
|
37
|
+
"@ocap/mcrypto": "^1.19.9",
|
|
38
|
+
"@ocap/util": "^1.19.9",
|
|
39
|
+
"@ocap/wallet": "^1.19.9",
|
|
40
40
|
"agentkeepalive": "^4.6.0",
|
|
41
41
|
"axios": "^1.7.9",
|
|
42
42
|
"base64-url": "^2.3.3",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"@types/fs-extra": "^9.0.13",
|
|
65
65
|
"@types/jest": "^28.1.8",
|
|
66
66
|
"@types/js-yaml": "^4.0.9",
|
|
67
|
-
"@types/json-stable-stringify": "^1.
|
|
68
|
-
"@types/lodash": "^4.17.14",
|
|
67
|
+
"@types/json-stable-stringify": "^1.2.0",
|
|
69
68
|
"@types/mime-types": "^2.1.4",
|
|
70
69
|
"@types/node": "18.19.31",
|
|
71
70
|
"@types/valid-url": "^1.0.7",
|
|
72
71
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
73
72
|
"eslint": "^8.57.1",
|
|
73
|
+
"express": "^4.21.2",
|
|
74
74
|
"jest": "^28.1.3",
|
|
75
75
|
"lint-staged": "^13.3.0",
|
|
76
76
|
"ts-jest": "^28.0.8",
|
|
77
77
|
"typescript": "^4.9.5"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "a6ef4e989848b33ea26c84fe0d93109587143d34"
|
|
80
80
|
}
|