@maioradv/nestjs-core 1.2.6 → 1.2.7
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.
|
@@ -6,10 +6,12 @@ import { Stats } from 'fs';
|
|
|
6
6
|
import internal from 'stream';
|
|
7
7
|
export declare class StorageService {
|
|
8
8
|
rootPath: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
useRealPath: boolean;
|
|
10
|
+
read(relativePath: string): Promise<Buffer>;
|
|
11
|
+
write(relativePath: string, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | internal.Stream): Promise<void>;
|
|
12
|
+
append(relativePath: string, data: string | Uint8Array): Promise<void>;
|
|
13
|
+
delete(relativePath: string): Promise<void>;
|
|
14
|
+
stat(relativePath: string): Promise<Stats>;
|
|
15
|
+
private realPath;
|
|
14
16
|
private safeDirectory;
|
|
15
17
|
}
|
|
@@ -15,32 +15,36 @@ const common_1 = require("@nestjs/common");
|
|
|
15
15
|
let StorageService = class StorageService {
|
|
16
16
|
constructor() {
|
|
17
17
|
this.rootPath = (0, path_helper_1.joinFromRoot)('public');
|
|
18
|
+
this.useRealPath = false;
|
|
18
19
|
}
|
|
19
|
-
async read(
|
|
20
|
-
const realPath =
|
|
20
|
+
async read(relativePath) {
|
|
21
|
+
const realPath = this.realPath(relativePath);
|
|
21
22
|
return await fs_1.promises.readFile(realPath, {});
|
|
22
23
|
}
|
|
23
|
-
async write(
|
|
24
|
-
const realPath =
|
|
24
|
+
async write(relativePath, data) {
|
|
25
|
+
const realPath = this.realPath(relativePath);
|
|
25
26
|
await this.safeDirectory(realPath);
|
|
26
27
|
return await fs_1.promises.writeFile(realPath, data, 'utf8');
|
|
27
28
|
}
|
|
28
|
-
async append(
|
|
29
|
-
const realPath =
|
|
29
|
+
async append(relativePath, data) {
|
|
30
|
+
const realPath = this.realPath(relativePath);
|
|
30
31
|
await this.safeDirectory(realPath);
|
|
31
32
|
return await fs_1.promises.appendFile(realPath, data + os_1.EOL);
|
|
32
33
|
}
|
|
33
|
-
async delete(
|
|
34
|
-
const realPath =
|
|
34
|
+
async delete(relativePath) {
|
|
35
|
+
const realPath = this.realPath(relativePath);
|
|
35
36
|
try {
|
|
36
37
|
return await fs_1.promises.unlink(realPath);
|
|
37
38
|
}
|
|
38
39
|
catch (e) { }
|
|
39
40
|
}
|
|
40
|
-
async stat(
|
|
41
|
-
const realPath =
|
|
41
|
+
async stat(relativePath) {
|
|
42
|
+
const realPath = this.realPath(relativePath);
|
|
42
43
|
return fs_1.promises.stat(realPath);
|
|
43
44
|
}
|
|
45
|
+
realPath(relativePath) {
|
|
46
|
+
return this.useRealPath ? relativePath : (0, path_1.join)(this.rootPath, relativePath);
|
|
47
|
+
}
|
|
44
48
|
async safeDirectory(path) {
|
|
45
49
|
const dirPath = (0, path_1.dirname)(path);
|
|
46
50
|
try {
|