UNPKG

@dudousxd/nestjs-media

Version:

Filesystem + media-library for NestJS — one package

855 lines (845 loc) 30.3 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { ConversionNotDefinedError: () => import_nestjs_media_core2.ConversionNotDefinedError, FileNotFoundError: () => import_nestjs_media_core2.FileNotFoundError, ImageProcessorMissingError: () => import_nestjs_media_core2.ImageProcessorMissingError, InvalidPartNumberError: () => import_nestjs_media_core2.InvalidPartNumberError, MEDIA_ATTACHMENTS: () => MEDIA_ATTACHMENTS, MEDIA_DIRECT: () => MEDIA_DIRECT, MEDIA_LIBRARY: () => MEDIA_LIBRARY, MEDIA_STORAGE: () => MEDIA_STORAGE, MEDIA_STORAGE_SHARED: () => MEDIA_STORAGE_SHARED, MEDIA_STORE: () => MEDIA_STORE, MEDIA_TUS: () => MEDIA_TUS, MEDIA_UPLOADS: () => MEDIA_UPLOADS, MEDIA_UPLOAD_SESSIONS: () => MEDIA_UPLOAD_SESSIONS, MediaDirectUploadController: () => MediaDirectUploadController, MediaModule: () => MediaModule, MediaMultipartUploadController: () => MediaMultipartUploadController, MediaNotFoundError: () => import_nestjs_media_core2.MediaNotFoundError, MediaService: () => MediaService, MediaUploadController: () => MediaUploadController, MimeNotAllowedError: () => import_nestjs_media_core2.MimeNotAllowedError, ResumableUploadManager: () => import_nestjs_media_core2.ResumableUploadManager, UnknownDiskError: () => import_nestjs_media_core2.UnknownDiskError, UnsupportedOperationError: () => import_nestjs_media_core2.UnsupportedOperationError, UploadOffsetConflictError: () => import_nestjs_media_core2.UploadOffsetConflictError, UploadSessionNotFoundError: () => import_nestjs_media_core2.UploadSessionNotFoundError, mediaDiagnosticKey: () => import_nestjs_media_core2.mediaDiagnosticKey, publishMedia: () => import_nestjs_media_core2.publishMedia }); module.exports = __toCommonJS(index_exports); // src/media.module.ts var import_nestjs_media_core = require("@dudousxd/nestjs-media-core"); var import_common5 = require("@nestjs/common"); // src/media-direct-upload.controller.ts var import_common = require("@nestjs/common"); // src/tokens.ts var MEDIA_STORAGE = Symbol("MEDIA_STORAGE"); var MEDIA_LIBRARY = Symbol("MEDIA_LIBRARY"); var MEDIA_UPLOADS = Symbol("MEDIA_UPLOADS"); var MEDIA_TUS = Symbol("MEDIA_TUS"); var MEDIA_ATTACHMENTS = Symbol("MEDIA_ATTACHMENTS"); var MEDIA_DIRECT = Symbol("MEDIA_DIRECT"); var MEDIA_STORE = Symbol.for("nestjs-media:store"); var MEDIA_UPLOAD_SESSIONS = Symbol.for("nestjs-media:upload-sessions"); var MEDIA_STORAGE_SHARED = Symbol.for("nestjs-media:storage"); // src/media-direct-upload.controller.ts function _ts_decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; } __name(_ts_decorate, "_ts_decorate"); function _ts_metadata(k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); } __name(_ts_metadata, "_ts_metadata"); function _ts_param(paramIndex, decorator) { return function(target, key) { decorator(target, key, paramIndex); }; } __name(_ts_param, "_ts_param"); var MediaDirectUploadController = class { static { __name(this, "MediaDirectUploadController"); } manager; constructor(manager) { this.manager = manager; } initiate(body) { if (!this.manager) throw new import_common.NotImplementedException("Direct uploads are not configured."); return this.manager.createUpload({ key: body.key, ...body.contentType !== void 0 ? { contentType: body.contentType } : {}, ...body.size !== void 0 ? { size: body.size } : {}, ...body.partSize !== void 0 ? { partSize: body.partSize } : {}, ...body.disk !== void 0 ? { disk: body.disk } : {} }); } presignPart(uploadId, partNumber, keyQuery, diskQuery, body) { if (!this.manager) throw new import_common.NotImplementedException("Direct uploads are not configured."); const key = keyQuery ?? body.key; if (!key) throw new import_common.NotImplementedException("key is required"); return this.manager.presignPart({ key, uploadId, partNumber: Number(partNumber), ...diskQuery !== void 0 ? { disk: diskQuery } : body.disk !== void 0 ? { disk: body.disk } : {} }); } complete(uploadId, body) { if (!this.manager) throw new import_common.NotImplementedException("Direct uploads are not configured."); return this.manager.completeUpload({ key: body.key, uploadId, parts: body.parts, ...body.disk !== void 0 ? { disk: body.disk } : {} }); } abort(uploadId, keyQuery, diskQuery, body) { if (!this.manager) throw new import_common.NotImplementedException("Direct uploads are not configured."); const key = keyQuery ?? body.key; if (!key) throw new import_common.NotImplementedException("key is required"); return this.manager.abortUpload({ key, uploadId, ...diskQuery !== void 0 ? { disk: diskQuery } : body.disk !== void 0 ? { disk: body.disk } : {} }); } }; _ts_decorate([ (0, import_common.Post)("initiate"), _ts_param(0, (0, import_common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof InitiateBody === "undefined" ? Object : InitiateBody ]), _ts_metadata("design:returntype", void 0) ], MediaDirectUploadController.prototype, "initiate", null); _ts_decorate([ (0, import_common.Post)(":uploadId/parts/:partNumber"), _ts_param(0, (0, import_common.Param)("uploadId")), _ts_param(1, (0, import_common.Param)("partNumber")), _ts_param(2, (0, import_common.Query)("key")), _ts_param(3, (0, import_common.Query)("disk")), _ts_param(4, (0, import_common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ String, String, Object, Object, Object ]), _ts_metadata("design:returntype", void 0) ], MediaDirectUploadController.prototype, "presignPart", null); _ts_decorate([ (0, import_common.Post)(":uploadId/complete"), _ts_param(0, (0, import_common.Param)("uploadId")), _ts_param(1, (0, import_common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ String, typeof CompleteBody === "undefined" ? Object : CompleteBody ]), _ts_metadata("design:returntype", void 0) ], MediaDirectUploadController.prototype, "complete", null); _ts_decorate([ (0, import_common.Delete)(":uploadId"), _ts_param(0, (0, import_common.Param)("uploadId")), _ts_param(1, (0, import_common.Query)("key")), _ts_param(2, (0, import_common.Query)("disk")), _ts_param(3, (0, import_common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ String, Object, Object, Object ]), _ts_metadata("design:returntype", void 0) ], MediaDirectUploadController.prototype, "abort", null); MediaDirectUploadController = _ts_decorate([ (0, import_common.Controller)("media/uploads/direct"), _ts_param(0, (0, import_common.Inject)(MEDIA_DIRECT)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ Object ]) ], MediaDirectUploadController); // src/media-multipart-upload.controller.ts var import_common2 = require("@nestjs/common"); function _ts_decorate2(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; } __name(_ts_decorate2, "_ts_decorate"); function _ts_metadata2(k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); } __name(_ts_metadata2, "_ts_metadata"); function _ts_param2(paramIndex, decorator) { return function(target, key) { decorator(target, key, paramIndex); }; } __name(_ts_param2, "_ts_param"); var MediaMultipartUploadController = class { static { __name(this, "MediaMultipartUploadController"); } manager; constructor(manager) { this.manager = manager; } requireManager() { if (!this.manager) throw new import_common2.NotImplementedException("Uploads are not configured."); return this.manager; } async uploadPart(id, partNumber, req) { const manager = this.requireManager(); if (!req.body || req.body.byteLength === 0) { throw new import_common2.BadRequestException("Empty upload part body \u2014 ensure a raw-body parser with a size cap is mounted on this route."); } return manager.writePart(id, Number(partNumber), req.body); } async complete(id) { const manager = this.requireManager(); return manager.complete(id); } async listParts(id) { const manager = this.requireManager(); const parts = await manager.listParts(id); return { parts: parts.map((part) => part.partNumber) }; } }; _ts_decorate2([ (0, import_common2.Put)(":id/parts/:partNumber"), _ts_param2(0, (0, import_common2.Param)("id")), _ts_param2(1, (0, import_common2.Param)("partNumber")), _ts_param2(2, (0, import_common2.Req)()), _ts_metadata2("design:type", Function), _ts_metadata2("design:paramtypes", [ String, String, typeof ReqLike === "undefined" ? Object : ReqLike ]), _ts_metadata2("design:returntype", Promise) ], MediaMultipartUploadController.prototype, "uploadPart", null); _ts_decorate2([ (0, import_common2.Post)(":id/complete"), _ts_param2(0, (0, import_common2.Param)("id")), _ts_metadata2("design:type", Function), _ts_metadata2("design:paramtypes", [ String ]), _ts_metadata2("design:returntype", Promise) ], MediaMultipartUploadController.prototype, "complete", null); _ts_decorate2([ (0, import_common2.Get)(":id/parts"), _ts_param2(0, (0, import_common2.Param)("id")), _ts_metadata2("design:type", Function), _ts_metadata2("design:paramtypes", [ String ]), _ts_metadata2("design:returntype", Promise) ], MediaMultipartUploadController.prototype, "listParts", null); MediaMultipartUploadController = _ts_decorate2([ (0, import_common2.Controller)("media/uploads"), _ts_param2(0, (0, import_common2.Inject)(MEDIA_UPLOADS)), _ts_metadata2("design:type", Function), _ts_metadata2("design:paramtypes", [ Object ]) ], MediaMultipartUploadController); // src/media-upload.controller.ts var import_common3 = require("@nestjs/common"); function _ts_decorate3(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; } __name(_ts_decorate3, "_ts_decorate"); function _ts_metadata3(k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); } __name(_ts_metadata3, "_ts_metadata"); function _ts_param3(paramIndex, decorator) { return function(target, key) { decorator(target, key, paramIndex); }; } __name(_ts_param3, "_ts_param"); var MediaUploadController = class { static { __name(this, "MediaUploadController"); } handler; constructor(handler) { this.handler = handler; } options(res, headers) { return this.run({ method: "OPTIONS", headers }, res); } create(res, headers) { return this.run({ method: "POST", headers }, res); } head(id, res, headers) { return this.run({ method: "HEAD", uploadId: id, headers }, res); } patch(id, req, res, headers) { return this.run({ method: "PATCH", uploadId: id, headers, ...req.body ? { body: req.body } : {} }, res); } remove(id, res, headers) { return this.run({ method: "DELETE", uploadId: id, headers }, res); } async run(req, res) { if (!this.handler) throw new import_common3.NotImplementedException("Tus uploads are not configured."); const result = await this.handler.handle(req); res.status(result.status); for (const [name, value] of Object.entries(result.headers)) res.setHeader(name, value); if (result.body !== void 0) res.send(result.body); else res.end(); } }; _ts_decorate3([ (0, import_common3.Options)(), _ts_param3(0, (0, import_common3.Res)()), _ts_param3(1, (0, import_common3.Headers)()), _ts_metadata3("design:type", Function), _ts_metadata3("design:paramtypes", [ typeof ResLike === "undefined" ? Object : ResLike, typeof Record === "undefined" ? Object : Record ]), _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], MediaUploadController.prototype, "options", null); _ts_decorate3([ (0, import_common3.Post)(), _ts_param3(0, (0, import_common3.Res)()), _ts_param3(1, (0, import_common3.Headers)()), _ts_metadata3("design:type", Function), _ts_metadata3("design:paramtypes", [ typeof ResLike === "undefined" ? Object : ResLike, typeof Record === "undefined" ? Object : Record ]), _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], MediaUploadController.prototype, "create", null); _ts_decorate3([ (0, import_common3.Head)(":id"), _ts_param3(0, (0, import_common3.Param)("id")), _ts_param3(1, (0, import_common3.Res)()), _ts_param3(2, (0, import_common3.Headers)()), _ts_metadata3("design:type", Function), _ts_metadata3("design:paramtypes", [ String, typeof ResLike === "undefined" ? Object : ResLike, typeof Record === "undefined" ? Object : Record ]), _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], MediaUploadController.prototype, "head", null); _ts_decorate3([ (0, import_common3.Patch)(":id"), _ts_param3(0, (0, import_common3.Param)("id")), _ts_param3(1, (0, import_common3.Req)()), _ts_param3(2, (0, import_common3.Res)()), _ts_param3(3, (0, import_common3.Headers)()), _ts_metadata3("design:type", Function), _ts_metadata3("design:paramtypes", [ String, typeof ReqLike === "undefined" ? Object : ReqLike, typeof ResLike === "undefined" ? Object : ResLike, typeof Record === "undefined" ? Object : Record ]), _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], MediaUploadController.prototype, "patch", null); _ts_decorate3([ (0, import_common3.Delete)(":id"), _ts_param3(0, (0, import_common3.Param)("id")), _ts_param3(1, (0, import_common3.Res)()), _ts_param3(2, (0, import_common3.Headers)()), _ts_metadata3("design:type", Function), _ts_metadata3("design:paramtypes", [ String, typeof ResLike === "undefined" ? Object : ResLike, typeof Record === "undefined" ? Object : Record ]), _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], MediaUploadController.prototype, "remove", null); MediaUploadController = _ts_decorate3([ (0, import_common3.Controller)("media/uploads"), _ts_param3(0, (0, import_common3.Inject)(MEDIA_TUS)), _ts_metadata3("design:type", Function), _ts_metadata3("design:paramtypes", [ Object ]) ], MediaUploadController); // src/media.service.ts var import_common4 = require("@nestjs/common"); function _ts_decorate4(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; } __name(_ts_decorate4, "_ts_decorate"); function _ts_metadata4(k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); } __name(_ts_metadata4, "_ts_metadata"); function _ts_param4(paramIndex, decorator) { return function(target, key) { decorator(target, key, paramIndex); }; } __name(_ts_param4, "_ts_param"); var MediaService = class { static { __name(this, "MediaService"); } manager; mediaLibrary; uploadManager; attachmentManager; directManager; constructor(manager, mediaLibrary, uploadManager, attachmentManager, directManager) { this.manager = manager; this.mediaLibrary = mediaLibrary; this.uploadManager = uploadManager; this.attachmentManager = attachmentManager; this.directManager = directManager; } /** Attachment-as-column API (adonis-attachment style): `media.attachments.createFromFile(...)`. */ get attachments() { return this.attachmentManager; } /** Storage layer (layer 1): `media.disk('s3').put(...)`. */ disk(name) { return this.manager.disk(name); } /** Names of the configured disks (delegates to the storage manager). */ diskNames() { return this.manager.diskNames(); } /** Media-library layer (layer 2). Throws if no store was configured. */ get library() { if (!this.mediaLibrary) { throw new Error("MediaLibrary is not configured. Pass a `store` to MediaModule.forRoot to enable the media-library layer."); } return this.mediaLibrary; } /** Resumable (proxy) uploads. Throws if no upload session store was configured. */ get uploads() { if (!this.uploadManager) { throw new Error("Resumable uploads are not configured. Pass `uploadSessions` to MediaModule.forRoot to enable them."); } return this.uploadManager; } /** Direct (S3 multipart presign) uploads. Throws if not configured. */ get directUploads() { if (!this.directManager) { throw new Error("Direct uploads are not configured. Pass `direct` to MediaModule.forRoot to enable them."); } return this.directManager; } }; MediaService = _ts_decorate4([ (0, import_common4.Injectable)(), _ts_param4(0, (0, import_common4.Inject)(MEDIA_STORAGE)), _ts_param4(1, (0, import_common4.Inject)(MEDIA_LIBRARY)), _ts_param4(2, (0, import_common4.Inject)(MEDIA_UPLOADS)), _ts_param4(3, (0, import_common4.Inject)(MEDIA_ATTACHMENTS)), _ts_param4(4, (0, import_common4.Inject)(MEDIA_DIRECT)), _ts_metadata4("design:type", Function), _ts_metadata4("design:paramtypes", [ typeof StorageManager === "undefined" ? Object : StorageManager, Object, Object, typeof AttachmentManager === "undefined" ? Object : AttachmentManager, Object ]) ], MediaService); // src/media.module.ts function _ts_decorate5(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; } __name(_ts_decorate5, "_ts_decorate"); function perSurfaceGuards(guards) { if (Array.isArray(guards)) return { tus: guards, multipart: guards, direct: guards }; return { tus: guards?.tus ?? [], multipart: guards?.multipart ?? [], direct: guards?.direct ?? [] }; } __name(perSurfaceGuards, "perSurfaceGuards"); function guardProviders(guards) { const bySurface = perSurfaceGuards(guards); return [ .../* @__PURE__ */ new Set([ ...bySurface.tus, ...bySurface.multipart, ...bySurface.direct ]) ]; } __name(guardProviders, "guardProviders"); var GUARDS_METADATA = "__guards__"; function applyGuards(guards) { const bySurface = perSurfaceGuards(guards); Reflect.defineMetadata(GUARDS_METADATA, bySurface.tus, MediaUploadController); Reflect.defineMetadata(GUARDS_METADATA, bySurface.multipart, MediaMultipartUploadController); Reflect.defineMetadata(GUARDS_METADATA, bySurface.direct, MediaDirectUploadController); } __name(applyGuards, "applyGuards"); function buildLibrary(manager, options) { if (!options.store) return null; return new import_nestjs_media_core.MediaLibrary({ storage: manager, store: options.store, ...options.collections ? { collections: options.collections } : {}, ...options.imageProcessor ? { imageProcessor: options.imageProcessor } : {} }); } __name(buildLibrary, "buildLibrary"); function buildAttachments(manager, options) { return new import_nestjs_media_core.AttachmentManager({ storage: manager, ...options.imageProcessor ? { imageProcessor: options.imageProcessor } : {} }); } __name(buildAttachments, "buildAttachments"); function buildUploads(manager, options) { if (!options.uploadSessions) return null; return new import_nestjs_media_core.ResumableUploadManager({ storage: manager, sessions: options.uploadSessions, ...options.uploadTmpPrefix ? { tmpPrefix: options.uploadTmpPrefix } : {} }); } __name(buildUploads, "buildUploads"); function buildTus(uploads, options) { if (!uploads || !options.tus) return null; return new import_nestjs_media_core.TusUploadHandler({ manager: uploads, disk: options.tus.disk, basePath: options.tus.basePath ?? "/media/uploads", ...options.tus.maxSize ? { maxSize: options.tus.maxSize } : {}, ...options.tus.keyFor ? { keyFor: options.tus.keyFor } : {} }); } __name(buildTus, "buildTus"); function buildDirect(manager, options) { if (!options.direct) return null; return new import_nestjs_media_core.DirectUploadManager({ storage: manager, ...options.direct.partSize ? { defaultPartSize: options.direct.partSize } : {} }); } __name(buildDirect, "buildDirect"); var MediaModule = class _MediaModule { static { __name(this, "MediaModule"); } static forRoot(options) { const manager = new import_nestjs_media_core.StorageManager(options); const uploads = buildUploads(manager, options); const tus = buildTus(uploads, options); const direct = buildDirect(manager, options); applyGuards(options.guards); return { module: _MediaModule, imports: options.imports ?? [], providers: [ { provide: MEDIA_STORAGE, useValue: manager }, { provide: MEDIA_STORAGE_SHARED, useExisting: MEDIA_STORAGE }, { provide: MEDIA_LIBRARY, useValue: buildLibrary(manager, options) }, { provide: MEDIA_UPLOADS, useValue: uploads }, { provide: MEDIA_TUS, useValue: tus }, { provide: MEDIA_ATTACHMENTS, useValue: buildAttachments(manager, options) }, { provide: MEDIA_DIRECT, useValue: direct }, { provide: MEDIA_STORE, useValue: options.store ?? null }, { provide: MEDIA_UPLOAD_SESSIONS, useValue: options.uploadSessions ?? null }, ...guardProviders(options.guards), MediaService ], controllers: [ ...tus ? [ MediaUploadController ] : [], ...uploads ? [ MediaMultipartUploadController ] : [], ...direct ? [ MediaDirectUploadController ] : [] ], exports: [ MediaService, MEDIA_STORAGE, MEDIA_STORAGE_SHARED, MEDIA_LIBRARY, MEDIA_UPLOADS, MEDIA_TUS, MEDIA_ATTACHMENTS, MEDIA_DIRECT, MEDIA_STORE, MEDIA_UPLOAD_SESSIONS ] }; } static forRootAsync(options) { const providers = [ { provide: MEDIA_STORAGE, inject: options.inject ?? [], useFactory: /* @__PURE__ */ __name(async (...args) => new import_nestjs_media_core.StorageManager(await options.useFactory(...args)), "useFactory") }, { provide: MEDIA_STORAGE_SHARED, useExisting: MEDIA_STORAGE }, { provide: MEDIA_LIBRARY, inject: [ MEDIA_STORAGE, ...options.inject ?? [] ], useFactory: /* @__PURE__ */ __name(async (manager, ...args) => buildLibrary(manager, await options.useFactory(...args)), "useFactory") }, { provide: MEDIA_UPLOADS, inject: [ MEDIA_STORAGE, ...options.inject ?? [] ], useFactory: /* @__PURE__ */ __name(async (manager, ...args) => buildUploads(manager, await options.useFactory(...args)), "useFactory") }, { provide: MEDIA_TUS, inject: [ MEDIA_UPLOADS, ...options.inject ?? [] ], useFactory: /* @__PURE__ */ __name(async (uploads, ...args) => buildTus(uploads, await options.useFactory(...args)), "useFactory") }, { provide: MEDIA_ATTACHMENTS, inject: [ MEDIA_STORAGE, ...options.inject ?? [] ], useFactory: /* @__PURE__ */ __name(async (manager, ...args) => buildAttachments(manager, await options.useFactory(...args)), "useFactory") }, { provide: MEDIA_DIRECT, inject: [ MEDIA_STORAGE, ...options.inject ?? [] ], useFactory: /* @__PURE__ */ __name(async (manager, ...args) => buildDirect(manager, await options.useFactory(...args)), "useFactory") }, { provide: MEDIA_STORE, inject: options.inject ?? [], useFactory: /* @__PURE__ */ __name(async (...args) => (await options.useFactory(...args)).store ?? null, "useFactory") }, { provide: MEDIA_UPLOAD_SESSIONS, inject: options.inject ?? [], useFactory: /* @__PURE__ */ __name(async (...args) => (await options.useFactory(...args)).uploadSessions ?? null, "useFactory") }, ...guardProviders(options.guards), MediaService ]; applyGuards(options.guards); return { module: _MediaModule, imports: options.imports ?? [], providers, // Unlike `forRoot`, async options are resolved at runtime by `useFactory`, // so we cannot know at module-build time whether `tus`/`direct` are configured // and therefore cannot mount these controllers conditionally. Each mounted // controller injects its nullable manager token (MEDIA_TUS / MEDIA_UPLOADS / // MEDIA_DIRECT) and cleanly responds 501 NotImplemented when its feature is // left unconfigured by the factory. `mount` is a separate, STATIC escape // hatch (see its JSDoc on `MediaModuleAsyncOptions`) for dropping a // controller's route surface entirely instead of leaving it mounted-but-501. controllers: [ ...options.mount?.tus === false ? [] : [ MediaUploadController ], ...options.mount?.multipart === false ? [] : [ MediaMultipartUploadController ], ...options.mount?.direct === false ? [] : [ MediaDirectUploadController ] ], exports: [ MediaService, MEDIA_STORAGE, MEDIA_STORAGE_SHARED, MEDIA_LIBRARY, MEDIA_UPLOADS, MEDIA_TUS, MEDIA_ATTACHMENTS, MEDIA_DIRECT, MEDIA_STORE, MEDIA_UPLOAD_SESSIONS ] }; } }; MediaModule = _ts_decorate5([ (0, import_common5.Global)(), (0, import_common5.Module)({}) ], MediaModule); // src/index.ts var import_nestjs_media_core2 = require("@dudousxd/nestjs-media-core"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ConversionNotDefinedError, FileNotFoundError, ImageProcessorMissingError, InvalidPartNumberError, MEDIA_ATTACHMENTS, MEDIA_DIRECT, MEDIA_LIBRARY, MEDIA_STORAGE, MEDIA_STORAGE_SHARED, MEDIA_STORE, MEDIA_TUS, MEDIA_UPLOADS, MEDIA_UPLOAD_SESSIONS, MediaDirectUploadController, MediaModule, MediaMultipartUploadController, MediaNotFoundError, MediaService, MediaUploadController, MimeNotAllowedError, ResumableUploadManager, UnknownDiskError, UnsupportedOperationError, UploadOffsetConflictError, UploadSessionNotFoundError, mediaDiagnosticKey, publishMedia }); //# sourceMappingURL=index.cjs.map