document-drive 0.0.17 → 0.0.19
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 +16 -17
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { DocumentDriveDocument } from 'document-model-libs/document-drive';
|
|
2
2
|
import { Document } from 'document-model/document';
|
|
3
3
|
import type { Dirent } from 'fs';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
writeFileSync
|
|
10
|
+
} from 'fs';
|
|
5
11
|
import fs from 'fs/promises';
|
|
6
12
|
import path from 'path';
|
|
7
13
|
import sanitize from 'sanitize-filename';
|
|
@@ -46,7 +52,7 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
46
52
|
async getDocuments(drive: string) {
|
|
47
53
|
let files: Dirent[] = [];
|
|
48
54
|
try {
|
|
49
|
-
files =
|
|
55
|
+
files = readdirSync(path.join(this.basePath, drive), {
|
|
50
56
|
withFileTypes: true
|
|
51
57
|
});
|
|
52
58
|
} catch (error) {
|
|
@@ -72,10 +78,9 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
72
78
|
|
|
73
79
|
async getDocument(drive: string, id: string) {
|
|
74
80
|
try {
|
|
75
|
-
const content =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
81
|
+
const content = readFileSync(this._buildDocumentPath(drive, id), {
|
|
82
|
+
encoding: 'utf-8'
|
|
83
|
+
});
|
|
79
84
|
return JSON.parse(content);
|
|
80
85
|
} catch (error) {
|
|
81
86
|
console.error(error);
|
|
@@ -85,16 +90,10 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
85
90
|
|
|
86
91
|
async saveDocument(drive: string, id: string, document: Document) {
|
|
87
92
|
const documentPath = this._buildDocumentPath(drive, id);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
await fs.writeFile(handle, JSON.stringify(document), {
|
|
93
|
-
encoding: 'utf-8'
|
|
94
|
-
});
|
|
95
|
-
} finally {
|
|
96
|
-
await handle?.close();
|
|
97
|
-
}
|
|
93
|
+
await ensureDir(path.dirname(documentPath));
|
|
94
|
+
await writeFileSync(documentPath, JSON.stringify(document), {
|
|
95
|
+
encoding: 'utf-8'
|
|
96
|
+
});
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
async deleteDocument(drive: string, id: string) {
|
|
@@ -102,7 +101,7 @@ export class FilesystemStorage implements IDriveStorage {
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
async getDrives() {
|
|
105
|
-
const files = await
|
|
104
|
+
const files = await readdirSync(this.drivesPath, {
|
|
106
105
|
withFileTypes: true
|
|
107
106
|
});
|
|
108
107
|
const drives: string[] = [];
|