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 | let MulterModule = MulterModule_1 = class MulterModule {
|
11 | static register(options = {}) {
|
12 | return {
|
13 | module: MulterModule_1,
|
14 | providers: [
|
15 | { provide: files_constants_1.MULTER_MODULE_OPTIONS, useValue: options },
|
16 | {
|
17 | provide: multer_constants_1.MULTER_MODULE_ID,
|
18 | useValue: random_string_generator_util_1.randomStringGenerator(),
|
19 | },
|
20 | ],
|
21 | exports: [files_constants_1.MULTER_MODULE_OPTIONS],
|
22 | };
|
23 | }
|
24 | static registerAsync(options) {
|
25 | return {
|
26 | module: MulterModule_1,
|
27 | imports: options.imports,
|
28 | providers: [
|
29 | ...this.createAsyncProviders(options),
|
30 | {
|
31 | provide: multer_constants_1.MULTER_MODULE_ID,
|
32 | useValue: random_string_generator_util_1.randomStringGenerator(),
|
33 | },
|
34 | ],
|
35 | exports: [files_constants_1.MULTER_MODULE_OPTIONS],
|
36 | };
|
37 | }
|
38 | static createAsyncProviders(options) {
|
39 | if (options.useExisting || options.useFactory) {
|
40 | return [this.createAsyncOptionsProvider(options)];
|
41 | }
|
42 | return [
|
43 | this.createAsyncOptionsProvider(options),
|
44 | {
|
45 | provide: options.useClass,
|
46 | useClass: options.useClass,
|
47 | },
|
48 | ];
|
49 | }
|
50 | static createAsyncOptionsProvider(options) {
|
51 | if (options.useFactory) {
|
52 | return {
|
53 | provide: files_constants_1.MULTER_MODULE_OPTIONS,
|
54 | useFactory: options.useFactory,
|
55 | inject: options.inject || [],
|
56 | };
|
57 | }
|
58 | return {
|
59 | provide: files_constants_1.MULTER_MODULE_OPTIONS,
|
60 | useFactory: async (optionsFactory) => optionsFactory.createMulterOptions(),
|
61 | inject: [options.useExisting || options.useClass],
|
62 | };
|
63 | }
|
64 | };
|
65 | MulterModule = MulterModule_1 = tslib_1.__decorate([
|
66 | common_1.Module({})
|
67 | ], MulterModule);
|
68 | exports.MulterModule = MulterModule;
|