@dudousxd/nestjs-media
Version:
Filesystem + media-library for NestJS — one package
804 lines (795 loc) • 27.1 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/media.module.ts
import { AttachmentManager as AttachmentManager2, DirectUploadManager, MediaLibrary, ResumableUploadManager, StorageManager as StorageManager2, TusUploadHandler } from "@dudousxd/nestjs-media-core";
import { Global, Module } from "@nestjs/common";
// src/media-direct-upload.controller.ts
import { Body, Controller, Delete, Inject, NotImplementedException, Param, Post, Query } from "@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 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 NotImplementedException("Direct uploads are not configured.");
const key = keyQuery ?? body.key;
if (!key) throw new 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 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 NotImplementedException("Direct uploads are not configured.");
const key = keyQuery ?? body.key;
if (!key) throw new NotImplementedException("key is required");
return this.manager.abortUpload({
key,
uploadId,
...diskQuery !== void 0 ? {
disk: diskQuery
} : body.disk !== void 0 ? {
disk: body.disk
} : {}
});
}
};
_ts_decorate([
Post("initiate"),
_ts_param(0, 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([
Post(":uploadId/parts/:partNumber"),
_ts_param(0, Param("uploadId")),
_ts_param(1, Param("partNumber")),
_ts_param(2, Query("key")),
_ts_param(3, Query("disk")),
_ts_param(4, 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([
Post(":uploadId/complete"),
_ts_param(0, Param("uploadId")),
_ts_param(1, 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([
Delete(":uploadId"),
_ts_param(0, Param("uploadId")),
_ts_param(1, Query("key")),
_ts_param(2, Query("disk")),
_ts_param(3, 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([
Controller("media/uploads/direct"),
_ts_param(0, Inject(MEDIA_DIRECT)),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
Object
])
], MediaDirectUploadController);
// src/media-multipart-upload.controller.ts
import { BadRequestException, Controller as Controller2, Get, Inject as Inject2, NotImplementedException as NotImplementedException2, Param as Param2, Post as Post2, Put, Req } from "@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 NotImplementedException2("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 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([
Put(":id/parts/:partNumber"),
_ts_param2(0, Param2("id")),
_ts_param2(1, Param2("partNumber")),
_ts_param2(2, 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([
Post2(":id/complete"),
_ts_param2(0, Param2("id")),
_ts_metadata2("design:type", Function),
_ts_metadata2("design:paramtypes", [
String
]),
_ts_metadata2("design:returntype", Promise)
], MediaMultipartUploadController.prototype, "complete", null);
_ts_decorate2([
Get(":id/parts"),
_ts_param2(0, Param2("id")),
_ts_metadata2("design:type", Function),
_ts_metadata2("design:paramtypes", [
String
]),
_ts_metadata2("design:returntype", Promise)
], MediaMultipartUploadController.prototype, "listParts", null);
MediaMultipartUploadController = _ts_decorate2([
Controller2("media/uploads"),
_ts_param2(0, Inject2(MEDIA_UPLOADS)),
_ts_metadata2("design:type", Function),
_ts_metadata2("design:paramtypes", [
Object
])
], MediaMultipartUploadController);
// src/media-upload.controller.ts
import { Controller as Controller3, Delete as Delete2, Head, Headers, Inject as Inject3, NotImplementedException as NotImplementedException3, Options, Param as Param3, Patch, Post as Post3, Req as Req2, Res } from "@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 NotImplementedException3("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([
Options(),
_ts_param3(0, Res()),
_ts_param3(1, 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([
Post3(),
_ts_param3(0, Res()),
_ts_param3(1, 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([
Head(":id"),
_ts_param3(0, Param3("id")),
_ts_param3(1, Res()),
_ts_param3(2, 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([
Patch(":id"),
_ts_param3(0, Param3("id")),
_ts_param3(1, Req2()),
_ts_param3(2, Res()),
_ts_param3(3, 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([
Delete2(":id"),
_ts_param3(0, Param3("id")),
_ts_param3(1, Res()),
_ts_param3(2, 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([
Controller3("media/uploads"),
_ts_param3(0, Inject3(MEDIA_TUS)),
_ts_metadata3("design:type", Function),
_ts_metadata3("design:paramtypes", [
Object
])
], MediaUploadController);
// src/media.service.ts
import { Inject as Inject4, Injectable } from "@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([
Injectable(),
_ts_param4(0, Inject4(MEDIA_STORAGE)),
_ts_param4(1, Inject4(MEDIA_LIBRARY)),
_ts_param4(2, Inject4(MEDIA_UPLOADS)),
_ts_param4(3, Inject4(MEDIA_ATTACHMENTS)),
_ts_param4(4, Inject4(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 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 AttachmentManager2({
storage: manager,
...options.imageProcessor ? {
imageProcessor: options.imageProcessor
} : {}
});
}
__name(buildAttachments, "buildAttachments");
function buildUploads(manager, options) {
if (!options.uploadSessions) return null;
return new 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 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 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 StorageManager2(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 StorageManager2(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([
Global(),
Module({})
], MediaModule);
// src/index.ts
import { ConversionNotDefinedError, FileNotFoundError, ImageProcessorMissingError, InvalidPartNumberError, MediaNotFoundError, MimeNotAllowedError, ResumableUploadManager as ResumableUploadManager2, UnknownDiskError, UnsupportedOperationError, UploadOffsetConflictError, UploadSessionNotFoundError, mediaDiagnosticKey, publishMedia } from "@dudousxd/nestjs-media-core";
export {
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,
ResumableUploadManager2 as ResumableUploadManager,
UnknownDiskError,
UnsupportedOperationError,
UploadOffsetConflictError,
UploadSessionNotFoundError,
mediaDiagnosticKey,
publishMedia
};
//# sourceMappingURL=index.js.map