payload-video-streaming 0.0.0-stage → 0.2.0-beta.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/LICENSE +21 -0
- package/README.md +658 -2
- package/dist/bin/args.d.ts +24 -0
- package/dist/bin/args.js +96 -0
- package/dist/bin/args.js.map +1 -0
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +17 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/bin/fake.d.ts +2 -0
- package/dist/bin/fake.js +14 -0
- package/dist/bin/fake.js.map +1 -0
- package/dist/bin/migrate.d.ts +5 -0
- package/dist/bin/migrate.js +47 -0
- package/dist/bin/migrate.js.map +1 -0
- package/dist/bin/runFake.d.ts +2 -0
- package/dist/bin/runFake.js +24 -0
- package/dist/bin/runFake.js.map +1 -0
- package/dist/blocks.d.ts +42 -0
- package/dist/blocks.js +150 -0
- package/dist/blocks.js.map +1 -0
- package/dist/collection.d.ts +10 -0
- package/dist/collection.js +550 -0
- package/dist/collection.js.map +1 -0
- package/dist/components/CaptionsManager.d.ts +9 -0
- package/dist/components/CaptionsManager.js +174 -0
- package/dist/components/CaptionsManager.js.map +1 -0
- package/dist/components/DownloadsPanel.d.ts +9 -0
- package/dist/components/DownloadsPanel.js +147 -0
- package/dist/components/DownloadsPanel.js.map +1 -0
- package/dist/components/ListUploader.d.ts +11 -0
- package/dist/components/ListUploader.js +116 -0
- package/dist/components/ListUploader.js.map +1 -0
- package/dist/components/ThumbnailCell.d.ts +5 -0
- package/dist/components/ThumbnailCell.js +28 -0
- package/dist/components/ThumbnailCell.js.map +1 -0
- package/dist/components/Uploader.d.ts +17 -0
- package/dist/components/Uploader.js +162 -0
- package/dist/components/Uploader.js.map +1 -0
- package/dist/components/VideoBlockLabel.d.ts +11 -0
- package/dist/components/VideoBlockLabel.js +86 -0
- package/dist/components/VideoBlockLabel.js.map +1 -0
- package/dist/components/VideoField.d.ts +17 -0
- package/dist/components/VideoField.js +418 -0
- package/dist/components/VideoField.js.map +1 -0
- package/dist/components/api.d.ts +46 -0
- package/dist/components/api.js +74 -0
- package/dist/components/api.js.map +1 -0
- package/dist/components/chunkedUpload.d.ts +28 -0
- package/dist/components/chunkedUpload.js +49 -0
- package/dist/components/chunkedUpload.js.map +1 -0
- package/dist/components/styles.d.ts +95 -0
- package/dist/components/styles.js +148 -0
- package/dist/components/styles.js.map +1 -0
- package/dist/components/usePluginApi.d.ts +41 -0
- package/dist/components/usePluginApi.js +21 -0
- package/dist/components/usePluginApi.js.map +1 -0
- package/dist/components/useVideoUpload.d.ts +37 -0
- package/dist/components/useVideoUpload.js +181 -0
- package/dist/components/useVideoUpload.js.map +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +29 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/provider.d.ts +331 -0
- package/dist/core/provider.js +13 -0
- package/dist/core/provider.js.map +1 -0
- package/dist/core/registry.d.ts +17 -0
- package/dist/core/registry.js +110 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/status.d.ts +15 -0
- package/dist/core/status.js +29 -0
- package/dist/core/status.js.map +1 -0
- package/dist/endpoints/index.d.ts +3 -0
- package/dist/endpoints/index.js +464 -0
- package/dist/endpoints/index.js.map +1 -0
- package/dist/env.d.ts +40 -0
- package/dist/env.js +105 -0
- package/dist/env.js.map +1 -0
- package/dist/exports/bunny.d.ts +16 -0
- package/dist/exports/bunny.js +13 -0
- package/dist/exports/bunny.js.map +1 -0
- package/dist/exports/client.d.ts +13 -0
- package/dist/exports/client.js +13 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/cloudflare.d.ts +18 -0
- package/dist/exports/cloudflare.js +15 -0
- package/dist/exports/cloudflare.js.map +1 -0
- package/dist/exports/mux.d.ts +18 -0
- package/dist/exports/mux.js +15 -0
- package/dist/exports/mux.js.map +1 -0
- package/dist/exports/react.d.ts +13 -0
- package/dist/exports/react.js +11 -0
- package/dist/exports/react.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +4 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/testing.d.ts +13 -0
- package/dist/exports/testing.js +9 -0
- package/dist/exports/testing.js.map +1 -0
- package/dist/fields.d.ts +13 -0
- package/dist/fields.js +13 -0
- package/dist/fields.js.map +1 -0
- package/dist/frontend/ClientVideo.d.ts +14 -0
- package/dist/frontend/ClientVideo.js +43 -0
- package/dist/frontend/ClientVideo.js.map +1 -0
- package/dist/frontend/Video.d.ts +32 -0
- package/dist/frontend/Video.js +73 -0
- package/dist/frontend/Video.js.map +1 -0
- package/dist/frontend/VideoIframe.d.ts +35 -0
- package/dist/frontend/VideoIframe.js +60 -0
- package/dist/frontend/VideoIframe.js.map +1 -0
- package/dist/frontend/constants.d.ts +10 -0
- package/dist/frontend/constants.js +10 -0
- package/dist/frontend/constants.js.map +1 -0
- package/dist/frontend/converters.d.ts +25 -0
- package/dist/frontend/converters.js +24 -0
- package/dist/frontend/converters.js.map +1 -0
- package/dist/frontend/source.d.ts +80 -0
- package/dist/frontend/source.js +159 -0
- package/dist/frontend/source.js.map +1 -0
- package/dist/frontend/useVideoSource.d.ts +27 -0
- package/dist/frontend/useVideoSource.js +108 -0
- package/dist/frontend/useVideoSource.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate/cfStream.d.ts +108 -0
- package/dist/migrate/cfStream.js +418 -0
- package/dist/migrate/cfStream.js.map +1 -0
- package/dist/options.d.ts +4 -0
- package/dist/options.js +90 -0
- package/dist/options.js.map +1 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/plugin.js +98 -0
- package/dist/plugin.js.map +1 -0
- package/dist/providers/bunny/client.d.ts +78 -0
- package/dist/providers/bunny/client.js +231 -0
- package/dist/providers/bunny/client.js.map +1 -0
- package/dist/providers/bunny/env.d.ts +18 -0
- package/dist/providers/bunny/env.js +31 -0
- package/dist/providers/bunny/env.js.map +1 -0
- package/dist/providers/bunny/mapping.d.ts +39 -0
- package/dist/providers/bunny/mapping.js +123 -0
- package/dist/providers/bunny/mapping.js.map +1 -0
- package/dist/providers/bunny/options.d.ts +92 -0
- package/dist/providers/bunny/options.js +85 -0
- package/dist/providers/bunny/options.js.map +1 -0
- package/dist/providers/bunny/provider.d.ts +69 -0
- package/dist/providers/bunny/provider.js +472 -0
- package/dist/providers/bunny/provider.js.map +1 -0
- package/dist/providers/bunny/signing.d.ts +61 -0
- package/dist/providers/bunny/signing.js +144 -0
- package/dist/providers/bunny/signing.js.map +1 -0
- package/dist/providers/bunny/types.d.ts +153 -0
- package/dist/providers/bunny/types.js +64 -0
- package/dist/providers/bunny/types.js.map +1 -0
- package/dist/providers/bunny/urls.d.ts +49 -0
- package/dist/providers/bunny/urls.js +70 -0
- package/dist/providers/bunny/urls.js.map +1 -0
- package/dist/providers/bunny/webhook.d.ts +32 -0
- package/dist/providers/bunny/webhook.js +75 -0
- package/dist/providers/bunny/webhook.js.map +1 -0
- package/dist/providers/cloudflare/client.d.ts +93 -0
- package/dist/providers/cloudflare/client.js +436 -0
- package/dist/providers/cloudflare/client.js.map +1 -0
- package/dist/providers/cloudflare/env.d.ts +22 -0
- package/dist/providers/cloudflare/env.js +57 -0
- package/dist/providers/cloudflare/env.js.map +1 -0
- package/dist/providers/cloudflare/mapping.d.ts +15 -0
- package/dist/providers/cloudflare/mapping.js +95 -0
- package/dist/providers/cloudflare/mapping.js.map +1 -0
- package/dist/providers/cloudflare/options.d.ts +104 -0
- package/dist/providers/cloudflare/options.js +91 -0
- package/dist/providers/cloudflare/options.js.map +1 -0
- package/dist/providers/cloudflare/provider.d.ts +62 -0
- package/dist/providers/cloudflare/provider.js +434 -0
- package/dist/providers/cloudflare/provider.js.map +1 -0
- package/dist/providers/cloudflare/signing.d.ts +41 -0
- package/dist/providers/cloudflare/signing.js +97 -0
- package/dist/providers/cloudflare/signing.js.map +1 -0
- package/dist/providers/cloudflare/tus.d.ts +24 -0
- package/dist/providers/cloudflare/tus.js +55 -0
- package/dist/providers/cloudflare/tus.js.map +1 -0
- package/dist/providers/cloudflare/types.d.ts +156 -0
- package/dist/providers/cloudflare/types.js +14 -0
- package/dist/providers/cloudflare/types.js.map +1 -0
- package/dist/providers/cloudflare/urls.d.ts +55 -0
- package/dist/providers/cloudflare/urls.js +87 -0
- package/dist/providers/cloudflare/urls.js.map +1 -0
- package/dist/providers/cloudflare/webhook.d.ts +36 -0
- package/dist/providers/cloudflare/webhook.js +83 -0
- package/dist/providers/cloudflare/webhook.js.map +1 -0
- package/dist/providers/mux/client.d.ts +82 -0
- package/dist/providers/mux/client.js +283 -0
- package/dist/providers/mux/client.js.map +1 -0
- package/dist/providers/mux/env.d.ts +21 -0
- package/dist/providers/mux/env.js +61 -0
- package/dist/providers/mux/env.js.map +1 -0
- package/dist/providers/mux/mapping.d.ts +38 -0
- package/dist/providers/mux/mapping.js +111 -0
- package/dist/providers/mux/mapping.js.map +1 -0
- package/dist/providers/mux/options.d.ts +96 -0
- package/dist/providers/mux/options.js +83 -0
- package/dist/providers/mux/options.js.map +1 -0
- package/dist/providers/mux/provider.d.ts +62 -0
- package/dist/providers/mux/provider.js +546 -0
- package/dist/providers/mux/provider.js.map +1 -0
- package/dist/providers/mux/signing.d.ts +45 -0
- package/dist/providers/mux/signing.js +84 -0
- package/dist/providers/mux/signing.js.map +1 -0
- package/dist/providers/mux/types.d.ts +173 -0
- package/dist/providers/mux/types.js +42 -0
- package/dist/providers/mux/types.js.map +1 -0
- package/dist/providers/mux/urls.d.ts +58 -0
- package/dist/providers/mux/urls.js +59 -0
- package/dist/providers/mux/urls.js.map +1 -0
- package/dist/providers/mux/webhook.d.ts +38 -0
- package/dist/providers/mux/webhook.js +115 -0
- package/dist/providers/mux/webhook.js.map +1 -0
- package/dist/service.d.ts +166 -0
- package/dist/service.js +857 -0
- package/dist/service.js.map +1 -0
- package/dist/testing/bunny.d.ts +113 -0
- package/dist/testing/bunny.js +776 -0
- package/dist/testing/bunny.js.map +1 -0
- package/dist/testing/cloudflare.d.ts +101 -0
- package/dist/testing/cloudflare.js +913 -0
- package/dist/testing/cloudflare.js.map +1 -0
- package/dist/testing/index.d.ts +45 -0
- package/dist/testing/index.js +42 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mux.d.ts +139 -0
- package/dist/testing/mux.js +1053 -0
- package/dist/testing/mux.js.map +1 -0
- package/dist/testing/types.d.ts +90 -0
- package/dist/testing/types.js +9 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/access.d.ts +22 -0
- package/dist/utils/access.js +66 -0
- package/dist/utils/access.js.map +1 -0
- package/dist/utils/localReq.d.ts +11 -0
- package/dist/utils/localReq.js +23 -0
- package/dist/utils/localReq.js.map +1 -0
- package/dist/utils/request.d.ts +12 -0
- package/dist/utils/request.js +55 -0
- package/dist/utils/request.js.map +1 -0
- package/dist/utils/version.d.ts +5 -0
- package/dist/utils/version.js +7 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +174 -4
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uploads a file with sequential `PUT` requests carrying `Content-Range` headers (the `put-chunked`
|
|
3
|
+
* protocol, used by providers such as Mux). Works in the browser and in Node; no dependencies.
|
|
4
|
+
*
|
|
5
|
+
* The server answers `308` (or any 2xx) after each chunk; a `Range: bytes=0-N` header on the reply,
|
|
6
|
+
* when present, tells us how much it has really received.
|
|
7
|
+
*/ export class ChunkedUpload {
|
|
8
|
+
/** Bytes the server has acknowledged. */ offset = 0;
|
|
9
|
+
controller = null;
|
|
10
|
+
options;
|
|
11
|
+
constructor(options){
|
|
12
|
+
if (!(options.chunkSize > 0)) {
|
|
13
|
+
throw new Error('ChunkedUpload: chunkSize must be a positive number of bytes');
|
|
14
|
+
}
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
/** Uploads from the current offset until the file is complete. Rejects with an AbortError when paused. */ async start() {
|
|
18
|
+
const { chunkSize, file, headers, onProgress, url } = this.options;
|
|
19
|
+
const doFetch = this.options.fetch ?? ((...args)=>globalThis.fetch(...args));
|
|
20
|
+
const total = file.size;
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
this.controller = controller;
|
|
23
|
+
while(this.offset < total){
|
|
24
|
+
const end = Math.min(this.offset + chunkSize, total);
|
|
25
|
+
const res = await doFetch(url, {
|
|
26
|
+
body: file.slice(this.offset, end),
|
|
27
|
+
headers: {
|
|
28
|
+
...headers,
|
|
29
|
+
'Content-Range': `bytes ${this.offset}-${end - 1}/${total}`
|
|
30
|
+
},
|
|
31
|
+
method: 'PUT',
|
|
32
|
+
signal: controller.signal
|
|
33
|
+
});
|
|
34
|
+
if (res.status !== 308 && !res.ok) {
|
|
35
|
+
throw new Error(`Upload failed (HTTP ${res.status})`);
|
|
36
|
+
}
|
|
37
|
+
const range = /bytes=\d+-(\d+)/.exec(res.headers.get('range') ?? '');
|
|
38
|
+
this.offset = range ? Number(range[1]) + 1 : end;
|
|
39
|
+
onProgress?.(this.offset, total);
|
|
40
|
+
}
|
|
41
|
+
this.controller = null;
|
|
42
|
+
}
|
|
43
|
+
/** Stops after aborting the request in flight; call `start()` again to resume. */ pause() {
|
|
44
|
+
this.controller?.abort();
|
|
45
|
+
this.controller = null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=chunkedUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/chunkedUpload.ts"],"sourcesContent":["/**\n * Uploads a file with sequential `PUT` requests carrying `Content-Range` headers (the `put-chunked`\n * protocol, used by providers such as Mux). Works in the browser and in Node; no dependencies.\n *\n * The server answers `308` (or any 2xx) after each chunk; a `Range: bytes=0-N` header on the reply,\n * when present, tells us how much it has really received.\n */\nexport type ChunkedUploadOptions = {\n /** Bytes per request. The last chunk may be smaller. */\n chunkSize: number\n /** Custom fetch (tests). */\n fetch?: typeof fetch\n file: Blob\n headers?: Record<string, string>\n onProgress?: (loaded: number, total: number) => void\n url: string\n}\n\nexport class ChunkedUpload {\n /** Bytes the server has acknowledged. */\n offset = 0\n private controller: AbortController | null = null\n private readonly options: ChunkedUploadOptions\n\n constructor(options: ChunkedUploadOptions) {\n if (!(options.chunkSize > 0)) {\n throw new Error('ChunkedUpload: chunkSize must be a positive number of bytes')\n }\n this.options = options\n }\n\n /** Uploads from the current offset until the file is complete. Rejects with an AbortError when paused. */\n async start(): Promise<void> {\n const { chunkSize, file, headers, onProgress, url } = this.options\n const doFetch = this.options.fetch ?? ((...args: Parameters<typeof fetch>) => globalThis.fetch(...args))\n const total = file.size\n const controller = new AbortController()\n this.controller = controller\n while (this.offset < total) {\n const end = Math.min(this.offset + chunkSize, total)\n const res = await doFetch(url, {\n body: file.slice(this.offset, end),\n headers: { ...headers, 'Content-Range': `bytes ${this.offset}-${end - 1}/${total}` },\n method: 'PUT',\n signal: controller.signal,\n })\n if (res.status !== 308 && !res.ok) {\n throw new Error(`Upload failed (HTTP ${res.status})`)\n }\n const range = /bytes=\\d+-(\\d+)/.exec(res.headers.get('range') ?? '')\n this.offset = range ? Number(range[1]) + 1 : end\n onProgress?.(this.offset, total)\n }\n this.controller = null\n }\n\n /** Stops after aborting the request in flight; call `start()` again to resume. */\n pause(): void {\n this.controller?.abort()\n this.controller = null\n }\n}\n"],"names":["ChunkedUpload","offset","controller","options","chunkSize","Error","start","file","headers","onProgress","url","doFetch","fetch","args","globalThis","total","size","AbortController","end","Math","min","res","body","slice","method","signal","status","ok","range","exec","get","Number","pause","abort"],"mappings":"AAAA;;;;;;CAMC,GAYD,OAAO,MAAMA;IACX,uCAAuC,GACvCC,SAAS,EAAC;IACFC,aAAqC,KAAI;IAChCC,QAA6B;IAE9C,YAAYA,OAA6B,CAAE;QACzC,IAAI,CAAEA,CAAAA,QAAQC,SAAS,GAAG,CAAA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pB;IAEA,gFAAgF,GAChF8B,QAAc;QACZ,IAAI,CAAC9B,UAAU,EAAE+B;QACjB,IAAI,CAAC/B,UAAU,GAAG;IACpB;AACF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
export declare const colors: {
|
|
3
|
+
bg: string;
|
|
4
|
+
border: string;
|
|
5
|
+
error: string;
|
|
6
|
+
muted: string;
|
|
7
|
+
subtle: string;
|
|
8
|
+
success: string;
|
|
9
|
+
text: string;
|
|
10
|
+
warning: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const styles: {
|
|
13
|
+
actions: {
|
|
14
|
+
alignItems: "center";
|
|
15
|
+
display: "flex";
|
|
16
|
+
flexWrap: "wrap";
|
|
17
|
+
gap: number;
|
|
18
|
+
};
|
|
19
|
+
badge: (tone: "error" | "muted" | "success" | "warning") => CSSProperties;
|
|
20
|
+
button: {
|
|
21
|
+
background: string;
|
|
22
|
+
border: string;
|
|
23
|
+
borderRadius: number;
|
|
24
|
+
color: string;
|
|
25
|
+
cursor: "pointer";
|
|
26
|
+
font: "inherit";
|
|
27
|
+
padding: string;
|
|
28
|
+
};
|
|
29
|
+
card: {
|
|
30
|
+
background: string;
|
|
31
|
+
border: string;
|
|
32
|
+
borderRadius: number;
|
|
33
|
+
display: "flex";
|
|
34
|
+
flexDirection: "column";
|
|
35
|
+
gap: number;
|
|
36
|
+
marginBottom: number;
|
|
37
|
+
padding: number;
|
|
38
|
+
};
|
|
39
|
+
dropzone: (active: boolean) => CSSProperties;
|
|
40
|
+
error: {
|
|
41
|
+
color: string;
|
|
42
|
+
fontSize: number;
|
|
43
|
+
};
|
|
44
|
+
heading: {
|
|
45
|
+
fontSize: number;
|
|
46
|
+
fontWeight: number;
|
|
47
|
+
margin: number;
|
|
48
|
+
};
|
|
49
|
+
input: {
|
|
50
|
+
background: string;
|
|
51
|
+
border: string;
|
|
52
|
+
borderRadius: number;
|
|
53
|
+
color: string;
|
|
54
|
+
font: "inherit";
|
|
55
|
+
padding: string;
|
|
56
|
+
};
|
|
57
|
+
muted: {
|
|
58
|
+
color: string;
|
|
59
|
+
fontSize: number;
|
|
60
|
+
};
|
|
61
|
+
player: {
|
|
62
|
+
aspectRatio: "16 / 9";
|
|
63
|
+
background: string;
|
|
64
|
+
border: number;
|
|
65
|
+
borderRadius: number;
|
|
66
|
+
width: string;
|
|
67
|
+
};
|
|
68
|
+
progressOuter: {
|
|
69
|
+
background: string;
|
|
70
|
+
borderRadius: number;
|
|
71
|
+
height: number;
|
|
72
|
+
overflow: "hidden";
|
|
73
|
+
width: string;
|
|
74
|
+
};
|
|
75
|
+
progressInner: (pct: number) => CSSProperties;
|
|
76
|
+
row: {
|
|
77
|
+
alignItems: "center";
|
|
78
|
+
display: "flex";
|
|
79
|
+
gap: number;
|
|
80
|
+
justifyContent: "space-between";
|
|
81
|
+
};
|
|
82
|
+
table: {
|
|
83
|
+
borderCollapse: "collapse";
|
|
84
|
+
fontSize: number;
|
|
85
|
+
width: string;
|
|
86
|
+
};
|
|
87
|
+
td: {
|
|
88
|
+
borderTop: string;
|
|
89
|
+
padding: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export declare const statusTone: (status?: null | string) => "error" | "muted" | "success" | "warning";
|
|
93
|
+
export declare const STATUS_TEXT: Record<string, string>;
|
|
94
|
+
export declare const formatBytes: (bytes?: null | number) => string;
|
|
95
|
+
export declare const formatDuration: (seconds?: null | number) => string;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { VIDEO_STATUS_LABELS } from '../core/status.js';
|
|
2
|
+
/**
|
|
3
|
+
* Inline styles using Payload theme variables with fallbacks, so the components look native on
|
|
4
|
+
* Payload 4 (`--color-*`) and Payload 3 (`--theme-*`) without shipping a stylesheet.
|
|
5
|
+
*/ const v = (v4, v3, fallback)=>`var(${v4}, var(${v3}, ${fallback}))`;
|
|
6
|
+
export const colors = {
|
|
7
|
+
bg: v('--color-bg', '--theme-elevation-0', '#fff'),
|
|
8
|
+
border: v('--color-border', '--theme-elevation-150', '#ddd'),
|
|
9
|
+
error: v('--color-error', '--theme-error-500', '#d32f2f'),
|
|
10
|
+
muted: v('--color-text-muted', '--theme-elevation-500', '#777'),
|
|
11
|
+
subtle: v('--color-bg-subtle', '--theme-elevation-50', '#f5f5f5'),
|
|
12
|
+
success: v('--color-success', '--theme-success-500', '#2e7d32'),
|
|
13
|
+
text: v('--color-text', '--theme-text', '#222'),
|
|
14
|
+
warning: v('--color-warning', '--theme-warning-500', '#ed6c02')
|
|
15
|
+
};
|
|
16
|
+
export const styles = {
|
|
17
|
+
actions: {
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
display: 'flex',
|
|
20
|
+
flexWrap: 'wrap',
|
|
21
|
+
gap: 8
|
|
22
|
+
},
|
|
23
|
+
badge: (tone)=>({
|
|
24
|
+
border: `1px solid ${colors[tone]}`,
|
|
25
|
+
borderRadius: 999,
|
|
26
|
+
color: colors[tone],
|
|
27
|
+
display: 'inline-block',
|
|
28
|
+
fontSize: 12,
|
|
29
|
+
lineHeight: '18px',
|
|
30
|
+
padding: '0 8px'
|
|
31
|
+
}),
|
|
32
|
+
button: {
|
|
33
|
+
background: colors.subtle,
|
|
34
|
+
border: `1px solid ${colors.border}`,
|
|
35
|
+
borderRadius: 4,
|
|
36
|
+
color: colors.text,
|
|
37
|
+
cursor: 'pointer',
|
|
38
|
+
font: 'inherit',
|
|
39
|
+
padding: '6px 12px'
|
|
40
|
+
},
|
|
41
|
+
card: {
|
|
42
|
+
background: colors.bg,
|
|
43
|
+
border: `1px solid ${colors.border}`,
|
|
44
|
+
borderRadius: 6,
|
|
45
|
+
display: 'flex',
|
|
46
|
+
flexDirection: 'column',
|
|
47
|
+
gap: 12,
|
|
48
|
+
marginBottom: 24,
|
|
49
|
+
padding: 16
|
|
50
|
+
},
|
|
51
|
+
dropzone: (active)=>({
|
|
52
|
+
alignItems: 'center',
|
|
53
|
+
background: active ? colors.subtle : 'transparent',
|
|
54
|
+
border: `2px dashed ${active ? colors.text : colors.border}`,
|
|
55
|
+
borderRadius: 6,
|
|
56
|
+
cursor: 'pointer',
|
|
57
|
+
display: 'flex',
|
|
58
|
+
flexDirection: 'column',
|
|
59
|
+
gap: 8,
|
|
60
|
+
justifyContent: 'center',
|
|
61
|
+
padding: 32,
|
|
62
|
+
textAlign: 'center'
|
|
63
|
+
}),
|
|
64
|
+
error: {
|
|
65
|
+
color: colors.error,
|
|
66
|
+
fontSize: 13
|
|
67
|
+
},
|
|
68
|
+
heading: {
|
|
69
|
+
fontSize: 14,
|
|
70
|
+
fontWeight: 600,
|
|
71
|
+
margin: 0
|
|
72
|
+
},
|
|
73
|
+
input: {
|
|
74
|
+
background: colors.bg,
|
|
75
|
+
border: `1px solid ${colors.border}`,
|
|
76
|
+
borderRadius: 4,
|
|
77
|
+
color: colors.text,
|
|
78
|
+
font: 'inherit',
|
|
79
|
+
padding: '6px 8px'
|
|
80
|
+
},
|
|
81
|
+
muted: {
|
|
82
|
+
color: colors.muted,
|
|
83
|
+
fontSize: 13
|
|
84
|
+
},
|
|
85
|
+
player: {
|
|
86
|
+
aspectRatio: '16 / 9',
|
|
87
|
+
background: '#000',
|
|
88
|
+
border: 0,
|
|
89
|
+
borderRadius: 4,
|
|
90
|
+
width: '100%'
|
|
91
|
+
},
|
|
92
|
+
progressOuter: {
|
|
93
|
+
background: colors.subtle,
|
|
94
|
+
borderRadius: 4,
|
|
95
|
+
height: 8,
|
|
96
|
+
overflow: 'hidden',
|
|
97
|
+
width: '100%'
|
|
98
|
+
},
|
|
99
|
+
progressInner: (pct)=>({
|
|
100
|
+
background: colors.success,
|
|
101
|
+
height: '100%',
|
|
102
|
+
transition: 'width 200ms',
|
|
103
|
+
width: `${Math.max(0, Math.min(100, pct))}%`
|
|
104
|
+
}),
|
|
105
|
+
row: {
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
display: 'flex',
|
|
108
|
+
gap: 12,
|
|
109
|
+
justifyContent: 'space-between'
|
|
110
|
+
},
|
|
111
|
+
table: {
|
|
112
|
+
borderCollapse: 'collapse',
|
|
113
|
+
fontSize: 13,
|
|
114
|
+
width: '100%'
|
|
115
|
+
},
|
|
116
|
+
td: {
|
|
117
|
+
borderTop: `1px solid ${colors.border}`,
|
|
118
|
+
padding: '6px 4px'
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export const statusTone = (status)=>status === 'ready' ? 'success' : status === 'error' ? 'error' : status ? 'warning' : 'muted';
|
|
122
|
+
export const STATUS_TEXT = VIDEO_STATUS_LABELS;
|
|
123
|
+
export const formatBytes = (bytes)=>{
|
|
124
|
+
if (!bytes || bytes <= 0) {
|
|
125
|
+
return '—';
|
|
126
|
+
}
|
|
127
|
+
const units = [
|
|
128
|
+
'B',
|
|
129
|
+
'KB',
|
|
130
|
+
'MB',
|
|
131
|
+
'GB',
|
|
132
|
+
'TB'
|
|
133
|
+
];
|
|
134
|
+
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
|
|
135
|
+
return `${(bytes / 1024 ** i).toFixed(i === 0 ? 0 : 1)} ${units[i]}`;
|
|
136
|
+
};
|
|
137
|
+
export const formatDuration = (seconds)=>{
|
|
138
|
+
if (seconds === null || seconds === undefined || seconds < 0) {
|
|
139
|
+
return '—';
|
|
140
|
+
}
|
|
141
|
+
const s = Math.round(seconds);
|
|
142
|
+
const h = Math.floor(s / 3600);
|
|
143
|
+
const m = Math.floor(s % 3600 / 60);
|
|
144
|
+
const sec = s % 60;
|
|
145
|
+
return h ? `${h}:${String(m).padStart(2, '0')}:${String(sec).padStart(2, '0')}` : `${m}:${String(sec).padStart(2, '0')}`;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react'\n\nimport { VIDEO_STATUS_LABELS } from '../core/status.js'\n\n/**\n * Inline styles using Payload theme variables with fallbacks, so the components look native on\n * Payload 4 (`--color-*`) and Payload 3 (`--theme-*`) without shipping a stylesheet.\n */\nconst v = (v4: string, v3: string, fallback: string) => `var(${v4}, var(${v3}, ${fallback}))`\n\nexport const colors = {\n bg: v('--color-bg', '--theme-elevation-0', '#fff'),\n border: v('--color-border', '--theme-elevation-150', '#ddd'),\n error: v('--color-error', '--theme-error-500', '#d32f2f'),\n muted: v('--color-text-muted', '--theme-elevation-500', '#777'),\n subtle: v('--color-bg-subtle', '--theme-elevation-50', '#f5f5f5'),\n success: v('--color-success', '--theme-success-500', '#2e7d32'),\n text: v('--color-text', '--theme-text', '#222'),\n warning: v('--color-warning', '--theme-warning-500', '#ed6c02'),\n}\n\nexport const styles = {\n actions: { alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: 8 } satisfies CSSProperties,\n badge: (tone: 'error' | 'muted' | 'success' | 'warning'): CSSProperties => ({\n border: `1px solid ${colors[tone]}`,\n borderRadius: 999,\n color: colors[tone],\n display: 'inline-block',\n fontSize: 12,\n lineHeight: '18px',\n padding: '0 8px',\n }),\n button: {\n background: colors.subtle,\n border: `1px solid ${colors.border}`,\n borderRadius: 4,\n color: colors.text,\n cursor: 'pointer',\n font: 'inherit',\n padding: '6px 12px',\n } satisfies CSSProperties,\n card: {\n background: colors.bg,\n border: `1px solid ${colors.border}`,\n borderRadius: 6,\n display: 'flex',\n flexDirection: 'column',\n gap: 12,\n marginBottom: 24,\n padding: 16,\n } satisfies CSSProperties,\n dropzone: (active: boolean): CSSProperties => ({\n alignItems: 'center',\n background: active ? colors.subtle : 'transparent',\n border: `2px dashed ${active ? colors.text : colors.border}`,\n borderRadius: 6,\n cursor: 'pointer',\n display: 'flex',\n flexDirection: 'column',\n gap: 8,\n justifyContent: 'center',\n padding: 32,\n textAlign: 'center',\n }),\n error: { color: colors.error, fontSize: 13 } satisfies CSSProperties,\n heading: { fontSize: 14, fontWeight: 600, margin: 0 } satisfies CSSProperties,\n input: {\n background: colors.bg,\n border: `1px solid ${colors.border}`,\n borderRadius: 4,\n color: colors.text,\n font: 'inherit',\n padding: '6px 8px',\n } satisfies CSSProperties,\n muted: { color: colors.muted, fontSize: 13 } satisfies CSSProperties,\n player: {\n aspectRatio: '16 / 9',\n background: '#000',\n border: 0,\n borderRadius: 4,\n width: '100%',\n } satisfies CSSProperties,\n progressOuter: {\n background: colors.subtle,\n borderRadius: 4,\n height: 8,\n overflow: 'hidden',\n width: '100%',\n } satisfies CSSProperties,\n progressInner: (pct: number): CSSProperties => ({\n background: colors.success,\n height: '100%',\n transition: 'width 200ms',\n width: `${Math.max(0, Math.min(100, pct))}%`,\n }),\n row: { alignItems: 'center', display: 'flex', gap: 12, justifyContent: 'space-between' } satisfies CSSProperties,\n table: { borderCollapse: 'collapse', fontSize: 13, width: '100%' } satisfies CSSProperties,\n td: { borderTop: `1px solid ${colors.border}`, padding: '6px 4px' } satisfies CSSProperties,\n}\n\nexport const statusTone = (status?: null | string): 'error' | 'muted' | 'success' | 'warning' =>\n status === 'ready' ? 'success' : status === 'error' ? 'error' : status ? 'warning' : 'muted'\n\nexport const STATUS_TEXT: Record<string, string> = VIDEO_STATUS_LABELS\n\nexport const formatBytes = (bytes?: null | number): string => {\n if (!bytes || bytes <= 0) {\n return '—'\n }\n const units = ['B', 'KB', 'MB', 'GB', 'TB']\n const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1)\n return `${(bytes / 1024 ** i).toFixed(i === 0 ? 0 : 1)} ${units[i]}`\n}\n\nexport const formatDuration = (seconds?: null | number): string => {\n if (seconds === null || seconds === undefined || seconds < 0) {\n return '—'\n }\n const s = Math.round(seconds)\n const h = Math.floor(s / 3600)\n const m = Math.floor((s % 3600) / 60)\n const sec = s % 60\n return h ? `${h}:${String(m).padStart(2, '0')}:${String(sec).padStart(2, '0')}` : `${m}:${String(sec).padStart(2, '0')}`\n}\n"],"names":["VIDEO_STATUS_LABELS","v","v4","v3","fallback","colors","bg","border","error","muted","subtle","success","text","warning","styles","actions","alignItems","display","flexWrap","gap","badge","tone","borderRadius","color","fontSize","lineHeight","padding","button","background","cursor","font","card","flexDirection","marginBottom","dropzone","active","justifyContent","textAlign","heading","fontWeight","margin","input","player","aspectRatio","width","progressOuter","height","overflow","progressInner","pct","transition","Math","max","min","row","table","borderCollapse","td","borderTop","statusTone","status","STATUS_TEXT","formatBytes","bytes","units","i","floor","log","length","toFixed","formatDuration","seconds","undefined","s","round","h","m","sec","String","padStart"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,oBAAmB;AAEvD;;;CAGC,GACD,MAAMC,IAAI,CAACC,IAAYC,IAAYC,WAAqB,CAAC,IAAI,EAAEF,GAAG,MAAM,EAAEC,GAAG,EAAE,EAAEC,SAAS,EAAE,CAAC;AAE7F,OAAO,MAAMC,SAAS;IACpBC,IAAIL,EAAE,cAAc,uBAAuB;IAC3CM,QAAQN,EAAE,kBAAkB,yBAAyB;IACrDO,OAAOP,EAAE,iBAAiB,qBAAqB;IAC/CQ,OAAOR,EAAE,sBAAsB,yBAAyB;IACxDS,QAAQT,EAAE,qBAAqB,wBAAwB;IACvDU,SAASV,EAAE,mBAAmB,uBAAuB;IACrDW,MAAMX,EAAE,gBAAgB,gBAAgB;IACxCY,SAASZ,EAAE,mBAAmB,uBAAuB;AACvD,EAAC;AAED,OAAO,MAAMa,SAAS;IACpBC,SAAS;QAAEC,YAAY;QAAUC,SAAS;QAAQC,UAAU;QAAQC,KAAK;IAAE;IAC3EC,OAAO,CAACC,OAAoE,CAAA;YAC1Ed,QAAQ,CAAC,UAAU,EAAEF,MAAM,CAACgB,KAAK,EAAE;YACnCC,cAAc;YACdC,OAAOlB,MAAM,CAACgB,KAAK;YACnBJ,SAAS;YACTO,UAAU;YACVC,YAAY;YACZC,SAAS;QACX,CAAA;IACAC,QAAQ;QACNC,YAAYvB,OAAOK,MAAM;QACzBH,QAAQ,CAAC,UAAU,EAAEF,OAAOE,MAAM,EAAE;QACpCe,cAAc;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GAAG,MAAM,GAAG,GAAGH,EAAE,CAAC,EAAEE,OAAOD,KAAKE,QAAQ,CAAC,GAAG,MAAM;AAC1H,EAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Resolves the REST API base from the Payload client config (works on v3 and v4). */
|
|
2
|
+
export declare const usePluginApi: (collectionSlug: string) => {
|
|
3
|
+
adminRoute: string;
|
|
4
|
+
api: {
|
|
5
|
+
captions: (id: number | string) => Promise<{
|
|
6
|
+
captions: import("../index.js").CaptionTrack[];
|
|
7
|
+
}>;
|
|
8
|
+
createDownload: (id: number | string, type: import("../index.js").DownloadType) => Promise<{
|
|
9
|
+
downloads: import("../index.js").Downloads;
|
|
10
|
+
}>;
|
|
11
|
+
createUpload: (body: {
|
|
12
|
+
filename: string;
|
|
13
|
+
id?: number | string;
|
|
14
|
+
provider?: string;
|
|
15
|
+
size: number;
|
|
16
|
+
title?: string;
|
|
17
|
+
}) => Promise<import("../types.js").CreateUploadResult>;
|
|
18
|
+
deleteCaption: (id: number | string, language: string) => Promise<{
|
|
19
|
+
captions: import("../index.js").CaptionTrack[];
|
|
20
|
+
}>;
|
|
21
|
+
deleteDownload: (id: number | string, type: import("../index.js").DownloadType) => Promise<{
|
|
22
|
+
downloads: import("../index.js").Downloads;
|
|
23
|
+
}>;
|
|
24
|
+
downloads: (id: number | string) => Promise<{
|
|
25
|
+
downloads: import("../index.js").Downloads;
|
|
26
|
+
}>;
|
|
27
|
+
generateCaption: (id: number | string, language: string) => Promise<{
|
|
28
|
+
captions: import("../index.js").CaptionTrack[];
|
|
29
|
+
}>;
|
|
30
|
+
importFromUrl: (url: string, title?: string, provider?: string) => Promise<{
|
|
31
|
+
doc: import("../types.js").VideoDoc;
|
|
32
|
+
}>;
|
|
33
|
+
playback: (id: number | string) => Promise<import("../types.js").VideoPlayback>;
|
|
34
|
+
sync: (id: number | string) => Promise<{
|
|
35
|
+
doc: import("../types.js").VideoDoc;
|
|
36
|
+
}>;
|
|
37
|
+
uploadCaption: (id: number | string, language: string, file: File) => Promise<{
|
|
38
|
+
captions: import("../index.js").CaptionTrack[];
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useConfig } from '@payloadcms/ui';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { createPluginApi } from './api.js';
|
|
5
|
+
/** Resolves the REST API base from the Payload client config (works on v3 and v4). */ export const usePluginApi = (collectionSlug)=>{
|
|
6
|
+
const { config } = useConfig();
|
|
7
|
+
const serverURL = config.serverURL ?? '';
|
|
8
|
+
const apiRoute = config.routes?.api ?? '/api';
|
|
9
|
+
const adminRoute = config.routes?.admin ?? '/admin';
|
|
10
|
+
const api = useMemo(()=>createPluginApi(`${serverURL}${apiRoute}`, collectionSlug), [
|
|
11
|
+
serverURL,
|
|
12
|
+
apiRoute,
|
|
13
|
+
collectionSlug
|
|
14
|
+
]);
|
|
15
|
+
return {
|
|
16
|
+
adminRoute: `${serverURL}${adminRoute}`,
|
|
17
|
+
api
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=usePluginApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/usePluginApi.ts"],"sourcesContent":["'use client'\n\nimport { useConfig } from '@payloadcms/ui'\nimport { useMemo } from 'react'\n\nimport { createPluginApi } from './api.js'\n\n/** Resolves the REST API base from the Payload client config (works on v3 and v4). */\nexport const usePluginApi = (collectionSlug: string) => {\n const { config } = useConfig()\n const serverURL = (config as { serverURL?: string }).serverURL ?? ''\n const apiRoute = config.routes?.api ?? '/api'\n const adminRoute = config.routes?.admin ?? '/admin'\n const api = useMemo(() => createPluginApi(`${serverURL}${apiRoute}`, collectionSlug), [serverURL, apiRoute, collectionSlug])\n return { adminRoute: `${serverURL}${adminRoute}`, api }\n}\n"],"names":["useConfig","useMemo","createPluginApi","usePluginApi","collectionSlug","config","serverURL","apiRoute","routes","api","adminRoute","admin"],"mappings":"AAAA;AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,OAAO,QAAQ,QAAO;AAE/B,SAASC,eAAe,QAAQ,WAAU;AAE1C,oFAAoF,GACpF,OAAO,MAAMC,eAAe,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAE,GAAGL;IACnB,MAAMM,YAAY,AAACD,OAAkCC,SAAS,IAAI;IAClE,MAAMC,WAAWF,OAAOG,MAAM,EAAEC,OAAO;IACvC,MAAMC,aAAaL,OAAOG,MAAM,EAAEG,SAAS;IAC3C,MAAMF,MAAMR,QAAQ,IAAMC,gBAAgB,GAAGI,YAAYC,UAAU,EAAEH,iBAAiB;QAACE;QAAWC;QAAUH;KAAe;IAC3H,OAAO;QAAEM,YAAY,GAAGJ,YAAYI,YAAY;QAAED;IAAI;AACxD,EAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CreateUploadResult } from '../types.js';
|
|
2
|
+
import type { PluginApi } from './api.js';
|
|
3
|
+
export type UploadState = {
|
|
4
|
+
error: string;
|
|
5
|
+
phase: 'error';
|
|
6
|
+
} | {
|
|
7
|
+
loaded: number;
|
|
8
|
+
paused: boolean;
|
|
9
|
+
phase: 'uploading';
|
|
10
|
+
result: CreateUploadResult;
|
|
11
|
+
total: number;
|
|
12
|
+
} | {
|
|
13
|
+
phase: 'done';
|
|
14
|
+
result: CreateUploadResult;
|
|
15
|
+
} | {
|
|
16
|
+
phase: 'idle';
|
|
17
|
+
} | {
|
|
18
|
+
phase: 'preparing';
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Uploads a file directly from the browser to the video provider, with whichever protocol the provider
|
|
22
|
+
* chose: a multipart `post`, resumable `tus`, or `put-chunked`. `tus-js-client` is only loaded when a
|
|
23
|
+
* tus upload starts.
|
|
24
|
+
*/
|
|
25
|
+
export declare const useVideoUpload: (api: PluginApi) => {
|
|
26
|
+
cancel: () => void;
|
|
27
|
+
canPause: boolean;
|
|
28
|
+
pause: () => void;
|
|
29
|
+
reset: () => void;
|
|
30
|
+
resume: () => void;
|
|
31
|
+
start: (file: File, options?: {
|
|
32
|
+
id?: number | string;
|
|
33
|
+
provider?: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
}) => Promise<CreateUploadResult | null>;
|
|
36
|
+
state: UploadState;
|
|
37
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useRef, useState } from 'react';
|
|
3
|
+
import { ChunkedUpload } from './chunkedUpload.js';
|
|
4
|
+
/**
|
|
5
|
+
* Uploads a file directly from the browser to the video provider, with whichever protocol the provider
|
|
6
|
+
* chose: a multipart `post`, resumable `tus`, or `put-chunked`. `tus-js-client` is only loaded when a
|
|
7
|
+
* tus upload starts.
|
|
8
|
+
*/ export const useVideoUpload = (api)=>{
|
|
9
|
+
const [state, setState] = useState({
|
|
10
|
+
phase: 'idle'
|
|
11
|
+
});
|
|
12
|
+
const pausableRef = useRef(null);
|
|
13
|
+
const cancelRef = useRef(null);
|
|
14
|
+
const start = useCallback(async (file, options = {})=>{
|
|
15
|
+
setState({
|
|
16
|
+
phase: 'preparing'
|
|
17
|
+
});
|
|
18
|
+
let result;
|
|
19
|
+
try {
|
|
20
|
+
result = await api.createUpload({
|
|
21
|
+
filename: file.name,
|
|
22
|
+
id: options.id,
|
|
23
|
+
provider: options.provider,
|
|
24
|
+
size: file.size,
|
|
25
|
+
title: options.title
|
|
26
|
+
});
|
|
27
|
+
} catch (err) {
|
|
28
|
+
setState({
|
|
29
|
+
error: err.message,
|
|
30
|
+
phase: 'error'
|
|
31
|
+
});
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
setState({
|
|
35
|
+
loaded: 0,
|
|
36
|
+
paused: false,
|
|
37
|
+
phase: 'uploading',
|
|
38
|
+
result,
|
|
39
|
+
total: file.size
|
|
40
|
+
});
|
|
41
|
+
const onProgress = (loaded, total)=>setState((prev)=>prev.phase === 'uploading' ? {
|
|
42
|
+
...prev,
|
|
43
|
+
loaded,
|
|
44
|
+
total
|
|
45
|
+
} : prev);
|
|
46
|
+
const upload = result.upload;
|
|
47
|
+
try {
|
|
48
|
+
if (upload.protocol === 'tus') {
|
|
49
|
+
const { Upload } = await import('tus-js-client');
|
|
50
|
+
await new Promise((resolve, reject)=>{
|
|
51
|
+
const tus = new Upload(file, {
|
|
52
|
+
// tus-js-client casts the option with Number(), so an explicit undefined would become NaN
|
|
53
|
+
// (empty PATCH requests forever). Leave it out to keep the default: one request.
|
|
54
|
+
...upload.chunkSize ? {
|
|
55
|
+
chunkSize: upload.chunkSize
|
|
56
|
+
} : {},
|
|
57
|
+
endpoint: upload.endpoint,
|
|
58
|
+
headers: upload.headers,
|
|
59
|
+
metadata: {
|
|
60
|
+
filename: file.name,
|
|
61
|
+
filetype: file.type,
|
|
62
|
+
...upload.metadata
|
|
63
|
+
},
|
|
64
|
+
onError: reject,
|
|
65
|
+
onProgress,
|
|
66
|
+
onSuccess: ()=>resolve(),
|
|
67
|
+
retryDelays: [
|
|
68
|
+
0,
|
|
69
|
+
1000,
|
|
70
|
+
3000,
|
|
71
|
+
5000,
|
|
72
|
+
10000
|
|
73
|
+
],
|
|
74
|
+
uploadSize: file.size,
|
|
75
|
+
uploadUrl: upload.uploadUrl
|
|
76
|
+
});
|
|
77
|
+
pausableRef.current = {
|
|
78
|
+
pause: ()=>void tus.abort(),
|
|
79
|
+
resume: ()=>tus.start()
|
|
80
|
+
};
|
|
81
|
+
cancelRef.current = ()=>{
|
|
82
|
+
// Ask the server to discard the partial upload; not every tus server supports termination.
|
|
83
|
+
tus.abort(true).catch(()=>undefined);
|
|
84
|
+
reject(new Error('Upload cancelled'));
|
|
85
|
+
};
|
|
86
|
+
tus.start();
|
|
87
|
+
});
|
|
88
|
+
} else if (upload.protocol === 'put-chunked') {
|
|
89
|
+
const chunked = new ChunkedUpload({
|
|
90
|
+
chunkSize: upload.chunkSize,
|
|
91
|
+
file,
|
|
92
|
+
headers: upload.headers,
|
|
93
|
+
onProgress,
|
|
94
|
+
url: upload.url
|
|
95
|
+
});
|
|
96
|
+
await new Promise((resolve, reject)=>{
|
|
97
|
+
let cancelled = false;
|
|
98
|
+
const run = ()=>chunked.start().then(resolve, (err)=>{
|
|
99
|
+
// A pause aborts the request in flight; only real failures (or a cancel) end the upload.
|
|
100
|
+
if (cancelled || err.name !== 'AbortError') {
|
|
101
|
+
reject(cancelled ? new Error('Upload cancelled') : err);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
pausableRef.current = {
|
|
105
|
+
pause: ()=>chunked.pause(),
|
|
106
|
+
resume: ()=>void run()
|
|
107
|
+
};
|
|
108
|
+
cancelRef.current = ()=>{
|
|
109
|
+
cancelled = true;
|
|
110
|
+
chunked.pause();
|
|
111
|
+
};
|
|
112
|
+
void run();
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
await new Promise((resolve, reject)=>{
|
|
116
|
+
const xhr = new XMLHttpRequest();
|
|
117
|
+
cancelRef.current = ()=>xhr.abort();
|
|
118
|
+
xhr.upload.onprogress = (e)=>e.lengthComputable && onProgress(e.loaded, e.total);
|
|
119
|
+
xhr.onload = ()=>xhr.status >= 200 && xhr.status < 300 ? resolve() : reject(new Error(`Upload failed (HTTP ${xhr.status})`));
|
|
120
|
+
xhr.onerror = ()=>reject(new Error('Network error during upload'));
|
|
121
|
+
xhr.onabort = ()=>reject(new Error('Upload cancelled'));
|
|
122
|
+
const form = new FormData();
|
|
123
|
+
form.append(upload.fieldName ?? 'file', file, file.name);
|
|
124
|
+
xhr.open('POST', upload.url);
|
|
125
|
+
xhr.send(form);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
setState({
|
|
130
|
+
error: err.message || 'Upload failed',
|
|
131
|
+
phase: 'error'
|
|
132
|
+
});
|
|
133
|
+
return null;
|
|
134
|
+
} finally{
|
|
135
|
+
pausableRef.current = null;
|
|
136
|
+
cancelRef.current = null;
|
|
137
|
+
}
|
|
138
|
+
setState({
|
|
139
|
+
phase: 'done',
|
|
140
|
+
result
|
|
141
|
+
});
|
|
142
|
+
return result;
|
|
143
|
+
}, [
|
|
144
|
+
api
|
|
145
|
+
]);
|
|
146
|
+
const pause = useCallback(()=>{
|
|
147
|
+
pausableRef.current?.pause();
|
|
148
|
+
setState((prev)=>prev.phase === 'uploading' ? {
|
|
149
|
+
...prev,
|
|
150
|
+
paused: true
|
|
151
|
+
} : prev);
|
|
152
|
+
}, []);
|
|
153
|
+
const resume = useCallback(()=>{
|
|
154
|
+
pausableRef.current?.resume();
|
|
155
|
+
setState((prev)=>prev.phase === 'uploading' ? {
|
|
156
|
+
...prev,
|
|
157
|
+
paused: false
|
|
158
|
+
} : prev);
|
|
159
|
+
}, []);
|
|
160
|
+
const cancel = useCallback(()=>{
|
|
161
|
+
cancelRef.current?.();
|
|
162
|
+
setState({
|
|
163
|
+
error: 'Upload cancelled',
|
|
164
|
+
phase: 'error'
|
|
165
|
+
});
|
|
166
|
+
}, []);
|
|
167
|
+
const reset = useCallback(()=>setState({
|
|
168
|
+
phase: 'idle'
|
|
169
|
+
}), []);
|
|
170
|
+
return {
|
|
171
|
+
cancel,
|
|
172
|
+
canPause: Boolean(pausableRef.current),
|
|
173
|
+
pause,
|
|
174
|
+
reset,
|
|
175
|
+
resume,
|
|
176
|
+
start,
|
|
177
|
+
state
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=useVideoUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/useVideoUpload.ts"],"sourcesContent":["'use client'\n\nimport type { Upload as TusUpload } from 'tus-js-client'\n\nimport { useCallback, useRef, useState } from 'react'\n\nimport type { CreateUploadResult } from '../types.js'\nimport type { PluginApi } from './api.js'\n\nimport { ChunkedUpload } from './chunkedUpload.js'\n\nexport type UploadState =\n | { error: string; phase: 'error' }\n | { loaded: number; paused: boolean; phase: 'uploading'; result: CreateUploadResult; total: number }\n | { phase: 'done'; result: CreateUploadResult }\n | { phase: 'idle' }\n | { phase: 'preparing' }\n\ntype Pausable = { pause: () => void; resume: () => void }\n\n/**\n * Uploads a file directly from the browser to the video provider, with whichever protocol the provider\n * chose: a multipart `post`, resumable `tus`, or `put-chunked`. `tus-js-client` is only loaded when a\n * tus upload starts.\n */\nexport const useVideoUpload = (api: PluginApi) => {\n const [state, setState] = useState<UploadState>({ phase: 'idle' })\n const pausableRef = useRef<null | Pausable>(null)\n const cancelRef = useRef<null | (() => void)>(null)\n\n const start = useCallback(\n async (\n file: File,\n options: { id?: number | string; provider?: string; title?: string } = {},\n ): Promise<CreateUploadResult | null> => {\n setState({ phase: 'preparing' })\n let result: CreateUploadResult\n try {\n result = await api.createUpload({\n filename: file.name,\n id: options.id,\n provider: options.provider,\n size: file.size,\n title: options.title,\n })\n } catch (err) {\n setState({ error: (err as Error).message, phase: 'error' })\n return null\n }\n setState({ loaded: 0, paused: false, phase: 'uploading', result, total: file.size })\n\n const onProgress = (loaded: number, total: number) =>\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, loaded, total } : prev))\n const upload = result.upload\n\n try {\n if (upload.protocol === 'tus') {\n const { Upload } = await import('tus-js-client')\n await new Promise<void>((resolve, reject) => {\n const tus: TusUpload = new Upload(file, {\n // tus-js-client casts the option with Number(), so an explicit undefined would become NaN\n // (empty PATCH requests forever). Leave it out to keep the default: one request.\n ...(upload.chunkSize ? { chunkSize: upload.chunkSize } : {}),\n endpoint: upload.endpoint,\n headers: upload.headers,\n metadata: { filename: file.name, filetype: file.type, ...upload.metadata },\n onError: reject,\n onProgress,\n onSuccess: () => resolve(),\n retryDelays: [0, 1000, 3000, 5000, 10000],\n uploadSize: file.size,\n uploadUrl: upload.uploadUrl,\n })\n pausableRef.current = { pause: () => void tus.abort(), resume: () => tus.start() }\n cancelRef.current = () => {\n // Ask the server to discard the partial upload; not every tus server supports termination.\n tus.abort(true).catch(() => undefined)\n reject(new Error('Upload cancelled'))\n }\n tus.start()\n })\n } else if (upload.protocol === 'put-chunked') {\n const chunked = new ChunkedUpload({ chunkSize: upload.chunkSize, file, headers: upload.headers, onProgress, url: upload.url })\n await new Promise<void>((resolve, reject) => {\n let cancelled = false\n const run = () =>\n chunked.start().then(resolve, (err: Error) => {\n // A pause aborts the request in flight; only real failures (or a cancel) end the upload.\n if (cancelled || err.name !== 'AbortError') {\n reject(cancelled ? new Error('Upload cancelled') : err)\n }\n })\n pausableRef.current = { pause: () => chunked.pause(), resume: () => void run() }\n cancelRef.current = () => {\n cancelled = true\n chunked.pause()\n }\n void run()\n })\n } else {\n await new Promise<void>((resolve, reject) => {\n const xhr = new XMLHttpRequest()\n cancelRef.current = () => xhr.abort()\n xhr.upload.onprogress = (e) => e.lengthComputable && onProgress(e.loaded, e.total)\n xhr.onload = () =>\n xhr.status >= 200 && xhr.status < 300 ? resolve() : reject(new Error(`Upload failed (HTTP ${xhr.status})`))\n xhr.onerror = () => reject(new Error('Network error during upload'))\n xhr.onabort = () => reject(new Error('Upload cancelled'))\n const form = new FormData()\n form.append(upload.fieldName ?? 'file', file, file.name)\n xhr.open('POST', upload.url)\n xhr.send(form)\n })\n }\n } catch (err) {\n setState({ error: (err as Error).message || 'Upload failed', phase: 'error' })\n return null\n } finally {\n pausableRef.current = null\n cancelRef.current = null\n }\n setState({ phase: 'done', result })\n return result\n },\n [api],\n )\n\n const pause = useCallback(() => {\n pausableRef.current?.pause()\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, paused: true } : prev))\n }, [])\n\n const resume = useCallback(() => {\n pausableRef.current?.resume()\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, paused: false } : prev))\n }, [])\n\n const cancel = useCallback(() => {\n cancelRef.current?.()\n setState({ error: 'Upload cancelled', phase: 'error' })\n }, [])\n\n const reset = useCallback(() => setState({ phase: 'idle' }), [])\n\n return { cancel, canPause: Boolean(pausableRef.current), pause, reset, resume, start, state }\n}\n"],"names":["useCallback","useRef","useState","ChunkedUpload","useVideoUpload","api","state","setState","phase","pausableRef","cancelRef","start","file","options","result","createUpload","filename","name","id","provider","size","title","err","error","message","loaded","paused","total","onProgress","prev","upload","protocol","Upload","Promise","resolve","reject","tus","chunkSize","endpoint","headers","metadata","filetype","type","onError","onSuccess","retryDelays","uploadSize","uploadUrl","current","pause","abort","resume","catch","undefined","Error","chunked","url","cancelled","run","then","xhr","XMLHttpRequest","onprogress","e","lengthComputable","onload","status","onerror","onabort","form","FormData","append","fieldName","open","send","cancel","reset","canPause","Boolean"],"mappings":"AAAA;AAIA,SAASA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAKrD,SAASC,aAAa,QAAQ,qBAAoB;AAWlD;;;;CAIC,GACD,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,MAAM,CAACC,OAAOC,SAAS,GAAGL,SAAsB;QAAEM,OAAO;IAAO;IAChE,MAAMC,cAAcR,OAAwB;IAC5C,MAAMS,YAAYT,OAA4B;IAE9C,MAAMU,QAAQX,YACZ,OACEY,MACAC,UAAuE,CAAC,CAAC;QAEzEN,SAAS;YAAEC,OAAO;QAAY;QAC9B,IAAIM;QACJ,IAAI;YACFA,SAAS,MAAMT,IAAIU,YAAY,CAAC;gBAC9BC,UAAUJ,KAAKK,IAAI;gBACnBC,IAAIL,QAAQK,EAAE;gBACdC,UAAUN,QAAQM,QAAQ;gBAC1BC,MAAMR,KAAKQ,IAAI;gBACfC,OAAOR,QAAQQ,KAAK;YACtB;QACF,EAAE,OAAOC,KAAK;YACZf,SAAS;gBAAEgB,OAAO,AAACD,IAAcE,OAAO;gBAAEhB,OAAO;YAAQ;YACzD,OAAO;QACT;QACAD,SAAS;YAAEkB,QAAQ;YAAGC,QAAQ;YAAOlB,OAAO;YAAaM;YAAQa,OAAOf,KAAKQ,IAAI;QAAC;QAElF,MAAMQ,aAAa,CAACH,QAAgBE,QAClCpB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ACF;QACF,EAAE,OAAO/C,KAAK;YACZf,SAAS;gBAAEgB,OAAO,AAACD,IAAcE,OAAO,IAAI;gBAAiBhB,OAAO;YAAQ;YAC5E,OAAO;QACT,SAAU;YACRC,YAAYuC,OAAO,GAAG;YACtBtC,UAAUsC,OAAO,GAAG;QACtB;QACAzC,SAAS;YAAEC,OAAO;YAAQM;QAAO;QACjC,OAAOA;IACT,GACA;QAACT;KAAI;IAGP,MAAM4C,QAAQjD,YAAY;QACxBS,YAAYuC,OAAO,EAAEC;QACrB1C,SAAS,CAACsB,OAAUA,KAAKrB,KAAK,KAAK,cAAc;gBAAE,GAAGqB,IAAI;gBAAEH,QAAQ;YAAK,IAAIG;IAC/E,GAAG,EAAE;IAEL,MAAMsB,SAASnD,YAAY;QACzBS,YAAYuC,OAAO,EAAEG;QACrB5C,SAAS,CAACsB,OAAUA,KAAKrB,KAAK,KAAK,cAAc;gBAAE,GAAGqB,IAAI;gBAAEH,QAAQ;YAAM,IAAIG;IAChF,GAAG,EAAE;IAEL,MAAM8C,SAAS3E,YAAY;QACzBU,UAAUsC,OAAO;QACjBzC,SAAS;YAAEgB,OAAO;YAAoBf,OAAO;QAAQ;IACvD,GAAG,EAAE;IAEL,MAAMoE,QAAQ5E,YAAY,IAAMO,SAAS;YAAEC,OAAO;QAAO,IAAI,EAAE;IAE/D,OAAO;QAAEmE;QAAQE,UAAUC,QAAQrE,YAAYuC,OAAO;QAAGC;QAAO2B;QAAOzB;QAAQxC;QAAOL;IAAM;AAC9F,EAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for errors returned by a video provider's API. Endpoints map these to HTTP responses
|
|
3
|
+
* (404 → 404, 429 → 429, anything else → 502) and include `details` as `providerErrors`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ProviderError extends Error {
|
|
6
|
+
/** Provider-specific error details (e.g. Cloudflare's `errors` array). */
|
|
7
|
+
readonly details: unknown[];
|
|
8
|
+
/** Brand checked by `isProviderError` (instanceof breaks when a bundler duplicates this module). */
|
|
9
|
+
readonly isProviderError = true;
|
|
10
|
+
/** Id of the provider that failed, e.g. `cloudflare`. */
|
|
11
|
+
readonly provider: string;
|
|
12
|
+
/** HTTP status from the provider, or 0 when it couldn't be reached. */
|
|
13
|
+
readonly status: number;
|
|
14
|
+
constructor(message: string, options: {
|
|
15
|
+
details?: unknown[];
|
|
16
|
+
provider: string;
|
|
17
|
+
status: number;
|
|
18
|
+
});
|
|
19
|
+
/** True when the provider reports that the resource doesn't exist. */
|
|
20
|
+
get isNotFound(): boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const isProviderError: (err: unknown) => err is ProviderError;
|
|
23
|
+
/** Thrown by the core when a provider lacks a capability an operation needs (HTTP 501). */
|
|
24
|
+
export declare class UnsupportedFeatureError extends Error {
|
|
25
|
+
readonly status = 501;
|
|
26
|
+
constructor(provider: string, feature: string);
|
|
27
|
+
}
|