SyncFolderPullCommand
该接口用于将 DID Space 上的文件夹同步到本地文件夹。
参数类型#
参数名称 | 类型 | 必要 | 默认值 | 参数说明 |
---|---|---|---|---|
source | string | Y | - | 需要被同步的源文件夹,文件夹请添加尾杠 / |
target | string | Y | - | 将源同步到目标文件夹,文件夹请添加尾杠 / |
concurrency | number | N | 256 | 并发数,默认为 256 |
retryCount | number | N | 3 | 同步失败后重试次数,默认重试 3 次 |
debug | boolean | N | false | 是否输出 debug 信息 |
filter | function | N | 默认同步所有文件 | 过滤函数,可用于过滤掉某些目录或文件 |
onProgress | function | N | - | 进度回调函数 |
onAfterUpload | function | N | - | 上传完成后回调函数 |
tmpDir | string | N | - | 临时存放文件的目录 |
返回类型:#
字段名称 | 类型 | 必要 | 参数说明 |
statusCode | number | Y | 返回状态码 |
---|---|---|---|
statusMessage | string | N | 一般来说,发生错误的时候才会有值 |
stack | string | N | 堆栈信息 |
data.errorCount | number | Y | 发生错误的任务数 |
data.count | number | Y | 总任务数 |
data.duration | number | Y | 花费的时间,单位秒(s) |
代码示例:#
- 同步 DID Spaces 的文件夹到本地
const { SpaceClient, SyncFolderPullCommand } = require('@blocklet/did-space-js');
const getWallet = require('@blocklet/sdk/lib/wallet');
const spaceClient = new SpaceClient({
endpoint,
wallet: getWallet(),
});
const syncFolderPullCommand = new SyncFolderPullCommand({
source: 'your_did_spaces/source_folder/',
target: 'target_folder/',
concurrency: 100,
retryCount: 2,
debug: true,
filter: (object, index, objects) => {
// filter logic here
},
onProgress: (input) => {
// progress callback logic here
},
onAfterUpload: (input) => {
// after upload callback logic here
},
tmpDir: 'temp/'
});
const result = await spaceClient.send(syncFolderPullCommand);