@adonis-agora/media 0.8.2 → 0.10.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.
- package/CHANGELOG.md +88 -0
- package/README.md +2 -2
- package/dist/providers/media_provider.d.ts.map +1 -1
- package/dist/providers/media_provider.js +138 -0
- package/dist/providers/media_provider.js.map +1 -1
- package/dist/src/content_type.d.ts +6 -1
- package/dist/src/content_type.d.ts.map +1 -1
- package/dist/src/content_type.js +102 -7
- package/dist/src/content_type.js.map +1 -1
- package/dist/src/define_config.d.ts +104 -5
- package/dist/src/define_config.d.ts.map +1 -1
- package/dist/src/define_config.js +7 -2
- package/dist/src/define_config.js.map +1 -1
- package/dist/src/diagnostics.d.ts +7 -0
- package/dist/src/diagnostics.d.ts.map +1 -1
- package/dist/src/diagnostics.js +20 -0
- package/dist/src/diagnostics.js.map +1 -1
- package/dist/src/direct_upload.d.ts +177 -0
- package/dist/src/direct_upload.d.ts.map +1 -0
- package/dist/src/direct_upload.js +299 -0
- package/dist/src/direct_upload.js.map +1 -0
- package/dist/src/direct_upload_handler.d.ts +117 -0
- package/dist/src/direct_upload_handler.d.ts.map +1 -0
- package/dist/src/direct_upload_handler.js +277 -0
- package/dist/src/direct_upload_handler.js.map +1 -0
- package/dist/src/disks/factory.d.ts +11 -3
- package/dist/src/disks/factory.d.ts.map +1 -1
- package/dist/src/disks/factory.js +5 -3
- package/dist/src/disks/factory.js.map +1 -1
- package/dist/src/disks/s3.d.ts +10 -0
- package/dist/src/disks/s3.d.ts.map +1 -1
- package/dist/src/disks/s3.js +96 -22
- package/dist/src/disks/s3.js.map +1 -1
- package/dist/src/disks/sigv4.d.ts +58 -0
- package/dist/src/disks/sigv4.d.ts.map +1 -0
- package/dist/src/disks/sigv4.js +87 -0
- package/dist/src/disks/sigv4.js.map +1 -0
- package/dist/src/disks/xml_fallback.d.ts +3 -3
- package/dist/src/disks/xml_fallback.js +3 -3
- package/dist/src/errors.d.ts +104 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +145 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hls/delivery.d.ts +112 -0
- package/dist/src/hls/delivery.d.ts.map +1 -0
- package/dist/src/hls/delivery.js +118 -0
- package/dist/src/hls/delivery.js.map +1 -0
- package/dist/src/hls/playlist.d.ts +67 -0
- package/dist/src/hls/playlist.d.ts.map +1 -0
- package/dist/src/hls/playlist.js +126 -0
- package/dist/src/hls/playlist.js.map +1 -0
- package/dist/src/index.d.ts +19 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +13 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/media_collection.d.ts +8 -1
- package/dist/src/media_collection.d.ts.map +1 -1
- package/dist/src/media_collection.js +23 -1
- package/dist/src/media_collection.js.map +1 -1
- package/dist/src/media_library.d.ts +32 -2
- package/dist/src/media_library.d.ts.map +1 -1
- package/dist/src/media_library.js +218 -11
- package/dist/src/media_library.js.map +1 -1
- package/dist/src/media_manager.d.ts +37 -2
- package/dist/src/media_manager.d.ts.map +1 -1
- package/dist/src/media_manager.js +54 -1
- package/dist/src/media_manager.js.map +1 -1
- package/dist/src/media_record.d.ts +22 -2
- package/dist/src/media_record.d.ts.map +1 -1
- package/dist/src/testing/fake_transformer.d.ts +32 -0
- package/dist/src/testing/fake_transformer.d.ts.map +1 -0
- package/dist/src/testing/fake_transformer.js +32 -0
- package/dist/src/testing/fake_transformer.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +1 -0
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/transformer.d.ts +111 -0
- package/dist/src/transformer.d.ts.map +1 -0
- package/dist/src/transformer.js +2 -0
- package/dist/src/transformer.js.map +1 -0
- package/dist/src/transformers/factory.d.ts +30 -0
- package/dist/src/transformers/factory.d.ts.map +1 -0
- package/dist/src/transformers/factory.js +34 -0
- package/dist/src/transformers/factory.js.map +1 -0
- package/dist/src/transformers/hls.d.ts +110 -0
- package/dist/src/transformers/hls.d.ts.map +1 -0
- package/dist/src/transformers/hls.js +111 -0
- package/dist/src/transformers/hls.js.map +1 -0
- package/dist/src/transformers/mediabunny.d.ts +5 -0
- package/dist/src/transformers/mediabunny.d.ts.map +1 -0
- package/dist/src/transformers/mediabunny.js +150 -0
- package/dist/src/transformers/mediabunny.js.map +1 -0
- package/dist/src/transformers/mediabunny_loader.d.ts +15 -0
- package/dist/src/transformers/mediabunny_loader.d.ts.map +1 -0
- package/dist/src/transformers/mediabunny_loader.js +21 -0
- package/dist/src/transformers/mediabunny_loader.js.map +1 -0
- package/dist/src/transformers/probe.d.ts +56 -0
- package/dist/src/transformers/probe.d.ts.map +1 -0
- package/dist/src/transformers/probe.js +32 -0
- package/dist/src/transformers/probe.js.map +1 -0
- package/dist/src/transformers/source_file.d.ts +20 -0
- package/dist/src/transformers/source_file.d.ts.map +1 -0
- package/dist/src/transformers/source_file.js +30 -0
- package/dist/src/transformers/source_file.js.map +1 -0
- package/dist/src/types.d.ts +80 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/stubs/config/media.stub +12 -0
- package/package.json +11 -7
- package/LICENSE +0 -21
|
@@ -7,6 +7,8 @@ import { processors } from './processors/factory.js';
|
|
|
7
7
|
import type { ImageProcessorFactory } from './processors/factory.js';
|
|
8
8
|
import { stores } from './stores/factory.js';
|
|
9
9
|
import type { LucidStoreConfig, StoreContext, StoreFactory } from './stores/factory.js';
|
|
10
|
+
import { transformers } from './transformers/factory.js';
|
|
11
|
+
import type { DirectUploadPolicy } from './types.js';
|
|
10
12
|
import type { UploadMode } from './upload_mode.js';
|
|
11
13
|
import { uploadSessions } from './upload_sessions/factory.js';
|
|
12
14
|
import type { LucidUploadSessionStoreConfig, UploadSessionStoreContext, UploadSessionStoreFactory } from './upload_sessions/factory.js';
|
|
@@ -42,6 +44,76 @@ export interface MediaUploadsConfig {
|
|
|
42
44
|
* disabled and no session store is built.
|
|
43
45
|
*/
|
|
44
46
|
resumable?: MediaResumableConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Session-backed direct upload settings (`media.direct`) — browser→S3 multipart through presigned
|
|
49
|
+
* part URLs, with the session (uploadId, part size, confirmed ETags) persisted server-side so an
|
|
50
|
+
* interrupted upload resumes after a page reload. Present ⇒ `media.direct` is available; when
|
|
51
|
+
* `routes.enabled`, the provider mounts the JSON endpoints. Absent ⇒ disabled, no session store
|
|
52
|
+
* is built. See {@link MediaDirectUploadConfig} for how this relates to TUS.
|
|
53
|
+
*/
|
|
54
|
+
direct?: MediaDirectUploadConfig;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Session-backed direct upload configuration. The session store is the SAME SPI (and, with
|
|
58
|
+
* `uploadSessions.lucid()`, the same tables) the resumable (TUS) subsystem uses — the two flows are
|
|
59
|
+
* complements, not rivals: TUS streams every chunk THROUGH the app (works on any disk, byte-exact
|
|
60
|
+
* resume), while direct hands the browser presigned URLs and the bytes never touch the app (S3-only,
|
|
61
|
+
* resumes at part granularity, needs bucket CORS exposing `ETag`). For video-sized files on S3,
|
|
62
|
+
* direct halves the total bandwidth.
|
|
63
|
+
*/
|
|
64
|
+
export interface MediaDirectUploadConfig {
|
|
65
|
+
/**
|
|
66
|
+
* Name of the session store (a key of {@link stores} below). Omit to use the in-memory store
|
|
67
|
+
* (single-process, non-durable — sessions won't survive a restart, uploads in flight will).
|
|
68
|
+
*/
|
|
69
|
+
store?: string;
|
|
70
|
+
/** Named session stores, built with the {@link uploadSessions} factory (lazy peers). */
|
|
71
|
+
stores?: Record<string, UploadSessionStoreFactory>;
|
|
72
|
+
/**
|
|
73
|
+
* Multipart part size in bytes. Falls back to `uploads.partSize`, then 20 MiB. S3 requires at
|
|
74
|
+
* least 5 MiB and at most 10,000 parts per upload.
|
|
75
|
+
*/
|
|
76
|
+
partSize?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Lifetime of presigned part URLs, in seconds. Falls back to `uploads.presignTtlSeconds`, then
|
|
79
|
+
* 3600. Expiry never strands an upload: `status()` re-issues fresh URLs for pending parts.
|
|
80
|
+
*/
|
|
81
|
+
presignTtlSeconds?: number;
|
|
82
|
+
/** Session lifetime in seconds. Omit for sessions that never expire. */
|
|
83
|
+
sessionTtlSeconds?: number;
|
|
84
|
+
/** Mount the built-in direct-session HTTP routes. Opt-in. */
|
|
85
|
+
routes?: {
|
|
86
|
+
/** Register the routes. Default false. */
|
|
87
|
+
enabled?: boolean;
|
|
88
|
+
/** Path prefix for the routes. Default `/media/uploads/direct/sessions`. */
|
|
89
|
+
prefix?: string;
|
|
90
|
+
/** Disk uploads land on. Defaults to the media default disk (must be multipart-capable). */
|
|
91
|
+
disk?: string;
|
|
92
|
+
/** Reject initiations whose declared `size` exceeds this many bytes. */
|
|
93
|
+
maxSize?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Collection these uploads are destined for. Set it to have `initiate` reject a declared
|
|
96
|
+
* `contentType` outside that collection's `acceptsMimeTypes` — before the multipart upload
|
|
97
|
+
* even opens. The collection config remains the single source of truth; nothing is restated
|
|
98
|
+
* here. Omit to accept any type (size limits still apply).
|
|
99
|
+
*/
|
|
100
|
+
collection?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Middleware applied to every built-in direct-session route (the provider passes them straight
|
|
103
|
+
* to the AdonisJS route group). Typed framework-neutrally as `unknown[]` so this config never
|
|
104
|
+
* imports AdonisJS — guard the routes here (e.g. `middleware.auth()`), since the handler itself
|
|
105
|
+
* performs NO authorization.
|
|
106
|
+
*/
|
|
107
|
+
middleware?: readonly unknown[];
|
|
108
|
+
/**
|
|
109
|
+
* Lazily load a {@link DirectUploadPolicy} that owns the app-specific decisions (key resolution,
|
|
110
|
+
* what the upload becomes on completion, error→HTTP mapping). A thunk so the policy module — and
|
|
111
|
+
* anything it imports — loads only when the routes mount. The provider reads its default export.
|
|
112
|
+
*/
|
|
113
|
+
policy?: () => Promise<{
|
|
114
|
+
default: DirectUploadPolicy<unknown, unknown>;
|
|
115
|
+
}>;
|
|
116
|
+
};
|
|
45
117
|
}
|
|
46
118
|
/**
|
|
47
119
|
* Resumable (TUS) upload configuration. The session store persists offset/length/metadata/expiry so
|
|
@@ -147,8 +219,8 @@ export interface MediaConfig {
|
|
|
147
219
|
* so the heavy peer is imported lazily. Required only if any collection defines conversions.
|
|
148
220
|
*/
|
|
149
221
|
imageProcessor?: ImageProcessor | ImageProcessorFactory;
|
|
150
|
-
/** Collection definitions (MIME whitelist, single-file replace, conversions). */
|
|
151
|
-
collections?: MediaCollectionConfig[];
|
|
222
|
+
/** Collection definitions (MIME whitelist, single-file replace, conversions, transformers). */
|
|
223
|
+
collections?: readonly MediaCollectionConfig[];
|
|
152
224
|
/** Key prefix for column attachments created via the `AttachmentManager`. Default `attachments`. */
|
|
153
225
|
attachmentKeyPrefix?: string;
|
|
154
226
|
/** Emit `agora:media:*` diagnostics events (default true). */
|
|
@@ -158,8 +230,35 @@ export interface MediaConfig {
|
|
|
158
230
|
/** How stored media is served back (`auto`/`public`/`signed`/`proxy` + signed-URL TTL). */
|
|
159
231
|
delivery?: MediaDeliveryConfig;
|
|
160
232
|
}
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Identity helper giving `config/media.ts` full type-checking. The `const` type parameter keeps
|
|
235
|
+
* collection/conversion/transformer names as literal types, so {@link InferConversions} /
|
|
236
|
+
* {@link InferTransformers} can extract them from `typeof config` — no `as const` needed.
|
|
237
|
+
*/
|
|
238
|
+
export declare function defineConfig<const T extends MediaConfig>(config?: T): T;
|
|
239
|
+
/** The collection literal types of a config (helper for the `Infer*` utilities). */
|
|
240
|
+
type CollectionOf<T extends MediaConfig> = T['collections'] extends readonly (infer C extends MediaCollectionConfig)[] ? C : never;
|
|
241
|
+
/**
|
|
242
|
+
* Union of the transformer names a config declares — for typing job payloads, `transform()` call
|
|
243
|
+
* sites, and route params against the config instead of restating strings:
|
|
244
|
+
*
|
|
245
|
+
* ```ts
|
|
246
|
+
* const config = defineConfig({
|
|
247
|
+
* collections: [{ name: 'videos', transformers: [transformers.hls(), transformers.probe()] }],
|
|
248
|
+
* })
|
|
249
|
+
* type AppTransformer = InferTransformers<typeof config> // 'hls' | 'probe'
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export type InferTransformers<T extends MediaConfig> = NonNullable<CollectionOf<T>['transformers']>[number]['name'];
|
|
253
|
+
/**
|
|
254
|
+
* Union of every conversion name a config declares — image presets and transformers alike, since
|
|
255
|
+
* both persist under `record.conversions`:
|
|
256
|
+
*
|
|
257
|
+
* ```ts
|
|
258
|
+
* type AppConversion = InferConversions<typeof config> // 'thumb' | 'og' | 'hls' | 'probe'
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export type InferConversions<T extends MediaConfig> = NonNullable<CollectionOf<T>['conversions']>[number]['name'] | InferTransformers<T>;
|
|
262
|
+
export { stores, processors, disks, uploadSessions, transformers };
|
|
164
263
|
export type { StoreContext, StoreFactory, LucidStoreConfig, ImageProcessorFactory, DiskFactory, S3DiskConfig, S3Credentials, UploadMode, DeliveryMode, UploadSessionStoreContext, UploadSessionStoreFactory, LucidUploadSessionStoreConfig, };
|
|
165
264
|
//# sourceMappingURL=define_config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define_config.d.ts","sourceRoot":"","sources":["../../src/define_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,M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AAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAC3D,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AACnE,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,6BAA6B,GAC9B,CAAC"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { disks } from './disks/factory.js';
|
|
2
2
|
import { processors } from './processors/factory.js';
|
|
3
3
|
import { stores } from './stores/factory.js';
|
|
4
|
+
import { transformers } from './transformers/factory.js';
|
|
4
5
|
import { uploadSessions } from './upload_sessions/factory.js';
|
|
5
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Identity helper giving `config/media.ts` full type-checking. The `const` type parameter keeps
|
|
8
|
+
* collection/conversion/transformer names as literal types, so {@link InferConversions} /
|
|
9
|
+
* {@link InferTransformers} can extract them from `typeof config` — no `as const` needed.
|
|
10
|
+
*/
|
|
6
11
|
export function defineConfig(config = {}) {
|
|
7
12
|
return config;
|
|
8
13
|
}
|
|
9
|
-
export { stores, processors, disks, uploadSessions };
|
|
14
|
+
export { stores, processors, disks, uploadSessions, transformers };
|
|
10
15
|
//# sourceMappingURL=define_config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define_config.js","sourceRoot":"","sources":["../../src/define_config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI3C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"define_config.js","sourceRoot":"","sources":["../../src/define_config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI3C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAoO9D;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAA8B,SAAY,EAAO;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC;AAmCD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -91,4 +91,11 @@ export interface MediaDiagnosticPayloads {
|
|
|
91
91
|
* into the library.
|
|
92
92
|
*/
|
|
93
93
|
export declare function publishMedia<E extends MediaDiagnosticEvent>(event: E, payload: MediaDiagnosticPayloads[E]): void;
|
|
94
|
+
/**
|
|
95
|
+
* Wrap a unit of media work in a structural trace span (`upload.policy.*` and friends). When a
|
|
96
|
+
* diagnostics trace slot is installed it observes the call (lib hard-coded to `'media'`); otherwise
|
|
97
|
+
* the wrapped function runs directly. Unlike {@link publishMedia}, errors are NOT swallowed — a
|
|
98
|
+
* traced policy hook must surface its failure to the caller so the handler can map it.
|
|
99
|
+
*/
|
|
100
|
+
export declare function traceMedia<T>(event: string, fn: () => T, payload?: unknown): T;
|
|
94
101
|
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,eAAO,MAAM,uBAAuB,6JAU1B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M9E"}
|
package/dist/src/diagnostics.js
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* and emitting is an inert no-op.
|
|
6
6
|
*/
|
|
7
7
|
const EMIT_SLOT = Symbol.for('@agora/diagnostics:emit');
|
|
8
|
+
/**
|
|
9
|
+
* The `@adonis-agora/diagnostics` trace capability, published on this global slot. Like
|
|
10
|
+
* {@link EMIT_SLOT} it is read STRUCTURALLY — media never imports the diagnostics package.
|
|
11
|
+
* A trace slot wraps a unit of work so an observer can time/inspect it; when no slot is
|
|
12
|
+
* installed the wrapped function simply runs and its result (or error) passes through.
|
|
13
|
+
*/
|
|
14
|
+
const TRACE_SLOT = Symbol.for('@agora/diagnostics:trace');
|
|
8
15
|
/**
|
|
9
16
|
* Every media milestone published on `agora:media:<event>`. The single runtime source for the
|
|
10
17
|
* {@link MediaDiagnosticEvent} union — a Telescope watcher iterates this to subscribe/claim.
|
|
@@ -87,4 +94,17 @@ export function publishMedia(event, payload) {
|
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Wrap a unit of media work in a structural trace span (`upload.policy.*` and friends). When a
|
|
99
|
+
* diagnostics trace slot is installed it observes the call (lib hard-coded to `'media'`); otherwise
|
|
100
|
+
* the wrapped function runs directly. Unlike {@link publishMedia}, errors are NOT swallowed — a
|
|
101
|
+
* traced policy hook must surface its failure to the caller so the handler can map it.
|
|
102
|
+
*/
|
|
103
|
+
export function traceMedia(event, fn, payload) {
|
|
104
|
+
const trace = globalThis[TRACE_SLOT];
|
|
105
|
+
if (typeof trace === 'function') {
|
|
106
|
+
return trace('media', event, fn, payload);
|
|
107
|
+
}
|
|
108
|
+
return fn();
|
|
109
|
+
}
|
|
90
110
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,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AACJ,CAAC;AAED,+IAA+I;AAC/I,MAAM,UAAU,wBAAwB,CAAC,KAAa;IACpD,MAAM,QAAQ,GAAI,UAAsC,CAAC,WAAW,CAEvD,CAAC;IACd,OAAO,QAAQ,EAAE,GAAG,CAAC,SAAS,KAAK,EAAE,CAAC,IAAI,KAAK,CAAC;AAClD,CAAC;AA4ED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAQ,EACR,OAAmC;IAEnC,MAAM,IAAI,GAAI,UAAsC,CAAC,SAAS,CAAuB,CAAC;IACtF,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,iDAAiD;QACnD,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAI,KAAa,EAAE,EAAW,EAAE,OAAiB;IACzE,MAAM,KAAK,GAAI,UAAsC,CAAC,UAAU,CAAwB,CAAC;IACzF,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,EAAE,EAAE,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { MediaCollectionRegistry } from './media_collection.js';
|
|
2
|
+
import type { UploadSession, UploadSessionListFilter, UploadSessionStore } from './resumable_upload.js';
|
|
3
|
+
import type { StorageManager } from './storage_manager.js';
|
|
4
|
+
import type { MultipartPart } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Default part size: 20 MiB. Between S3's 5 MiB minimum and a reasonable payload per browser `PUT`;
|
|
7
|
+
* with S3's 10,000-part cap it covers files up to ~195 GiB. Larger than the proxy default (8 MiB)
|
|
8
|
+
* on purpose — direct parts don't occupy app memory, so the only cost of a bigger part is a bigger
|
|
9
|
+
* retry unit.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_DIRECT_PART_SIZE: number;
|
|
12
|
+
/** S3's minimum part size (every part but the last). Enforced at `initiate` — see {@link UploadPartSizeError}. */
|
|
13
|
+
export declare const MIN_DIRECT_PART_SIZE: number;
|
|
14
|
+
/** S3's cap on parts per multipart upload. */
|
|
15
|
+
export declare const MAX_DIRECT_PARTS = 10000;
|
|
16
|
+
/** A part the client should `PUT`: its number and the presigned URL that authorizes exactly that. */
|
|
17
|
+
export interface DirectUploadPartUrl {
|
|
18
|
+
partNumber: number;
|
|
19
|
+
url: string;
|
|
20
|
+
}
|
|
21
|
+
export interface DirectUploadInitiateInput {
|
|
22
|
+
/** Disk name; defaults to the manager's default disk. Must be multipart-capable. */
|
|
23
|
+
disk?: string | undefined;
|
|
24
|
+
/** Final object key. Resolve it server-side (per user/tenant) — never trust a client-sent key. */
|
|
25
|
+
key: string;
|
|
26
|
+
/** Content-Type stamped on the final object, and checked against `collection`'s whitelist. */
|
|
27
|
+
contentType?: string | undefined;
|
|
28
|
+
/** Total file size in bytes. Required: it fixes the part count both sides slice by. */
|
|
29
|
+
size: number;
|
|
30
|
+
/**
|
|
31
|
+
* Collection this upload is destined for. When the manager holds a collection registry, the
|
|
32
|
+
* declared `contentType` is checked against that collection's `acceptsMimeTypes` HERE — before
|
|
33
|
+
* the multipart upload is opened, before a single byte moves. Mirrors the TUS `POST` gate: fast
|
|
34
|
+
* feedback and bandwidth economy, not the security boundary — `attachExisting` re-validates the
|
|
35
|
+
* real bytes at attach time.
|
|
36
|
+
*/
|
|
37
|
+
collection?: string | undefined;
|
|
38
|
+
/** Public/private visibility for the final object. */
|
|
39
|
+
visibility?: 'public' | 'private' | undefined;
|
|
40
|
+
/** Override the manager's part size for this upload. Same S3 bounds apply. */
|
|
41
|
+
partSize?: number | undefined;
|
|
42
|
+
/** Extra metadata persisted on the session (keys under `direct:` are reserved). */
|
|
43
|
+
metadata?: Record<string, string> | undefined;
|
|
44
|
+
}
|
|
45
|
+
/** What {@link DirectUploadManager.initiate} hands back — everything the client needs to start `PUT`ing. */
|
|
46
|
+
export interface DirectUploadCreatedSession {
|
|
47
|
+
/** Session id — the handle for `status`/`confirmPart`/`complete`/`abort`. */
|
|
48
|
+
id: string;
|
|
49
|
+
key: string;
|
|
50
|
+
disk: string;
|
|
51
|
+
/** The agreed slice size. The client MUST cut the file with exactly this. */
|
|
52
|
+
partSize: number;
|
|
53
|
+
size: number;
|
|
54
|
+
totalParts: number;
|
|
55
|
+
/** One presigned URL per part, 1-based, in order. */
|
|
56
|
+
parts: DirectUploadPartUrl[];
|
|
57
|
+
expiresAt?: Date | undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The resume answer: what is already confirmed (ETags the server holds) and what is still pending
|
|
61
|
+
* (with FRESH presigned URLs). A client that lost its state — page reload, new tab, new device —
|
|
62
|
+
* asks this and continues from the parts that are missing, re-uploading nothing.
|
|
63
|
+
*/
|
|
64
|
+
export interface DirectUploadStatus {
|
|
65
|
+
id: string;
|
|
66
|
+
key: string;
|
|
67
|
+
disk: string;
|
|
68
|
+
partSize: number;
|
|
69
|
+
size: number;
|
|
70
|
+
totalParts: number;
|
|
71
|
+
contentType?: string | undefined;
|
|
72
|
+
/** Parts whose ETags the session holds — already uploaded and confirmed. */
|
|
73
|
+
completedParts: MultipartPart[];
|
|
74
|
+
/** Parts still missing, each with a freshly presigned URL (expiry never strands an upload). */
|
|
75
|
+
pendingParts: DirectUploadPartUrl[];
|
|
76
|
+
expiresAt?: Date | undefined;
|
|
77
|
+
}
|
|
78
|
+
export interface DirectUploadManagerOptions {
|
|
79
|
+
storage: StorageManager;
|
|
80
|
+
/**
|
|
81
|
+
* Session persistence — the SAME SPI (and, with the Lucid driver, the same tables) the resumable
|
|
82
|
+
* (TUS) subsystem uses. The store must implement `addPart`/`listParts`; both bundled drivers do.
|
|
83
|
+
*/
|
|
84
|
+
sessions: UploadSessionStore;
|
|
85
|
+
/** Collection registry (`media.collections`) for the `initiate` MIME gate. Omit ⇒ no gate here. */
|
|
86
|
+
collections?: MediaCollectionRegistry | undefined;
|
|
87
|
+
/** Default part size in bytes. Default 20 MiB ({@link DEFAULT_DIRECT_PART_SIZE}). */
|
|
88
|
+
partSize?: number | undefined;
|
|
89
|
+
/** Lifetime of presigned part URLs, in seconds. Default 3600. */
|
|
90
|
+
presignTtlSeconds?: number | undefined;
|
|
91
|
+
/** Session lifetime in seconds. Omit for sessions that never expire. */
|
|
92
|
+
sessionTtlSeconds?: number | undefined;
|
|
93
|
+
idGenerator?: (() => string) | undefined;
|
|
94
|
+
/** Injectable clock (tests drive expiry deterministically). Default `() => new Date()`. */
|
|
95
|
+
clock?: (() => Date) | undefined;
|
|
96
|
+
/** Emit `upload.*` diagnostics events (default true). */
|
|
97
|
+
emitDiagnostics?: boolean | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Session-backed direct-to-S3 multipart uploads: the browser `PUT`s every byte straight to storage
|
|
101
|
+
* through presigned part URLs, and the app only coordinates — open, presign, collect ETags, close.
|
|
102
|
+
* The app's bandwidth cost is a handful of JSON round-trips regardless of file size, which is the
|
|
103
|
+
* entire point for video-sized files: the TUS path streams every chunk THROUGH the app (2× the
|
|
104
|
+
* bytes: client→app, app→S3), where this path streams none.
|
|
105
|
+
*
|
|
106
|
+
* What this adds over the raw primitives on {@link UploadManager} (`initiateDirect` & friends) is
|
|
107
|
+
* the **persisted session**: `uploadId`, the agreed `partSize` and every confirmed part ETag live
|
|
108
|
+
* in an {@link UploadSessionStore} — the same SPI the TUS engine persists its offsets in — instead
|
|
109
|
+
* of in the client's memory. A page reload no longer orphans the upload: the client asks
|
|
110
|
+
* {@link status} and gets back the confirmed ETags plus fresh URLs for what is missing.
|
|
111
|
+
*
|
|
112
|
+
* Framework-free, like {@link ResumableUploadManager}: the `DirectUploadHandler` maps it onto HTTP
|
|
113
|
+
* and the AdonisJS provider mounts that. `MediaManager.completeDirectUploadToLibrary` bridges a
|
|
114
|
+
* finished session into the media library through `attachExisting` — where the collection's
|
|
115
|
+
* whitelist checks the REAL bytes, exactly like every other upload path.
|
|
116
|
+
*/
|
|
117
|
+
export declare class DirectUploadManager {
|
|
118
|
+
#private;
|
|
119
|
+
private readonly storage;
|
|
120
|
+
private readonly sessions;
|
|
121
|
+
private readonly collections;
|
|
122
|
+
private readonly partSize;
|
|
123
|
+
private readonly presignTtlSeconds;
|
|
124
|
+
private readonly ttlSeconds;
|
|
125
|
+
private readonly newId;
|
|
126
|
+
private readonly now;
|
|
127
|
+
private readonly emitDiagnostics;
|
|
128
|
+
constructor(options: DirectUploadManagerOptions);
|
|
129
|
+
/**
|
|
130
|
+
* Open a direct upload: validate everything that can be validated without bytes, start the native
|
|
131
|
+
* multipart upload, persist the session, and presign every part URL in one batch (presigning is
|
|
132
|
+
* local computation — see `sigv4.ts` — so a 10,000-part batch costs no S3 round-trips).
|
|
133
|
+
*/
|
|
134
|
+
initiate(input: DirectUploadInitiateInput): Promise<DirectUploadCreatedSession>;
|
|
135
|
+
/**
|
|
136
|
+
* Record one part the client finished `PUT`ing (its S3 `ETag` response header). This is what makes
|
|
137
|
+
* the session resumable: an ETag the server holds survives any client-side loss of state. Safe to
|
|
138
|
+
* retry — confirming the same part again overwrites its ETag.
|
|
139
|
+
*/
|
|
140
|
+
confirmPart(id: string, part: MultipartPart): Promise<{
|
|
141
|
+
offset: number;
|
|
142
|
+
completedParts: number;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Where the upload stands, framed for resumption: the ETags already confirmed and a FRESH
|
|
146
|
+
* presigned URL for every part still missing. After a page reload the client calls this, slices
|
|
147
|
+
* the file with the returned `partSize`, uploads only `pendingParts`, and completes.
|
|
148
|
+
*/
|
|
149
|
+
status(id: string): Promise<DirectUploadStatus>;
|
|
150
|
+
/**
|
|
151
|
+
* Assemble the parts into the final object and close the session. `parts` supplements what the
|
|
152
|
+
* session already holds (a client may hand over ETags it never got to confirm — e.g. it raced
|
|
153
|
+
* completion against its last confirms); on overlap the caller's ETag wins. Every part number in
|
|
154
|
+
* `1..totalParts` must be accounted for, or this throws {@link UploadPartsIncompleteError} naming
|
|
155
|
+
* the gaps — BEFORE the S3 round-trip that would report an opaque `InvalidPart`.
|
|
156
|
+
*
|
|
157
|
+
* This is the raw primitive (the object exists, no media record). To land in the library, use
|
|
158
|
+
* `MediaManager.completeDirectUploadToLibrary`, which chains `attachExisting` — collection
|
|
159
|
+
* whitelist against the real bytes included.
|
|
160
|
+
*/
|
|
161
|
+
complete(id: string, parts?: MultipartPart[]): Promise<{
|
|
162
|
+
key: string;
|
|
163
|
+
disk: string;
|
|
164
|
+
size: number;
|
|
165
|
+
}>;
|
|
166
|
+
/**
|
|
167
|
+
* Discard an in-flight upload: abort the native multipart upload (S3 frees the stored parts and
|
|
168
|
+
* stops charging for them) and drop the session. The S3 abort is best-effort — a bucket lifecycle
|
|
169
|
+
* rule may have already reaped the upload (`NoSuchUpload`), and a session that can no longer be
|
|
170
|
+
* aborted remotely must still be deletable locally.
|
|
171
|
+
*/
|
|
172
|
+
abort(id: string): Promise<void>;
|
|
173
|
+
/** In-progress direct sessions, optionally filtered. Empty when the store cannot enumerate. */
|
|
174
|
+
list(filter?: UploadSessionListFilter): Promise<UploadSession[]>;
|
|
175
|
+
private emit;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=direct_upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct_upload.d.ts","sourceRoot":"","sources":["../../src/direct_upload.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,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