@maioradv/nestjs-core 1.2.5 → 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.
package/dist/providers/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./crypt.service"), exports);
|
|
18
18
|
__exportStar(require("./s3.service"), exports);
|
|
19
19
|
__exportStar(require("./accounts.service"), exports);
|
|
20
|
+
__exportStar(require("./storage.service"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import { Stats } from 'fs';
|
|
6
|
+
import internal from 'stream';
|
|
7
|
+
export declare class StorageService {
|
|
8
|
+
rootPath: string;
|
|
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;
|
|
16
|
+
private safeDirectory;
|
|
17
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.StorageService = void 0;
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const os_1 = require("os");
|
|
13
|
+
const path_helper_1 = require("../utils/path.helper");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
let StorageService = class StorageService {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.rootPath = (0, path_helper_1.joinFromRoot)('public');
|
|
18
|
+
this.useRealPath = false;
|
|
19
|
+
}
|
|
20
|
+
async read(relativePath) {
|
|
21
|
+
const realPath = this.realPath(relativePath);
|
|
22
|
+
return await fs_1.promises.readFile(realPath, {});
|
|
23
|
+
}
|
|
24
|
+
async write(relativePath, data) {
|
|
25
|
+
const realPath = this.realPath(relativePath);
|
|
26
|
+
await this.safeDirectory(realPath);
|
|
27
|
+
return await fs_1.promises.writeFile(realPath, data, 'utf8');
|
|
28
|
+
}
|
|
29
|
+
async append(relativePath, data) {
|
|
30
|
+
const realPath = this.realPath(relativePath);
|
|
31
|
+
await this.safeDirectory(realPath);
|
|
32
|
+
return await fs_1.promises.appendFile(realPath, data + os_1.EOL);
|
|
33
|
+
}
|
|
34
|
+
async delete(relativePath) {
|
|
35
|
+
const realPath = this.realPath(relativePath);
|
|
36
|
+
try {
|
|
37
|
+
return await fs_1.promises.unlink(realPath);
|
|
38
|
+
}
|
|
39
|
+
catch (e) { }
|
|
40
|
+
}
|
|
41
|
+
async stat(relativePath) {
|
|
42
|
+
const realPath = this.realPath(relativePath);
|
|
43
|
+
return fs_1.promises.stat(realPath);
|
|
44
|
+
}
|
|
45
|
+
realPath(relativePath) {
|
|
46
|
+
return this.useRealPath ? relativePath : (0, path_1.join)(this.rootPath, relativePath);
|
|
47
|
+
}
|
|
48
|
+
async safeDirectory(path) {
|
|
49
|
+
const dirPath = (0, path_1.dirname)(path);
|
|
50
|
+
try {
|
|
51
|
+
await fs_1.promises.stat(dirPath);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
await fs_1.promises.mkdir(dirPath, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.StorageService = StorageService;
|
|
59
|
+
exports.StorageService = StorageService = __decorate([
|
|
60
|
+
(0, common_1.Injectable)()
|
|
61
|
+
], StorageService);
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./chunk.helper"), exports);
|
|
18
18
|
__exportStar(require("./path.helper"), exports);
|
|
19
19
|
__exportStar(require("./slug.helper"), exports);
|
|
20
|
-
__exportStar(require("./storage.helper"), exports);
|
|
21
20
|
__exportStar(require("./types.helper"), exports);
|
|
22
21
|
__exportStar(require("./time.helper"), exports);
|
|
23
22
|
__exportStar(require("./image.helper"), exports);
|