1 | "use strict";
|
2 | var MulterModule_1;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.MulterModule = void 0;
|
5 | const tslib_1 = require("tslib");
|
6 | const common_1 = require("@nestjs/common");
|
7 | const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
8 | const files_constants_1 = require("./files.constants");
|
9 | const multer_constants_1 = require("./multer.constants");
|
10 |
|
11 |
|
12 |
|
13 | let MulterModule = exports.MulterModule = MulterModule_1 = class MulterModule {
|
14 | static register(options = {}) {
|
15 | return {
|
16 | module: MulterModule_1,
|
17 | providers: [
|
18 | { provide: files_constants_1.MULTER_MODULE_OPTIONS, useValue: options },
|
19 | {
|
20 | provide: multer_constants_1.MULTER_MODULE_ID,
|
21 | useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
|
22 | },
|
23 | ],
|
24 | exports: [files_constants_1.MULTER_MODULE_OPTIONS],
|
25 | };
|
26 | }
|
27 | static registerAsync(options) {
|
28 | return {
|
29 | module: MulterModule_1,
|
30 | imports: options.imports,
|
31 | providers: [
|
32 | ...this.createAsyncProviders(options),
|
33 | {
|
34 | provide: multer_constants_1.MULTER_MODULE_ID,
|
35 | useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
|
36 | },
|
37 | ],
|
38 | exports: [files_constants_1.MULTER_MODULE_OPTIONS],
|
39 | };
|
40 | }
|
41 | static createAsyncProviders(options) {
|
42 | if (options.useExisting || options.useFactory) {
|
43 | return [this.createAsyncOptionsProvider(options)];
|
44 | }
|
45 | return [
|
46 | this.createAsyncOptionsProvider(options),
|
47 | {
|
48 | provide: options.useClass,
|
49 | useClass: options.useClass,
|
50 | },
|
51 | ];
|
52 | }
|
53 | static createAsyncOptionsProvider(options) {
|
54 | if (options.useFactory) {
|
55 | return {
|
56 | provide: files_constants_1.MULTER_MODULE_OPTIONS,
|
57 | useFactory: options.useFactory,
|
58 | inject: options.inject || [],
|
59 | };
|
60 | }
|
61 | return {
|
62 | provide: files_constants_1.MULTER_MODULE_OPTIONS,
|
63 | useFactory: async (optionsFactory) => optionsFactory.createMulterOptions(),
|
64 | inject: [options.useExisting || options.useClass],
|
65 | };
|
66 | }
|
67 | };
|
68 | exports.MulterModule = MulterModule = MulterModule_1 = tslib_1.__decorate([
|
69 | (0, common_1.Module)({})
|
70 | ], MulterModule);
|