@did-space/fs-driver 0.2.116 → 0.2.118
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/config/index.js +4 -12
- package/dist/operator/index.js +48 -58
- package/package.json +4 -4
package/dist/config/index.js
CHANGED
|
@@ -36,9 +36,7 @@ class FsSpaceConfig {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
destroyConfig() {
|
|
39
|
-
return
|
|
40
|
-
return fs_extra_1.default.remove(this.key);
|
|
41
|
-
});
|
|
39
|
+
return fs_extra_1.default.remove(this.key);
|
|
42
40
|
}
|
|
43
41
|
// FIXME: @yejianchao 待实现,可以把key对应的Value的类型也带出来?我想到了一种方法,但是我觉得太粗糙了
|
|
44
42
|
set(key, value) {
|
|
@@ -85,19 +83,13 @@ class FsSpaceConfig {
|
|
|
85
83
|
});
|
|
86
84
|
}
|
|
87
85
|
setListable(options, status) {
|
|
88
|
-
return
|
|
89
|
-
return this.setPermission(options, core_1.Scopes['list:object'], status);
|
|
90
|
-
});
|
|
86
|
+
return this.setPermission(options, core_1.Scopes['list:object'], status);
|
|
91
87
|
}
|
|
92
88
|
setReadable(options, status) {
|
|
93
|
-
return
|
|
94
|
-
return this.setPermission(options, core_1.Scopes['read:object'], status);
|
|
95
|
-
});
|
|
89
|
+
return this.setPermission(options, core_1.Scopes['read:object'], status);
|
|
96
90
|
}
|
|
97
91
|
setWritable(options, status) {
|
|
98
|
-
return
|
|
99
|
-
return this.setPermission(options, core_1.Scopes['write:object'], status);
|
|
100
|
-
});
|
|
92
|
+
return this.setPermission(options, core_1.Scopes['write:object'], status);
|
|
101
93
|
}
|
|
102
94
|
isListable(options) {
|
|
103
95
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/operator/index.js
CHANGED
|
@@ -29,19 +29,14 @@ class FsSpaceOperator {
|
|
|
29
29
|
}
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
31
|
createSpace(_spaceConfig) {
|
|
32
|
-
return
|
|
33
|
-
return fs_extra_1.default.ensureDir(this.options.root);
|
|
34
|
-
});
|
|
32
|
+
return fs_extra_1.default.ensureDir(this.options.root);
|
|
35
33
|
}
|
|
36
34
|
destroySpace() {
|
|
37
|
-
return
|
|
38
|
-
return fs_extra_1.default.remove(this.options.root);
|
|
39
|
-
});
|
|
35
|
+
return fs_extra_1.default.remove(this.options.root);
|
|
40
36
|
}
|
|
41
37
|
isSpaceCreated() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
38
|
+
// @ts-expect-error
|
|
39
|
+
return fs_extra_1.default.existsSync(this.options.root);
|
|
45
40
|
}
|
|
46
41
|
getSpaceSize() {
|
|
47
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -50,23 +45,22 @@ class FsSpaceOperator {
|
|
|
50
45
|
});
|
|
51
46
|
}
|
|
52
47
|
getPathStatus(path) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
48
|
+
const files = filehound_1.default.create()
|
|
49
|
+
.paths(path)
|
|
50
|
+
.includeFileStats()
|
|
51
|
+
.findSync();
|
|
52
|
+
const pathStatus = files.reduce((_pathStatus, file) => {
|
|
53
|
+
_pathStatus.size += file.stats.size;
|
|
54
|
+
_pathStatus.objects++;
|
|
55
|
+
_pathStatus.lastModified = Math.max(new Date(file.stats.mtime).getTime(), _pathStatus.lastModified);
|
|
56
|
+
return _pathStatus;
|
|
57
|
+
}, {
|
|
58
|
+
size: 0,
|
|
59
|
+
objects: 0,
|
|
60
|
+
lastModified: 0,
|
|
61
|
+
});
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
return pathStatus;
|
|
70
64
|
}
|
|
71
65
|
createAppSpace(options) {
|
|
72
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -79,9 +73,8 @@ class FsSpaceOperator {
|
|
|
79
73
|
});
|
|
80
74
|
}
|
|
81
75
|
getAppSpacePath(options) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
76
|
+
// @ts-expect-error
|
|
77
|
+
return (0, path_1.join)(this.options.root, FsSpaceOperator.APPS, options.appDid);
|
|
85
78
|
}
|
|
86
79
|
getObjectKey(options) {
|
|
87
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -143,6 +136,9 @@ class FsSpaceOperator {
|
|
|
143
136
|
lists(options) {
|
|
144
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
138
|
const path = (0, path_1.join)(this.options.root, options.key);
|
|
139
|
+
if (!(yield this.existsAsOwner(options.key))) {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
146
142
|
// 以 非递归的方式 && 显示文件夹 的方式列出当前文件
|
|
147
143
|
if (!options.recursive) {
|
|
148
144
|
const objectNames = fs_extra_1.default.readdirSync(path);
|
|
@@ -193,25 +189,24 @@ class FsSpaceOperator {
|
|
|
193
189
|
});
|
|
194
190
|
}
|
|
195
191
|
list(options) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
});
|
|
192
|
+
const objectKey = (0, path_1.join)(this.options.root, options.key);
|
|
193
|
+
if (!fs_extra_1.default.existsSync(objectKey)) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const fileStat = fs_extra_1.default.statSync(objectKey);
|
|
197
|
+
const objectName = (0, path_1.basename)(objectKey);
|
|
198
|
+
const directorySuffixes = fileStat.isDirectory() ? '/' : '';
|
|
199
|
+
const key = (0, path_1.join)(options.key, directorySuffixes);
|
|
200
|
+
return {
|
|
201
|
+
// @ts-expect-error
|
|
202
|
+
key,
|
|
203
|
+
name: (0, path_1.join)(objectName, directorySuffixes),
|
|
204
|
+
isDir: fileStat.isDirectory(),
|
|
205
|
+
size: fileStat.size,
|
|
206
|
+
lastModified: new Date(fileStat.mtime).getTime(),
|
|
207
|
+
editable: core_1.Space.editable(key),
|
|
208
|
+
mimeType: mime_types_1.default.lookup(objectName) || 'unknown',
|
|
209
|
+
};
|
|
215
210
|
}
|
|
216
211
|
writeAsOwner(key, data) {
|
|
217
212
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -233,20 +228,15 @@ class FsSpaceOperator {
|
|
|
233
228
|
});
|
|
234
229
|
}
|
|
235
230
|
deleteAsOwner(key) {
|
|
236
|
-
return
|
|
237
|
-
return fs_extra_1.default.remove((0, path_1.join)(this.options.root, key));
|
|
238
|
-
});
|
|
231
|
+
return fs_extra_1.default.remove((0, path_1.join)(this.options.root, key));
|
|
239
232
|
}
|
|
240
233
|
readAsOwner(key) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return fs_extra_1.default.readFile((0, path_1.join)(this.options.root, key)).then((data) => stream_1.Readable.from(data));
|
|
244
|
-
});
|
|
234
|
+
// FIXME: @yejianchao 应该可以refactor,但是我还需要测试一下
|
|
235
|
+
return fs_extra_1.default.readFile((0, path_1.join)(this.options.root, key)).then((data) => stream_1.Readable.from(data));
|
|
245
236
|
}
|
|
246
237
|
existsAsOwner(key) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
});
|
|
238
|
+
// @ts-expect-error
|
|
239
|
+
return fs_extra_1.default.existsSync((0, path_1.join)(this.options.root, key));
|
|
250
240
|
}
|
|
251
241
|
}
|
|
252
242
|
exports.FsSpaceOperator = FsSpaceOperator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-space/fs-driver",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.118",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
]
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@did-space/core": "0.2.
|
|
35
|
+
"@did-space/core": "0.2.118",
|
|
36
36
|
"filehound": "^1.17.6",
|
|
37
37
|
"fs-extra": "^10.1.0",
|
|
38
38
|
"hasha": "^5.2.2",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"url-join": "4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@arcblock/eslint-config-ts": "^0.2.
|
|
45
|
+
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
46
46
|
"@types/fs-extra": "^9.0.13",
|
|
47
47
|
"@types/jest": "^28.1.5",
|
|
48
48
|
"@types/js-yaml": "^4.0.5",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"ts-jest": "^28.0.6",
|
|
56
56
|
"typescript": "^4.9.5"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "ae24b656fb484cb1147c3bccce6d4c8f956e7c30"
|
|
59
59
|
}
|