document-drive 0.0.2 → 0.0.3
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/package.json +1 -1
- package/src/storage/filesystem.ts +19 -3
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DocumentDriveDocument } from 'document-model-libs/document-drive';
|
|
2
2
|
import { Document } from 'document-model/document';
|
|
3
|
+
import type { Dirent } from 'fs';
|
|
3
4
|
import { existsSync, mkdirSync } from 'fs';
|
|
4
5
|
import fs from 'fs/promises';
|
|
5
6
|
|
|
@@ -14,6 +15,13 @@ function ensureDir(dir: string) {
|
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
type FSError = {
|
|
19
|
+
errno: number;
|
|
20
|
+
code: string;
|
|
21
|
+
syscall: string;
|
|
22
|
+
path: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
17
25
|
export class FilesystemStorage implements IDriveStorage {
|
|
18
26
|
private basePath: string;
|
|
19
27
|
private drivesPath: string;
|
|
@@ -37,9 +45,17 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
async getDocuments(drive: string) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
let files: Dirent[] = [];
|
|
49
|
+
try {
|
|
50
|
+
files = await fs.readdir(path.join(this.basePath, drive), {
|
|
51
|
+
withFileTypes: true
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
// if folder is not found then drive has no documents
|
|
55
|
+
if ((error as FSError).code !== 'ENOENT') {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
43
59
|
const documents: string[] = [];
|
|
44
60
|
for (const file of files.filter(file => file.isFile())) {
|
|
45
61
|
try {
|