@ackplus/nest-file-storage 0.0.2
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/LICENSE +21 -0
- package/README.md +409 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +5 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/file-storage.service.d.ts +8 -0
- package/dist/lib/file-storage.service.d.ts.map +1 -0
- package/dist/lib/file-storage.service.js +30 -0
- package/dist/lib/file-storage.service.js.map +1 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +22 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/interceptor/file-storage.interceptor.d.ts +25 -0
- package/dist/lib/interceptor/file-storage.interceptor.d.ts.map +1 -0
- package/dist/lib/interceptor/file-storage.interceptor.js +141 -0
- package/dist/lib/interceptor/file-storage.interceptor.js.map +1 -0
- package/dist/lib/nest-file-storage.module.d.ts +9 -0
- package/dist/lib/nest-file-storage.module.d.ts.map +1 -0
- package/dist/lib/nest-file-storage.module.js +80 -0
- package/dist/lib/nest-file-storage.module.js.map +1 -0
- package/dist/lib/storage/azure.storage.d.ts +19 -0
- package/dist/lib/storage/azure.storage.d.ts.map +1 -0
- package/dist/lib/storage/azure.storage.js +189 -0
- package/dist/lib/storage/azure.storage.js.map +1 -0
- package/dist/lib/storage/local.storage.d.ts +35 -0
- package/dist/lib/storage/local.storage.d.ts.map +1 -0
- package/dist/lib/storage/local.storage.js +219 -0
- package/dist/lib/storage/local.storage.js.map +1 -0
- package/dist/lib/storage/s3.storage.d.ts +20 -0
- package/dist/lib/storage/s3.storage.d.ts.map +1 -0
- package/dist/lib/storage/s3.storage.js +231 -0
- package/dist/lib/storage/s3.storage.js.map +1 -0
- package/dist/lib/storage.factory.d.ts +9 -0
- package/dist/lib/storage.factory.d.ts.map +1 -0
- package/dist/lib/storage.factory.js +82 -0
- package/dist/lib/storage.factory.js.map +1 -0
- package/dist/lib/types.d.ts +91 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +10 -0
- package/dist/lib/types.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
import { Request } from 'express';
|
|
3
|
+
export declare enum FileStorageEnum {
|
|
4
|
+
LOCAL = "local",
|
|
5
|
+
S3 = "s3",
|
|
6
|
+
AZURE = "azure"
|
|
7
|
+
}
|
|
8
|
+
export interface FileStorageOptions {
|
|
9
|
+
prefix?: string;
|
|
10
|
+
fileName?: (file: any, req: Request) => string;
|
|
11
|
+
fileDist?: (file: any, req: Request) => string;
|
|
12
|
+
transformUploadedFileObject?: (file: any) => any;
|
|
13
|
+
}
|
|
14
|
+
export interface S3StorageOptions extends FileStorageOptions {
|
|
15
|
+
accessKeyId: string;
|
|
16
|
+
secretAccessKey: string;
|
|
17
|
+
region: string;
|
|
18
|
+
bucket: string;
|
|
19
|
+
endpoint?: string;
|
|
20
|
+
cloudFrontUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface LocalStorageOptions extends FileStorageOptions {
|
|
23
|
+
rootPath: string;
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
}
|
|
26
|
+
export interface AzureStorageOptions extends FileStorageOptions {
|
|
27
|
+
account: string;
|
|
28
|
+
accountKey: string;
|
|
29
|
+
container: string;
|
|
30
|
+
}
|
|
31
|
+
export type StorageOptions = S3StorageOptions | AzureStorageOptions | LocalStorageOptions;
|
|
32
|
+
export type FileStorageConfigOptions = {
|
|
33
|
+
storage: FileStorageEnum.LOCAL;
|
|
34
|
+
localConfig: LocalStorageOptions;
|
|
35
|
+
} | {
|
|
36
|
+
storage: FileStorageEnum.S3;
|
|
37
|
+
s3Config: S3StorageOptions;
|
|
38
|
+
} | {
|
|
39
|
+
storage: FileStorageEnum.AZURE;
|
|
40
|
+
azureConfig: AzureStorageOptions;
|
|
41
|
+
};
|
|
42
|
+
export interface FileStorageClassOptions {
|
|
43
|
+
storageFactory: () => Promise<new (...args: any[]) => Storage> | (new (...args: any[]) => Storage);
|
|
44
|
+
options?: any;
|
|
45
|
+
}
|
|
46
|
+
export type FileStorageModuleOptions = FileStorageConfigOptions | FileStorageClassOptions;
|
|
47
|
+
export interface FileStorageAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
48
|
+
/**
|
|
49
|
+
* The `useExisting` syntax allows you to create aliases for existing providers.
|
|
50
|
+
*/
|
|
51
|
+
useExisting?: Type<FileStorageOptionsFactory>;
|
|
52
|
+
/**
|
|
53
|
+
* The `useClass` syntax allows you to dynamically determine a class
|
|
54
|
+
* that a token should resolve to.
|
|
55
|
+
*/
|
|
56
|
+
useClass?: Type<FileStorageOptionsFactory>;
|
|
57
|
+
/**
|
|
58
|
+
* The `useFactory` syntax allows for creating providers dynamically.
|
|
59
|
+
*/
|
|
60
|
+
useFactory?: (...args: any[]) => Promise<FileStorageModuleOptions> | FileStorageModuleOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Optional list of providers to be injected into the context of the Factory function.
|
|
63
|
+
*/
|
|
64
|
+
inject?: any[];
|
|
65
|
+
}
|
|
66
|
+
export interface FileStorageOptionsFactory {
|
|
67
|
+
createFileStorageOptions(): Promise<FileStorageModuleOptions> | FileStorageModuleOptions;
|
|
68
|
+
}
|
|
69
|
+
export interface UploadedFile {
|
|
70
|
+
fieldName?: string;
|
|
71
|
+
fieldname?: string;
|
|
72
|
+
fileName: string;
|
|
73
|
+
originalName: string;
|
|
74
|
+
size: number;
|
|
75
|
+
mimetype?: string;
|
|
76
|
+
buffer?: Buffer;
|
|
77
|
+
key: string;
|
|
78
|
+
url: string;
|
|
79
|
+
fullPath: string;
|
|
80
|
+
encoding?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface Storage {
|
|
83
|
+
getFile(key: string): Promise<Buffer> | Buffer;
|
|
84
|
+
deleteFile(key: string): Promise<void> | void;
|
|
85
|
+
putFile(fileContent: Buffer, key: string): Promise<UploadedFile> | UploadedFile;
|
|
86
|
+
path?(filePath: string): Promise<string> | string;
|
|
87
|
+
getUrl(key: string): Promise<string> | string;
|
|
88
|
+
getSignedUrl?(key: string, options: any): Promise<string> | string;
|
|
89
|
+
copyFile(oldKey: string, newKey: string): Promise<UploadedFile>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,oBAAY,eAAe;IACvB,KAAK,UAAU;IACf,EAAE,OAAO;IACT,KAAK,UAAU;CAClB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;IAC/C,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;IAC/C,2BAA2B,CAAC,EAAE,CAAC,IAAI,KAAA,KAAK,GAAG,CAAC;CAC/C;AAED,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IACxD,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED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AAO,CAAC,YAAY,CAAC,CAAA;CAClE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileStorageEnum = void 0;
|
|
4
|
+
var FileStorageEnum;
|
|
5
|
+
(function (FileStorageEnum) {
|
|
6
|
+
FileStorageEnum["LOCAL"] = "local";
|
|
7
|
+
FileStorageEnum["S3"] = "s3";
|
|
8
|
+
FileStorageEnum["AZURE"] = "azure";
|
|
9
|
+
})(FileStorageEnum || (exports.FileStorageEnum = FileStorageEnum = {}));
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":";;;AAIA,IAAY,eAIX;AAJD,WAAY,eAAe;IACvB,kCAAe,CAAA;IACf,4BAAS,CAAA;IACT,kCAAe,CAAA;AACnB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ackplus/nest-file-storage",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/ack-solutions/packages.git"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/ack-solutions/packages.git#readme",
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"typeorm": "^0.3.23",
|
|
21
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
22
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
23
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
24
|
+
"@azure/storage-blob": "^12.0.0",
|
|
25
|
+
"@aws-sdk/client-s3": "^3.0.0",
|
|
26
|
+
"@aws-sdk/s3-request-presigner": "^3.0.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"@azure/storage-blob": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"@aws-sdk/client-s3": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"@aws-sdk/s3-request-presigner": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"typeorm": "^0.3.23",
|
|
41
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
42
|
+
"@nestjs/common": "^11.1.3",
|
|
43
|
+
"@nestjs/core": "^11.1.3",
|
|
44
|
+
"@types/multer": "^2.0.0",
|
|
45
|
+
"@types/node": "^20.0.0",
|
|
46
|
+
"@types/uuid": "^9.0.0",
|
|
47
|
+
"@types/concat-stream": "^2.0.0"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"tslib": "^2.3.0",
|
|
51
|
+
"deepmerge": "4.3.1",
|
|
52
|
+
"class-transformer": "^0.5.1",
|
|
53
|
+
"class-validator": "^0.14.1",
|
|
54
|
+
"pluralize": "8.0.0",
|
|
55
|
+
"lodash": "^4.17.21",
|
|
56
|
+
"rxjs": "^7.8.0",
|
|
57
|
+
"multer": "^2.0.1",
|
|
58
|
+
"moment": "^2.30.1",
|
|
59
|
+
"uuid": "^9.0.0",
|
|
60
|
+
"concat-stream": "^2.0.0"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "pnpm run clean && tsc -p tsconfig.lib.json",
|
|
64
|
+
"clean": "rimraf dist",
|
|
65
|
+
"dev": "tsc -p tsconfig.lib.json --watch --preserveWatchOutput"
|
|
66
|
+
}
|
|
67
|
+
}
|