@dudousxd/nestjs-media-dashboard 0.1.0

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.
@@ -0,0 +1,828 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/server/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ MEDIA_STORAGE_SHARED: () => MEDIA_STORAGE_SHARED,
25
+ MEDIA_STORE: () => MEDIA_STORE,
26
+ MEDIA_UPLOAD_SESSIONS: () => MEDIA_UPLOAD_SESSIONS,
27
+ MediaConsoleApiModule: () => MediaConsoleApiModule,
28
+ MediaConsoleService: () => MediaConsoleService,
29
+ MediaDashboardModule: () => MediaDashboardModule
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // ../../node_modules/.pnpm/tsup@8.3.5_@swc+core@1.15.41_jiti@1.21.7_postcss@8.4.49_typescript@5.9.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
34
+ var getImportMetaUrl = /* @__PURE__ */ __name(() => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href, "getImportMetaUrl");
35
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
36
+
37
+ // src/server/media-dashboard.module.ts
38
+ var import_common6 = require("@nestjs/common");
39
+ var import_core = require("@nestjs/core");
40
+
41
+ // src/server/media-console-api.module.ts
42
+ var import_common4 = require("@nestjs/common");
43
+
44
+ // src/server/media-console-actions.controller.ts
45
+ var import_common2 = require("@nestjs/common");
46
+
47
+ // src/server/media-console.service.ts
48
+ var import_common = require("@nestjs/common");
49
+
50
+ // src/server/tokens.ts
51
+ var MEDIA_STORE = Symbol.for("nestjs-media:store");
52
+ var MEDIA_UPLOAD_SESSIONS = Symbol.for("nestjs-media:upload-sessions");
53
+ var MEDIA_STORAGE_SHARED = Symbol.for("nestjs-media:storage");
54
+ var MEDIA_DASHBOARD_BASE_PATH = Symbol("MEDIA_DASHBOARD_BASE_PATH");
55
+ var MEDIA_DASHBOARD_API_PATH = Symbol("MEDIA_DASHBOARD_API_PATH");
56
+ var MEDIA_DASHBOARD_ACTIONS = Symbol("MEDIA_DASHBOARD_ACTIONS");
57
+
58
+ // src/server/media-console.service.ts
59
+ function _ts_decorate(decorators, target, key, desc) {
60
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
62
+ 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;
63
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
64
+ }
65
+ __name(_ts_decorate, "_ts_decorate");
66
+ function _ts_metadata(k, v) {
67
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
68
+ }
69
+ __name(_ts_metadata, "_ts_metadata");
70
+ function _ts_param(paramIndex, decorator) {
71
+ return function(target, key) {
72
+ decorator(target, key, paramIndex);
73
+ };
74
+ }
75
+ __name(_ts_param, "_ts_param");
76
+ var URL_TTL_SECONDS = 300;
77
+ var DEFAULT_PAGE_LIMIT = 50;
78
+ function lastSegment(prefix) {
79
+ const trimmed = prefix.replace(/\/+$/, "");
80
+ const slash = trimmed.lastIndexOf("/");
81
+ return slash === -1 ? trimmed : trimmed.slice(slash + 1);
82
+ }
83
+ __name(lastSegment, "lastSegment");
84
+ function mapUpload(session) {
85
+ const percent = session.size !== void 0 && session.size > 0 ? Math.min(100, Math.round(session.offset / session.size * 100)) : null;
86
+ return {
87
+ id: session.id,
88
+ disk: session.disk,
89
+ key: session.key,
90
+ offset: session.offset,
91
+ size: session.size ?? null,
92
+ percent,
93
+ parts: session.parts,
94
+ multipart: session.multipartUploadId !== void 0,
95
+ ...session.createdAt ? {
96
+ createdAt: session.createdAt.toISOString()
97
+ } : {}
98
+ };
99
+ }
100
+ __name(mapUpload, "mapUpload");
101
+ function mapRecord(record) {
102
+ return {
103
+ id: record.id,
104
+ ownerType: record.ownerType,
105
+ ownerId: record.ownerId,
106
+ collection: record.collection,
107
+ name: record.name,
108
+ fileName: record.fileName,
109
+ mimeType: record.mimeType,
110
+ size: record.size,
111
+ disk: record.disk,
112
+ path: record.path,
113
+ createdAt: record.createdAt.toISOString()
114
+ };
115
+ }
116
+ __name(mapRecord, "mapRecord");
117
+ var MediaConsoleService = class {
118
+ static {
119
+ __name(this, "MediaConsoleService");
120
+ }
121
+ storage;
122
+ store;
123
+ uploads;
124
+ actionsEnabled;
125
+ constructor(storage, store, uploads, actionsEnabled) {
126
+ this.storage = storage;
127
+ this.store = store;
128
+ this.uploads = uploads;
129
+ this.actionsEnabled = actionsEnabled;
130
+ }
131
+ diskOrThrow(disk) {
132
+ if (!this.storage || !this.storage.diskNames().includes(disk)) {
133
+ throw new import_common.NotFoundException(`Unknown disk: ${disk}`);
134
+ }
135
+ return this.storage.disk(disk);
136
+ }
137
+ listDisks() {
138
+ const storage = this.storage;
139
+ if (!storage) return {
140
+ disks: []
141
+ };
142
+ const defaultDisk = storage.defaultDisk;
143
+ return {
144
+ disks: storage.diskNames().map((name) => ({
145
+ name,
146
+ default: name === defaultDisk,
147
+ capabilities: storage.disk(name).capabilities
148
+ }))
149
+ };
150
+ }
151
+ async listObjects(disk, options) {
152
+ const driver = this.diskOrThrow(disk);
153
+ const result = await driver.list(options.prefix ?? "", {
154
+ delimiter: "/",
155
+ ...options.cursor ? {
156
+ cursor: options.cursor
157
+ } : {},
158
+ limit: options.limit ?? DEFAULT_PAGE_LIMIT
159
+ });
160
+ return {
161
+ folders: result.folders.map((prefix) => ({
162
+ name: lastSegment(prefix),
163
+ prefix
164
+ })),
165
+ files: result.files.map((entry) => ({
166
+ key: entry.key,
167
+ name: entry.name,
168
+ sizeBytes: entry.sizeBytes,
169
+ lastModified: entry.lastModified ? entry.lastModified.toISOString() : null
170
+ })),
171
+ ...result.cursor ? {
172
+ cursor: result.cursor
173
+ } : {}
174
+ };
175
+ }
176
+ async objectDetail(disk, key) {
177
+ const driver = this.diskOrThrow(disk);
178
+ const stat = driver.stat ? await driver.stat(key) : {
179
+ size: await driver.size(key)
180
+ };
181
+ const url = driver.capabilities.presign ? await driver.temporaryUrl(key, URL_TTL_SECONDS) : await driver.url(key);
182
+ return {
183
+ key,
184
+ size: stat.size,
185
+ ...stat.contentType ? {
186
+ contentType: stat.contentType
187
+ } : {},
188
+ ...stat.lastModified ? {
189
+ lastModified: stat.lastModified.toISOString()
190
+ } : {},
191
+ url
192
+ };
193
+ }
194
+ async deleteObject(disk, key) {
195
+ await this.diskOrThrow(disk).delete(key);
196
+ }
197
+ async copyObject(disk, from, to) {
198
+ await this.diskOrThrow(disk).copy(from, to);
199
+ }
200
+ async moveObject(disk, from, to) {
201
+ await this.diskOrThrow(disk).move(from, to);
202
+ }
203
+ async listUploads(filter) {
204
+ if (!this.uploads || typeof this.uploads.list !== "function") return {
205
+ uploads: []
206
+ };
207
+ const sessions = await this.uploads.list({
208
+ ...filter.disk ? {
209
+ disk: filter.disk
210
+ } : {},
211
+ ...filter.prefix ? {
212
+ keyPrefix: filter.prefix
213
+ } : {}
214
+ });
215
+ return {
216
+ uploads: sessions.map(mapUpload)
217
+ };
218
+ }
219
+ async uploadDetail(id) {
220
+ if (!this.uploads) throw new import_common.NotFoundException("No upload store configured");
221
+ const session = await this.uploads.get(id);
222
+ if (!session) throw new import_common.NotFoundException(`Unknown upload: ${id}`);
223
+ const parts = this.uploads.listParts ? await this.uploads.listParts(id) : [];
224
+ return {
225
+ upload: mapUpload(session),
226
+ parts
227
+ };
228
+ }
229
+ /**
230
+ * Cancels a resumable session by removing its record from the upload store, so it stops
231
+ * appearing as in-progress. NOTE: this does NOT tear down an underlying native multipart upload
232
+ * (e.g. an S3 multipart) or its temporary parts — the decoupled console resolves only the
233
+ * `UploadSessionStore`, not the `ResumableUploadManager` that owns `abort()`. An incomplete
234
+ * multipart is reaped by the bucket's lifecycle policy. Surfaced as "Cancel session" in the UI.
235
+ */
236
+ async abortUpload(id) {
237
+ if (!this.uploads) throw new import_common.NotFoundException("No upload store configured");
238
+ await this.uploads.delete(id);
239
+ }
240
+ async listCollections() {
241
+ if (!this.store || typeof this.store.aggregate !== "function") return {
242
+ collections: []
243
+ };
244
+ const buckets = await this.store.aggregate({
245
+ groupBy: "collection",
246
+ sum: "size"
247
+ });
248
+ return {
249
+ collections: buckets
250
+ };
251
+ }
252
+ async listLibrary(filter) {
253
+ if (!this.store || typeof this.store.list !== "function") return {
254
+ records: []
255
+ };
256
+ const page = await this.store.list({
257
+ ...filter.collection ? {
258
+ collection: filter.collection
259
+ } : {},
260
+ ...filter.disk ? {
261
+ disk: filter.disk
262
+ } : {}
263
+ }, {
264
+ limit: filter.limit ?? DEFAULT_PAGE_LIMIT,
265
+ ...filter.cursor ? {
266
+ cursor: filter.cursor
267
+ } : {}
268
+ });
269
+ return {
270
+ records: page.records.map(mapRecord),
271
+ ...page.cursor ? {
272
+ cursor: page.cursor
273
+ } : {}
274
+ };
275
+ }
276
+ async libraryDetail(id) {
277
+ if (!this.store) throw new import_common.NotFoundException("No media store configured");
278
+ const record = await this.store.find(id);
279
+ if (!record) throw new import_common.NotFoundException(`Unknown media record: ${id}`);
280
+ const variants = await Promise.all(Object.entries(record.conversions).map(async ([name, conversion]) => {
281
+ const driver = this.storage?.diskNames().includes(conversion.disk) ? this.storage.disk(conversion.disk) : null;
282
+ const url = driver?.capabilities.presign ? await driver.temporaryUrl(conversion.path, URL_TTL_SECONDS) : await driver?.url(conversion.path) ?? "";
283
+ return {
284
+ name,
285
+ url
286
+ };
287
+ }));
288
+ return {
289
+ record: mapRecord(record),
290
+ variants
291
+ };
292
+ }
293
+ async deleteLibraryRecord(id) {
294
+ if (!this.store) throw new import_common.NotFoundException("No media store configured");
295
+ await this.store.delete(id);
296
+ }
297
+ topology() {
298
+ return {
299
+ hasStore: this.store !== null && typeof this.store.list === "function",
300
+ hasUploads: this.uploads !== null && typeof this.uploads.list === "function",
301
+ disks: this.storage ? this.storage.diskNames().length : 0,
302
+ actions: this.actionsEnabled === true
303
+ };
304
+ }
305
+ };
306
+ MediaConsoleService = _ts_decorate([
307
+ (0, import_common.Injectable)(),
308
+ _ts_param(0, (0, import_common.Optional)()),
309
+ _ts_param(0, (0, import_common.Inject)(MEDIA_STORAGE_SHARED)),
310
+ _ts_param(1, (0, import_common.Optional)()),
311
+ _ts_param(1, (0, import_common.Inject)(MEDIA_STORE)),
312
+ _ts_param(2, (0, import_common.Optional)()),
313
+ _ts_param(2, (0, import_common.Inject)(MEDIA_UPLOAD_SESSIONS)),
314
+ _ts_param(3, (0, import_common.Optional)()),
315
+ _ts_param(3, (0, import_common.Inject)(MEDIA_DASHBOARD_ACTIONS)),
316
+ _ts_metadata("design:type", Function),
317
+ _ts_metadata("design:paramtypes", [
318
+ Object,
319
+ Object,
320
+ Object,
321
+ Object
322
+ ])
323
+ ], MediaConsoleService);
324
+
325
+ // src/server/media-console-actions.controller.ts
326
+ function _ts_decorate2(decorators, target, key, desc) {
327
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
328
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
329
+ 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;
330
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
331
+ }
332
+ __name(_ts_decorate2, "_ts_decorate");
333
+ function _ts_metadata2(k, v) {
334
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
335
+ }
336
+ __name(_ts_metadata2, "_ts_metadata");
337
+ function _ts_param2(paramIndex, decorator) {
338
+ return function(target, key) {
339
+ decorator(target, key, paramIndex);
340
+ };
341
+ }
342
+ __name(_ts_param2, "_ts_param");
343
+ var MediaConsoleActionsController = class {
344
+ static {
345
+ __name(this, "MediaConsoleActionsController");
346
+ }
347
+ service;
348
+ constructor(service) {
349
+ this.service = service;
350
+ }
351
+ deleteObject(disk, key) {
352
+ return this.service.deleteObject(disk, key);
353
+ }
354
+ copyObject(disk, body) {
355
+ return this.service.copyObject(disk, body.from, body.to);
356
+ }
357
+ moveObject(disk, body) {
358
+ return this.service.moveObject(disk, body.from, body.to);
359
+ }
360
+ abortUpload(id) {
361
+ return this.service.abortUpload(id);
362
+ }
363
+ deleteLibraryRecord(id) {
364
+ return this.service.deleteLibraryRecord(id);
365
+ }
366
+ };
367
+ _ts_decorate2([
368
+ (0, import_common2.Delete)("disks/:disk/object"),
369
+ (0, import_common2.HttpCode)(204),
370
+ _ts_param2(0, (0, import_common2.Param)("disk")),
371
+ _ts_param2(1, (0, import_common2.Query)("key")),
372
+ _ts_metadata2("design:type", Function),
373
+ _ts_metadata2("design:paramtypes", [
374
+ String,
375
+ String
376
+ ]),
377
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
378
+ ], MediaConsoleActionsController.prototype, "deleteObject", null);
379
+ _ts_decorate2([
380
+ (0, import_common2.Post)("disks/:disk/copy"),
381
+ (0, import_common2.HttpCode)(204),
382
+ _ts_param2(0, (0, import_common2.Param)("disk")),
383
+ _ts_param2(1, (0, import_common2.Body)()),
384
+ _ts_metadata2("design:type", Function),
385
+ _ts_metadata2("design:paramtypes", [
386
+ String,
387
+ typeof CopyMoveBody === "undefined" ? Object : CopyMoveBody
388
+ ]),
389
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
390
+ ], MediaConsoleActionsController.prototype, "copyObject", null);
391
+ _ts_decorate2([
392
+ (0, import_common2.Post)("disks/:disk/move"),
393
+ (0, import_common2.HttpCode)(204),
394
+ _ts_param2(0, (0, import_common2.Param)("disk")),
395
+ _ts_param2(1, (0, import_common2.Body)()),
396
+ _ts_metadata2("design:type", Function),
397
+ _ts_metadata2("design:paramtypes", [
398
+ String,
399
+ typeof CopyMoveBody === "undefined" ? Object : CopyMoveBody
400
+ ]),
401
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
402
+ ], MediaConsoleActionsController.prototype, "moveObject", null);
403
+ _ts_decorate2([
404
+ (0, import_common2.Post)("uploads/:id/abort"),
405
+ (0, import_common2.HttpCode)(204),
406
+ _ts_param2(0, (0, import_common2.Param)("id")),
407
+ _ts_metadata2("design:type", Function),
408
+ _ts_metadata2("design:paramtypes", [
409
+ String
410
+ ]),
411
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
412
+ ], MediaConsoleActionsController.prototype, "abortUpload", null);
413
+ _ts_decorate2([
414
+ (0, import_common2.Delete)("library/:id"),
415
+ (0, import_common2.HttpCode)(204),
416
+ _ts_param2(0, (0, import_common2.Param)("id")),
417
+ _ts_metadata2("design:type", Function),
418
+ _ts_metadata2("design:paramtypes", [
419
+ String
420
+ ]),
421
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
422
+ ], MediaConsoleActionsController.prototype, "deleteLibraryRecord", null);
423
+ MediaConsoleActionsController = _ts_decorate2([
424
+ (0, import_common2.Controller)(),
425
+ _ts_param2(0, (0, import_common2.Inject)(MediaConsoleService)),
426
+ _ts_metadata2("design:type", Function),
427
+ _ts_metadata2("design:paramtypes", [
428
+ typeof MediaConsoleService === "undefined" ? Object : MediaConsoleService
429
+ ])
430
+ ], MediaConsoleActionsController);
431
+
432
+ // src/server/media-console-read.controller.ts
433
+ var import_common3 = require("@nestjs/common");
434
+ function _ts_decorate3(decorators, target, key, desc) {
435
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
436
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
437
+ 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;
438
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
439
+ }
440
+ __name(_ts_decorate3, "_ts_decorate");
441
+ function _ts_metadata3(k, v) {
442
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
443
+ }
444
+ __name(_ts_metadata3, "_ts_metadata");
445
+ function _ts_param3(paramIndex, decorator) {
446
+ return function(target, key) {
447
+ decorator(target, key, paramIndex);
448
+ };
449
+ }
450
+ __name(_ts_param3, "_ts_param");
451
+ function toLimit(value) {
452
+ if (value === void 0) return void 0;
453
+ const parsed = Number(value);
454
+ return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : void 0;
455
+ }
456
+ __name(toLimit, "toLimit");
457
+ var MediaConsoleReadController = class {
458
+ static {
459
+ __name(this, "MediaConsoleReadController");
460
+ }
461
+ service;
462
+ constructor(service) {
463
+ this.service = service;
464
+ }
465
+ disks() {
466
+ return this.service.listDisks();
467
+ }
468
+ objects(disk, prefix, cursor, limit) {
469
+ const limitValue = toLimit(limit);
470
+ return this.service.listObjects(disk, {
471
+ ...prefix ? {
472
+ prefix
473
+ } : {},
474
+ ...cursor ? {
475
+ cursor
476
+ } : {},
477
+ ...limitValue !== void 0 ? {
478
+ limit: limitValue
479
+ } : {}
480
+ });
481
+ }
482
+ object(disk, key) {
483
+ return this.service.objectDetail(disk, key);
484
+ }
485
+ uploads(disk, prefix) {
486
+ return this.service.listUploads({
487
+ ...disk ? {
488
+ disk
489
+ } : {},
490
+ ...prefix ? {
491
+ prefix
492
+ } : {}
493
+ });
494
+ }
495
+ upload(id) {
496
+ return this.service.uploadDetail(id);
497
+ }
498
+ collections() {
499
+ return this.service.listCollections();
500
+ }
501
+ library(collection, disk, cursor, limit) {
502
+ const limitValue = toLimit(limit);
503
+ return this.service.listLibrary({
504
+ ...collection ? {
505
+ collection
506
+ } : {},
507
+ ...disk ? {
508
+ disk
509
+ } : {},
510
+ ...cursor ? {
511
+ cursor
512
+ } : {},
513
+ ...limitValue !== void 0 ? {
514
+ limit: limitValue
515
+ } : {}
516
+ });
517
+ }
518
+ libraryRecord(id) {
519
+ return this.service.libraryDetail(id);
520
+ }
521
+ topology() {
522
+ return this.service.topology();
523
+ }
524
+ };
525
+ _ts_decorate3([
526
+ (0, import_common3.Get)("disks"),
527
+ _ts_metadata3("design:type", Function),
528
+ _ts_metadata3("design:paramtypes", []),
529
+ _ts_metadata3("design:returntype", typeof DiskListResponse === "undefined" ? Object : DiskListResponse)
530
+ ], MediaConsoleReadController.prototype, "disks", null);
531
+ _ts_decorate3([
532
+ (0, import_common3.Get)("disks/:disk/objects"),
533
+ _ts_param3(0, (0, import_common3.Param)("disk")),
534
+ _ts_param3(1, (0, import_common3.Query)("prefix")),
535
+ _ts_param3(2, (0, import_common3.Query)("cursor")),
536
+ _ts_param3(3, (0, import_common3.Query)("limit")),
537
+ _ts_metadata3("design:type", Function),
538
+ _ts_metadata3("design:paramtypes", [
539
+ String,
540
+ String,
541
+ String,
542
+ String
543
+ ]),
544
+ _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
545
+ ], MediaConsoleReadController.prototype, "objects", null);
546
+ _ts_decorate3([
547
+ (0, import_common3.Get)("disks/:disk/object"),
548
+ _ts_param3(0, (0, import_common3.Param)("disk")),
549
+ _ts_param3(1, (0, import_common3.Query)("key")),
550
+ _ts_metadata3("design:type", Function),
551
+ _ts_metadata3("design:paramtypes", [
552
+ String,
553
+ String
554
+ ]),
555
+ _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
556
+ ], MediaConsoleReadController.prototype, "object", null);
557
+ _ts_decorate3([
558
+ (0, import_common3.Get)("uploads"),
559
+ _ts_param3(0, (0, import_common3.Query)("disk")),
560
+ _ts_param3(1, (0, import_common3.Query)("prefix")),
561
+ _ts_metadata3("design:type", Function),
562
+ _ts_metadata3("design:paramtypes", [
563
+ String,
564
+ String
565
+ ]),
566
+ _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
567
+ ], MediaConsoleReadController.prototype, "uploads", null);
568
+ _ts_decorate3([
569
+ (0, import_common3.Get)("uploads/:id"),
570
+ _ts_param3(0, (0, import_common3.Param)("id")),
571
+ _ts_metadata3("design:type", Function),
572
+ _ts_metadata3("design:paramtypes", [
573
+ String
574
+ ]),
575
+ _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
576
+ ], MediaConsoleReadController.prototype, "upload", null);
577
+ _ts_decorate3([
578
+ (0, import_common3.Get)("library/collections"),
579
+ _ts_metadata3("design:type", Function),
580
+ _ts_metadata3("design:paramtypes", []),
581
+ _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
582
+ ], MediaConsoleReadController.prototype, "collections", null);
583
+ _ts_decorate3([
584
+ (0, import_common3.Get)("library"),
585
+ _ts_param3(0, (0, import_common3.Query)("collection")),
586
+ _ts_param3(1, (0, import_common3.Query)("disk")),
587
+ _ts_param3(2, (0, import_common3.Query)("cursor")),
588
+ _ts_param3(3, (0, import_common3.Query)("limit")),
589
+ _ts_metadata3("design:type", Function),
590
+ _ts_metadata3("design:paramtypes", [
591
+ String,
592
+ String,
593
+ String,
594
+ String
595
+ ]),
596
+ _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
597
+ ], MediaConsoleReadController.prototype, "library", null);
598
+ _ts_decorate3([
599
+ (0, import_common3.Get)("library/:id"),
600
+ _ts_param3(0, (0, import_common3.Param)("id")),
601
+ _ts_metadata3("design:type", Function),
602
+ _ts_metadata3("design:paramtypes", [
603
+ String
604
+ ]),
605
+ _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
606
+ ], MediaConsoleReadController.prototype, "libraryRecord", null);
607
+ _ts_decorate3([
608
+ (0, import_common3.Get)("topology"),
609
+ _ts_metadata3("design:type", Function),
610
+ _ts_metadata3("design:paramtypes", []),
611
+ _ts_metadata3("design:returntype", typeof Topology === "undefined" ? Object : Topology)
612
+ ], MediaConsoleReadController.prototype, "topology", null);
613
+ MediaConsoleReadController = _ts_decorate3([
614
+ (0, import_common3.Controller)(),
615
+ _ts_param3(0, (0, import_common3.Inject)(MediaConsoleService)),
616
+ _ts_metadata3("design:type", Function),
617
+ _ts_metadata3("design:paramtypes", [
618
+ typeof MediaConsoleService === "undefined" ? Object : MediaConsoleService
619
+ ])
620
+ ], MediaConsoleReadController);
621
+
622
+ // src/server/media-console-api.module.ts
623
+ function _ts_decorate4(decorators, target, key, desc) {
624
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
625
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
626
+ 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;
627
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
628
+ }
629
+ __name(_ts_decorate4, "_ts_decorate");
630
+ var MediaConsoleApiModule = class _MediaConsoleApiModule {
631
+ static {
632
+ __name(this, "MediaConsoleApiModule");
633
+ }
634
+ static register(actions) {
635
+ return {
636
+ module: _MediaConsoleApiModule,
637
+ controllers: actions ? [
638
+ MediaConsoleReadController,
639
+ MediaConsoleActionsController
640
+ ] : [
641
+ MediaConsoleReadController
642
+ ],
643
+ providers: [
644
+ MediaConsoleService,
645
+ {
646
+ provide: MEDIA_DASHBOARD_ACTIONS,
647
+ useValue: actions
648
+ }
649
+ ],
650
+ exports: [
651
+ MediaConsoleService
652
+ ]
653
+ };
654
+ }
655
+ };
656
+ MediaConsoleApiModule = _ts_decorate4([
657
+ (0, import_common4.Module)({})
658
+ ], MediaConsoleApiModule);
659
+
660
+ // src/server/media-dashboard-ui.controller.ts
661
+ var import_node_fs = require("fs");
662
+ var import_node_path = require("path");
663
+ var import_node_url = require("url");
664
+ var import_common5 = require("@nestjs/common");
665
+ function _ts_decorate5(decorators, target, key, desc) {
666
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
667
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
668
+ 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;
669
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
670
+ }
671
+ __name(_ts_decorate5, "_ts_decorate");
672
+ function _ts_metadata4(k, v) {
673
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
674
+ }
675
+ __name(_ts_metadata4, "_ts_metadata");
676
+ function _ts_param4(paramIndex, decorator) {
677
+ return function(target, key) {
678
+ decorator(target, key, paramIndex);
679
+ };
680
+ }
681
+ __name(_ts_param4, "_ts_param");
682
+ var BUILD_BASE = "/media";
683
+ function spaDir() {
684
+ return (0, import_node_url.fileURLToPath)(new URL("../spa", importMetaUrl));
685
+ }
686
+ __name(spaDir, "spaDir");
687
+ var CONTENT_TYPES = {
688
+ ".js": "text/javascript; charset=utf-8",
689
+ ".css": "text/css; charset=utf-8",
690
+ ".map": "application/json; charset=utf-8",
691
+ ".svg": "image/svg+xml",
692
+ ".json": "application/json; charset=utf-8",
693
+ ".woff2": "font/woff2",
694
+ ".ico": "image/x-icon"
695
+ };
696
+ var MediaDashboardUiController = class {
697
+ static {
698
+ __name(this, "MediaDashboardUiController");
699
+ }
700
+ basePath;
701
+ apiBasePath;
702
+ dir = spaDir();
703
+ constructor(basePath, apiBasePath) {
704
+ this.basePath = basePath;
705
+ this.apiBasePath = apiBasePath;
706
+ }
707
+ // index.html references hash-named bundles, so it MUST NOT be cached (stale bundle = "stuck
708
+ // loading after a deploy"). The hashed assets below are immutable.
709
+ index() {
710
+ const indexPath = (0, import_node_path.join)(this.dir, "index.html");
711
+ if (!(0, import_node_fs.existsSync)(indexPath)) {
712
+ throw new import_common5.NotFoundException("Console SPA is not built. Run the package build.");
713
+ }
714
+ const html = (0, import_node_fs.readFileSync)(indexPath, "utf8").replaceAll(`="${BUILD_BASE}/`, `="${this.basePath}/`);
715
+ const inject = `<script>window.__MEDIA_BASE__='${this.basePath}';window.__MEDIA_API__='${this.apiBasePath}';</script>`;
716
+ return html.includes("</head>") ? html.replace("</head>", `${inject}</head>`) : inject + html;
717
+ }
718
+ asset(file) {
719
+ const safe = (0, import_node_path.basename)(file);
720
+ if (safe !== file) throw new import_common5.NotFoundException();
721
+ const root = (0, import_node_path.resolve)(this.dir, "assets");
722
+ const assetPath = (0, import_node_path.resolve)(root, safe);
723
+ if (!assetPath.startsWith(root + import_node_path.sep) || !(0, import_node_fs.existsSync)(assetPath)) {
724
+ throw new import_common5.NotFoundException();
725
+ }
726
+ const type = CONTENT_TYPES[(0, import_node_path.extname)(safe)] ?? "application/octet-stream";
727
+ return new import_common5.StreamableFile((0, import_node_fs.readFileSync)(assetPath), {
728
+ type
729
+ });
730
+ }
731
+ };
732
+ _ts_decorate5([
733
+ (0, import_common5.Get)(),
734
+ (0, import_common5.Header)("Content-Type", "text/html; charset=utf-8"),
735
+ (0, import_common5.Header)("Cache-Control", "no-store, must-revalidate"),
736
+ _ts_metadata4("design:type", Function),
737
+ _ts_metadata4("design:paramtypes", []),
738
+ _ts_metadata4("design:returntype", String)
739
+ ], MediaDashboardUiController.prototype, "index", null);
740
+ _ts_decorate5([
741
+ (0, import_common5.Get)("assets/:file"),
742
+ (0, import_common5.Header)("Cache-Control", "public, max-age=31536000, immutable"),
743
+ _ts_param4(0, (0, import_common5.Param)("file")),
744
+ _ts_metadata4("design:type", Function),
745
+ _ts_metadata4("design:paramtypes", [
746
+ String
747
+ ]),
748
+ _ts_metadata4("design:returntype", typeof import_common5.StreamableFile === "undefined" ? Object : import_common5.StreamableFile)
749
+ ], MediaDashboardUiController.prototype, "asset", null);
750
+ MediaDashboardUiController = _ts_decorate5([
751
+ (0, import_common5.Controller)(),
752
+ _ts_param4(0, (0, import_common5.Inject)(MEDIA_DASHBOARD_BASE_PATH)),
753
+ _ts_param4(1, (0, import_common5.Inject)(MEDIA_DASHBOARD_API_PATH)),
754
+ _ts_metadata4("design:type", Function),
755
+ _ts_metadata4("design:paramtypes", [
756
+ String,
757
+ String
758
+ ])
759
+ ], MediaDashboardUiController);
760
+
761
+ // src/server/media-dashboard.module.ts
762
+ function _ts_decorate6(decorators, target, key, desc) {
763
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
764
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
765
+ 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;
766
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
767
+ }
768
+ __name(_ts_decorate6, "_ts_decorate");
769
+ function normalize(path) {
770
+ return `/${path.replace(/^\/+|\/+$/g, "")}`;
771
+ }
772
+ __name(normalize, "normalize");
773
+ var MediaDashboardModule = class _MediaDashboardModule {
774
+ static {
775
+ __name(this, "MediaDashboardModule");
776
+ }
777
+ static forRoot(options = {}) {
778
+ const basePath = normalize(options.basePath ?? "/media");
779
+ const apiBasePath = normalize(options.apiBasePath ?? `${basePath}/api`);
780
+ const actions = options.actions === true;
781
+ return {
782
+ module: _MediaDashboardModule,
783
+ imports: [
784
+ MediaConsoleApiModule.register(actions),
785
+ import_core.RouterModule.register([
786
+ {
787
+ path: basePath,
788
+ module: _MediaDashboardModule
789
+ },
790
+ {
791
+ path: apiBasePath,
792
+ module: MediaConsoleApiModule
793
+ }
794
+ ])
795
+ ],
796
+ controllers: [
797
+ MediaDashboardUiController
798
+ ],
799
+ providers: [
800
+ {
801
+ provide: MEDIA_DASHBOARD_BASE_PATH,
802
+ useValue: basePath
803
+ },
804
+ {
805
+ provide: MEDIA_DASHBOARD_API_PATH,
806
+ useValue: apiBasePath
807
+ }
808
+ ],
809
+ // Re-export the API module so its MediaConsoleService reaches importers if they want it.
810
+ exports: [
811
+ MediaConsoleApiModule
812
+ ]
813
+ };
814
+ }
815
+ };
816
+ MediaDashboardModule = _ts_decorate6([
817
+ (0, import_common6.Module)({})
818
+ ], MediaDashboardModule);
819
+ // Annotate the CommonJS export names for ESM import in node:
820
+ 0 && (module.exports = {
821
+ MEDIA_STORAGE_SHARED,
822
+ MEDIA_STORE,
823
+ MEDIA_UPLOAD_SESSIONS,
824
+ MediaConsoleApiModule,
825
+ MediaConsoleService,
826
+ MediaDashboardModule
827
+ });
828
+ //# sourceMappingURL=index.cjs.map