payload-video-streaming 0.2.0-beta.0 → 0.2.0-beta.1
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/README.md +174 -543
- package/dist/access.d.ts +35 -0
- package/dist/access.js +53 -0
- package/dist/access.js.map +1 -0
- package/dist/bin/args.d.ts +13 -0
- package/dist/bin/args.js +61 -0
- package/dist/bin/args.js.map +1 -1
- package/dist/bin/cli.js +9 -1
- package/dist/bin/cli.js.map +1 -1
- package/dist/bin/webhooks.d.ts +15 -0
- package/dist/bin/webhooks.js +149 -0
- package/dist/bin/webhooks.js.map +1 -0
- package/dist/collection.js +148 -1
- package/dist/collection.js.map +1 -1
- package/dist/components/BulkUploader.d.ts +16 -0
- package/dist/components/BulkUploader.js +226 -0
- package/dist/components/BulkUploader.js.map +1 -0
- package/dist/components/ListUploader.js +22 -0
- package/dist/components/ListUploader.js.map +1 -1
- package/dist/components/Uploader.d.ts +5 -0
- package/dist/components/Uploader.js +13 -4
- package/dist/components/Uploader.js.map +1 -1
- package/dist/components/VideoField.js +9 -5
- package/dist/components/VideoField.js.map +1 -1
- package/dist/components/VideoRelationshipField.d.ts +16 -0
- package/dist/components/VideoRelationshipField.js +106 -0
- package/dist/components/VideoRelationshipField.js.map +1 -0
- package/dist/components/WebhookStatusPanel.d.ts +6 -0
- package/dist/components/WebhookStatusPanel.js +143 -0
- package/dist/components/WebhookStatusPanel.js.map +1 -0
- package/dist/components/api.d.ts +7 -1
- package/dist/components/api.js +2 -0
- package/dist/components/api.js.map +1 -1
- package/dist/components/uploadFile.d.ts +30 -0
- package/dist/components/uploadFile.js +140 -0
- package/dist/components/uploadFile.js.map +1 -0
- package/dist/components/usePluginApi.d.ts +5 -0
- package/dist/components/useUploadQueue.d.ts +35 -0
- package/dist/components/useUploadQueue.js +135 -0
- package/dist/components/useUploadQueue.js.map +1 -0
- package/dist/components/useVideoUpload.d.ts +3 -7
- package/dist/components/useVideoUpload.js +29 -123
- package/dist/components/useVideoUpload.js.map +1 -1
- package/dist/core/provider.d.ts +16 -0
- package/dist/core/provider.js.map +1 -1
- package/dist/endpoints/index.js +38 -2
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/client.d.ts +9 -0
- package/dist/exports/client.js +5 -0
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/react.d.ts +12 -0
- package/dist/exports/react.js +7 -0
- package/dist/exports/react.js.map +1 -1
- package/dist/fields.d.ts +11 -2
- package/dist/fields.js +62 -2
- package/dist/fields.js.map +1 -1
- package/dist/frontend/VideoUploader.d.ts +65 -0
- package/dist/frontend/VideoUploader.js +260 -0
- package/dist/frontend/VideoUploader.js.map +1 -0
- package/dist/frontend/useVideoStatus.d.ts +26 -0
- package/dist/frontend/useVideoStatus.js +68 -0
- package/dist/frontend/useVideoStatus.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +7 -2
- package/dist/options.js +65 -2
- package/dist/options.js.map +1 -1
- package/dist/plugin.js +80 -1
- package/dist/plugin.js.map +1 -1
- package/dist/providers/bunny/provider.d.ts +2 -1
- package/dist/providers/bunny/provider.js +8 -0
- package/dist/providers/bunny/provider.js.map +1 -1
- package/dist/providers/cloudflare/provider.d.ts +2 -1
- package/dist/providers/cloudflare/provider.js +11 -0
- package/dist/providers/cloudflare/provider.js.map +1 -1
- package/dist/providers/mux/provider.d.ts +2 -1
- package/dist/providers/mux/provider.js +9 -0
- package/dist/providers/mux/provider.js.map +1 -1
- package/dist/service.d.ts +28 -1
- package/dist/service.js +114 -4
- package/dist/service.js.map +1 -1
- package/dist/types.d.ts +155 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -1
package/dist/fields.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fields.ts"],"sourcesContent":["import type { Field, RelationshipField } from 'payload'\n\nimport { DEFAULT_COLLECTION_SLUG } from './options.js'\n\nexport type VideoFieldArgs = {\n /** Slug of the videos collection if you changed it. */\n collectionSlug?: string\n /** Allow selecting multiple videos. */\n hasMany?: boolean\n name: string\n} & Partial<Omit<RelationshipField, 'hasMany' | 'name' | 'relationTo' | 'type'>>\n\n/**\n * A relationship field pointing at the videos collection, for use in your own\n * collections (e.g. `posts.heroVideo`). Populate it with `depth >= 1` to get `playback` URLs.\n */\nexport const videoField = ({\n name,\n collectionSlug = DEFAULT_COLLECTION_SLUG,\n hasMany = false,\n ...rest\n}: VideoFieldArgs): Field
|
|
1
|
+
{"version":3,"sources":["../src/fields.ts"],"sourcesContent":["import type { Field, FieldHook, PayloadRequest, RelationshipField } from 'payload'\n\nimport { DEFAULT_COLLECTION_SLUG } from './options.js'\n\n/** `req.context` key holding the ids of the videos a request's documents embed. */\nexport const embeddedVideosKey = (collectionSlug: string): string => `payload-video-streaming:embedded:${collectionSlug}`\n\n/** Ids of the videos that documents read in this request embed through `videoField()`. */\nexport const embeddedVideoIds = (req: Pick<PayloadRequest, 'context'>, collectionSlug: string): (number | string)[] => {\n const set = req.context?.[embeddedVideosKey(collectionSlug)]\n return set instanceof Set ? [...(set as Set<number | string>)] : []\n}\n\nconst idOf = (value: unknown): number | string | undefined => {\n if (typeof value === 'string' || typeof value === 'number') {\n return value\n }\n if (value && typeof value === 'object') {\n const v = value as { id?: unknown; value?: unknown }\n return idOf('value' in v ? v.value : v.id)\n }\n return undefined\n}\n\n/**\n * Remembers which videos the document being read embeds, before Payload populates the relationship.\n * The videos collection's read access lets this request read those videos (unless they're\n * restricted), so visitors can watch videos on pages they can read. See `playback.embedded`.\n */\nconst rememberEmbedded =\n (collectionSlug: string): FieldHook =>\n ({ req, value }) => {\n const ids = (Array.isArray(value) ? value : [value]).map(idOf).filter((id) => id !== undefined)\n if (ids.length && req?.context) {\n const key = embeddedVideosKey(collectionSlug)\n const set = (req.context[key] as Set<number | string> | undefined) ?? new Set<number | string>()\n for (const id of ids) {\n set.add(id)\n }\n req.context[key] = set\n }\n return value\n }\n\nexport type VideoFieldArgs = {\n /** Slug of the videos collection if you changed it. */\n collectionSlug?: string\n /** Allow selecting multiple videos. */\n hasMany?: boolean\n name: string\n /**\n * Show \"Upload new video\" under the picker, so editors can upload without leaving the document.\n * Default true. Ignored when you set your own `admin.components.Field`.\n */\n upload?: boolean\n} & Partial<Omit<RelationshipField, 'hasMany' | 'name' | 'relationTo' | 'type'>>\n\n/**\n * A relationship field pointing at the videos collection, for use in your own\n * collections (e.g. `posts.heroVideo`). Populate it with `depth >= 1` to get `playback` URLs.\n */\nexport const videoField = ({\n name,\n collectionSlug = DEFAULT_COLLECTION_SLUG,\n hasMany = false,\n upload = true,\n ...rest\n}: VideoFieldArgs): Field => {\n const admin = (rest.admin ?? {}) as NonNullable<RelationshipField['admin']>\n const withUpload =\n upload && !admin.components?.Field\n ? {\n ...admin,\n components: {\n ...admin.components,\n Field: { clientProps: { collectionSlug }, path: 'payload-video-streaming/client#VideoRelationshipField' },\n },\n }\n : rest.admin\n return {\n ...rest,\n name,\n type: 'relationship',\n ...(withUpload ? { admin: withUpload } : {}),\n hasMany,\n hooks: { ...rest.hooks, afterRead: [rememberEmbedded(collectionSlug), ...(rest.hooks?.afterRead ?? [])] },\n relationTo: collectionSlug,\n } as Field\n}\n"],"names":["DEFAULT_COLLECTION_SLUG","embeddedVideosKey","collectionSlug","embeddedVideoIds","req","set","context","Set","idOf","value","v","id","undefined","rememberEmbedded","ids","Array","isArray","map","filter","length","key","add","videoField","name","hasMany","upload","rest","admin","withUpload","components","Field","clientProps","path","type","hooks","afterRead","relationTo"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,eAAc;AAEtD,iFAAiF,GACjF,OAAO,MAAMC,oBAAoB,CAACC,iBAAmC,CAAC,iCAAiC,EAAEA,gBAAgB,CAAA;AAEzH,wFAAwF,GACxF,OAAO,MAAMC,mBAAmB,CAACC,KAAsCF;IACrE,MAAMG,MAAMD,IAAIE,OAAO,EAAE,CAACL,kB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GAAGD,IAAI;QACPH;QACAU,MAAM;QACN,GAAIL,aAAa;YAAED,OAAOC;QAAW,IAAI,CAAC,CAAC;QAC3CJ;QACAU,OAAO;YAAE,GAAGR,KAAKQ,KAAK;YAAEC,WAAW;gBAACtB,iBAAiBX;mBAAqBwB,KAAKQ,KAAK,EAAEC,aAAa,EAAE;aAAE;QAAC;QACxGC,YAAYlC;IACd;AACF,EAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CreateUploadResult, VideoDoc } from '../types.js';
|
|
3
|
+
export type VideoUploaderState = {
|
|
4
|
+
doc: null | VideoDoc;
|
|
5
|
+
id: number | string;
|
|
6
|
+
phase: 'processing';
|
|
7
|
+
} | {
|
|
8
|
+
doc: VideoDoc;
|
|
9
|
+
id: number | string;
|
|
10
|
+
phase: 'ready';
|
|
11
|
+
} | {
|
|
12
|
+
error: string;
|
|
13
|
+
id?: number | string;
|
|
14
|
+
phase: 'error';
|
|
15
|
+
} | {
|
|
16
|
+
canPause: boolean;
|
|
17
|
+
loaded: number;
|
|
18
|
+
paused: boolean;
|
|
19
|
+
phase: 'uploading';
|
|
20
|
+
total: number;
|
|
21
|
+
} | {
|
|
22
|
+
phase: 'idle';
|
|
23
|
+
};
|
|
24
|
+
export type VideoUploaderControls = {
|
|
25
|
+
cancel(): void;
|
|
26
|
+
pause(): void;
|
|
27
|
+
/** Back to an empty form, for another upload. */
|
|
28
|
+
reset(): void;
|
|
29
|
+
resume(): void;
|
|
30
|
+
};
|
|
31
|
+
export type VideoUploaderProps = {
|
|
32
|
+
/** `accept` of the file input. Default: video files. */
|
|
33
|
+
accept?: string;
|
|
34
|
+
/** REST API base. Default `/api`. */
|
|
35
|
+
apiRoute?: string;
|
|
36
|
+
/** Replace a custom UI: receives the state and controls (the form still handles file picking). */
|
|
37
|
+
children?: (state: VideoUploaderState, controls: VideoUploaderControls) => React.ReactNode;
|
|
38
|
+
className?: string;
|
|
39
|
+
/** Default `videos`. */
|
|
40
|
+
collectionSlug?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Refuse larger files in the browser, before anything is uploaded. Mirror `upload.maxFileSize`
|
|
43
|
+
* (the server enforces it either way).
|
|
44
|
+
*/
|
|
45
|
+
maxFileSize?: number;
|
|
46
|
+
/** The upload failed, or the provider couldn't process the video. */
|
|
47
|
+
onError?: (error: string) => void;
|
|
48
|
+
/** The video finished processing and can be played. */
|
|
49
|
+
onReady?: (doc: VideoDoc) => void;
|
|
50
|
+
/** The file reached the provider; processing starts. */
|
|
51
|
+
onUploaded?: (result: CreateUploadResult) => void;
|
|
52
|
+
/** Provider id. Default: the plugin's default provider. */
|
|
53
|
+
provider?: string;
|
|
54
|
+
/** Show a title input. Default true (the file name is used when it's left empty). */
|
|
55
|
+
showTitle?: boolean;
|
|
56
|
+
/** Poll with `POST /:id/sync` while processing (see `useVideoStatus`). Default false. */
|
|
57
|
+
sync?: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* An upload form for your site's frontend, e.g. members uploading their own videos: pick a file,
|
|
61
|
+
* optionally a title, then follow the upload and the provider's processing until the video is ready.
|
|
62
|
+
* Uses the logged-in user's session, so collection access and the plugin's upload rules apply.
|
|
63
|
+
* Unstyled: target the `pvs-uploader*` class names or `data-phase`, or render your own UI with `children`.
|
|
64
|
+
*/
|
|
65
|
+
export declare const VideoUploader: React.FC<VideoUploaderProps>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { createPluginApi } from '../components/api.js';
|
|
5
|
+
import { uploadVideoFile } from '../components/uploadFile.js';
|
|
6
|
+
import { useVideoStatus } from './useVideoStatus.js';
|
|
7
|
+
const formatMB = (bytes)=>`${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
8
|
+
/**
|
|
9
|
+
* An upload form for your site's frontend, e.g. members uploading their own videos: pick a file,
|
|
10
|
+
* optionally a title, then follow the upload and the provider's processing until the video is ready.
|
|
11
|
+
* Uses the logged-in user's session, so collection access and the plugin's upload rules apply.
|
|
12
|
+
* Unstyled: target the `pvs-uploader*` class names or `data-phase`, or render your own UI with `children`.
|
|
13
|
+
*/ export const VideoUploader = ({ accept = 'video/*', apiRoute = '/api', children, className, collectionSlug = 'videos', maxFileSize, onError, onReady, onUploaded, provider, showTitle = true, sync = false })=>{
|
|
14
|
+
const api = useMemo(()=>createPluginApi(apiRoute, collectionSlug), [
|
|
15
|
+
apiRoute,
|
|
16
|
+
collectionSlug
|
|
17
|
+
]);
|
|
18
|
+
const [state, setState] = useState({
|
|
19
|
+
phase: 'idle'
|
|
20
|
+
});
|
|
21
|
+
const [file, setFile] = useState(null);
|
|
22
|
+
const [title, setTitle] = useState('');
|
|
23
|
+
const controller = useRef(null);
|
|
24
|
+
const processingId = state.phase === 'processing' ? state.id : null;
|
|
25
|
+
const status = useVideoStatus(processingId, {
|
|
26
|
+
apiRoute,
|
|
27
|
+
collectionSlug,
|
|
28
|
+
sync
|
|
29
|
+
});
|
|
30
|
+
const callbacks = useRef({
|
|
31
|
+
onError,
|
|
32
|
+
onReady,
|
|
33
|
+
onUploaded
|
|
34
|
+
});
|
|
35
|
+
callbacks.current = {
|
|
36
|
+
onError,
|
|
37
|
+
onReady,
|
|
38
|
+
onUploaded
|
|
39
|
+
};
|
|
40
|
+
// Settle once the polled document is ready or failed. While processing, the doc comes from `status`.
|
|
41
|
+
useEffect(()=>{
|
|
42
|
+
if (processingId === null || !status.doc) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (status.status === 'ready') {
|
|
46
|
+
setState({
|
|
47
|
+
doc: status.doc,
|
|
48
|
+
id: processingId,
|
|
49
|
+
phase: 'ready'
|
|
50
|
+
});
|
|
51
|
+
callbacks.current.onReady?.(status.doc);
|
|
52
|
+
} else if (status.status === 'error') {
|
|
53
|
+
const message = status.doc.error?.message || 'The video could not be processed';
|
|
54
|
+
setState({
|
|
55
|
+
error: message,
|
|
56
|
+
id: processingId,
|
|
57
|
+
phase: 'error'
|
|
58
|
+
});
|
|
59
|
+
callbacks.current.onError?.(message);
|
|
60
|
+
}
|
|
61
|
+
}, [
|
|
62
|
+
processingId,
|
|
63
|
+
status.doc,
|
|
64
|
+
status.status
|
|
65
|
+
]);
|
|
66
|
+
const view = state.phase === 'processing' ? {
|
|
67
|
+
...state,
|
|
68
|
+
doc: status.doc
|
|
69
|
+
} : state;
|
|
70
|
+
useEffect(()=>()=>controller.current?.cancel(), []);
|
|
71
|
+
const fail = (error)=>{
|
|
72
|
+
setState({
|
|
73
|
+
error,
|
|
74
|
+
phase: 'error'
|
|
75
|
+
});
|
|
76
|
+
callbacks.current.onError?.(error);
|
|
77
|
+
};
|
|
78
|
+
const submit = async (event)=>{
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
if (!file) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (maxFileSize !== undefined && file.size > maxFileSize) {
|
|
84
|
+
fail(`This file is ${formatMB(file.size)}; the limit is ${formatMB(maxFileSize)}.`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
setState({
|
|
88
|
+
canPause: false,
|
|
89
|
+
loaded: 0,
|
|
90
|
+
paused: false,
|
|
91
|
+
phase: 'uploading',
|
|
92
|
+
total: file.size
|
|
93
|
+
});
|
|
94
|
+
const upload = uploadVideoFile(api, file, {
|
|
95
|
+
provider,
|
|
96
|
+
title: title.trim() || undefined
|
|
97
|
+
}, {
|
|
98
|
+
onCreated: (result)=>setState((prev)=>prev.phase === 'uploading' ? {
|
|
99
|
+
...prev,
|
|
100
|
+
canPause: result.upload.protocol !== 'post'
|
|
101
|
+
} : prev),
|
|
102
|
+
onProgress: (loaded, total)=>setState((prev)=>prev.phase === 'uploading' ? {
|
|
103
|
+
...prev,
|
|
104
|
+
loaded,
|
|
105
|
+
total
|
|
106
|
+
} : prev)
|
|
107
|
+
});
|
|
108
|
+
controller.current = upload;
|
|
109
|
+
try {
|
|
110
|
+
const result = await upload.done;
|
|
111
|
+
callbacks.current.onUploaded?.(result);
|
|
112
|
+
setState({
|
|
113
|
+
doc: null,
|
|
114
|
+
id: result.id,
|
|
115
|
+
phase: 'processing'
|
|
116
|
+
});
|
|
117
|
+
} catch (err) {
|
|
118
|
+
fail(err.message || 'Upload failed');
|
|
119
|
+
} finally{
|
|
120
|
+
controller.current = null;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const controls = {
|
|
124
|
+
cancel: ()=>controller.current?.cancel(),
|
|
125
|
+
pause: ()=>{
|
|
126
|
+
controller.current?.pause();
|
|
127
|
+
setState((prev)=>prev.phase === 'uploading' ? {
|
|
128
|
+
...prev,
|
|
129
|
+
paused: true
|
|
130
|
+
} : prev);
|
|
131
|
+
},
|
|
132
|
+
reset: ()=>{
|
|
133
|
+
setFile(null);
|
|
134
|
+
setTitle('');
|
|
135
|
+
setState({
|
|
136
|
+
phase: 'idle'
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
resume: ()=>{
|
|
140
|
+
controller.current?.resume();
|
|
141
|
+
setState((prev)=>prev.phase === 'uploading' ? {
|
|
142
|
+
...prev,
|
|
143
|
+
paused: false
|
|
144
|
+
} : prev);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const busy = state.phase === 'uploading' || state.phase === 'processing';
|
|
148
|
+
return /*#__PURE__*/ _jsxs("form", {
|
|
149
|
+
className: [
|
|
150
|
+
'pvs-uploader',
|
|
151
|
+
className
|
|
152
|
+
].filter(Boolean).join(' '),
|
|
153
|
+
"data-phase": view.phase,
|
|
154
|
+
onSubmit: submit,
|
|
155
|
+
children: [
|
|
156
|
+
state.phase === 'idle' || state.phase === 'error' ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
157
|
+
children: [
|
|
158
|
+
/*#__PURE__*/ _jsx("input", {
|
|
159
|
+
accept: accept,
|
|
160
|
+
"aria-label": "Video file",
|
|
161
|
+
className: "pvs-uploader-file",
|
|
162
|
+
name: "file",
|
|
163
|
+
onChange: (e)=>setFile(e.target.files?.[0] ?? null),
|
|
164
|
+
required: true,
|
|
165
|
+
type: "file"
|
|
166
|
+
}),
|
|
167
|
+
showTitle && /*#__PURE__*/ _jsx("input", {
|
|
168
|
+
"aria-label": "Title",
|
|
169
|
+
className: "pvs-uploader-title",
|
|
170
|
+
name: "title",
|
|
171
|
+
onChange: (e)=>setTitle(e.target.value),
|
|
172
|
+
placeholder: "Title (optional)",
|
|
173
|
+
value: title
|
|
174
|
+
}),
|
|
175
|
+
/*#__PURE__*/ _jsx("button", {
|
|
176
|
+
className: "pvs-uploader-submit",
|
|
177
|
+
disabled: !file || busy,
|
|
178
|
+
type: "submit",
|
|
179
|
+
children: "Upload"
|
|
180
|
+
})
|
|
181
|
+
]
|
|
182
|
+
}) : null,
|
|
183
|
+
children ? children(view, controls) : /*#__PURE__*/ _jsx(DefaultStatus, {
|
|
184
|
+
controls: controls,
|
|
185
|
+
state: view
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
const DefaultStatus = ({ controls, state })=>{
|
|
191
|
+
switch(state.phase){
|
|
192
|
+
case 'error':
|
|
193
|
+
return /*#__PURE__*/ _jsx("p", {
|
|
194
|
+
className: "pvs-uploader-error",
|
|
195
|
+
role: "alert",
|
|
196
|
+
children: state.error
|
|
197
|
+
});
|
|
198
|
+
case 'processing':
|
|
199
|
+
return /*#__PURE__*/ _jsxs("p", {
|
|
200
|
+
className: "pvs-uploader-status",
|
|
201
|
+
role: "status",
|
|
202
|
+
children: [
|
|
203
|
+
"Uploaded. Processing",
|
|
204
|
+
state.doc?.progress ? ` (${Math.round(state.doc.progress)}%)` : '',
|
|
205
|
+
"…"
|
|
206
|
+
]
|
|
207
|
+
});
|
|
208
|
+
case 'ready':
|
|
209
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
210
|
+
className: "pvs-uploader-status",
|
|
211
|
+
role: "status",
|
|
212
|
+
children: [
|
|
213
|
+
/*#__PURE__*/ _jsx("p", {
|
|
214
|
+
children: "Your video is ready."
|
|
215
|
+
}),
|
|
216
|
+
/*#__PURE__*/ _jsx("button", {
|
|
217
|
+
onClick: controls.reset,
|
|
218
|
+
type: "button",
|
|
219
|
+
children: "Upload another"
|
|
220
|
+
})
|
|
221
|
+
]
|
|
222
|
+
});
|
|
223
|
+
case 'uploading':
|
|
224
|
+
{
|
|
225
|
+
const pct = state.total ? Math.round(state.loaded / state.total * 100) : 0;
|
|
226
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
227
|
+
className: "pvs-uploader-status",
|
|
228
|
+
role: "status",
|
|
229
|
+
children: [
|
|
230
|
+
/*#__PURE__*/ _jsx("progress", {
|
|
231
|
+
max: 100,
|
|
232
|
+
value: pct
|
|
233
|
+
}),
|
|
234
|
+
/*#__PURE__*/ _jsxs("span", {
|
|
235
|
+
children: [
|
|
236
|
+
state.paused ? 'Paused' : 'Uploading',
|
|
237
|
+
" ",
|
|
238
|
+
pct,
|
|
239
|
+
"%"
|
|
240
|
+
]
|
|
241
|
+
}),
|
|
242
|
+
state.canPause && /*#__PURE__*/ _jsx("button", {
|
|
243
|
+
onClick: state.paused ? controls.resume : controls.pause,
|
|
244
|
+
type: "button",
|
|
245
|
+
children: state.paused ? 'Resume' : 'Pause'
|
|
246
|
+
}),
|
|
247
|
+
/*#__PURE__*/ _jsx("button", {
|
|
248
|
+
onClick: controls.cancel,
|
|
249
|
+
type: "button",
|
|
250
|
+
children: "Cancel"
|
|
251
|
+
})
|
|
252
|
+
]
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
default:
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
//# sourceMappingURL=VideoUploader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/frontend/VideoUploader.tsx"],"sourcesContent":["'use client'\n\nimport React, { useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { CreateUploadResult, VideoDoc } from '../types.js'\n\nimport { createPluginApi } from '../components/api.js'\nimport { uploadVideoFile, type VideoUploadController } from '../components/uploadFile.js'\nimport { useVideoStatus } from './useVideoStatus.js'\n\nexport type VideoUploaderState =\n | { doc: null | VideoDoc; id: number | string; phase: 'processing' }\n | { doc: VideoDoc; id: number | string; phase: 'ready' }\n | { error: string; id?: number | string; phase: 'error' }\n | { canPause: boolean; loaded: number; paused: boolean; phase: 'uploading'; total: number }\n | { phase: 'idle' }\n\nexport type VideoUploaderControls = {\n cancel(): void\n pause(): void\n /** Back to an empty form, for another upload. */\n reset(): void\n resume(): void\n}\n\nexport type VideoUploaderProps = {\n /** `accept` of the file input. Default: video files. */\n accept?: string\n /** REST API base. Default `/api`. */\n apiRoute?: string\n /** Replace a custom UI: receives the state and controls (the form still handles file picking). */\n children?: (state: VideoUploaderState, controls: VideoUploaderControls) => React.ReactNode\n className?: string\n /** Default `videos`. */\n collectionSlug?: string\n /**\n * Refuse larger files in the browser, before anything is uploaded. Mirror `upload.maxFileSize`\n * (the server enforces it either way).\n */\n maxFileSize?: number\n /** The upload failed, or the provider couldn't process the video. */\n onError?: (error: string) => void\n /** The video finished processing and can be played. */\n onReady?: (doc: VideoDoc) => void\n /** The file reached the provider; processing starts. */\n onUploaded?: (result: CreateUploadResult) => void\n /** Provider id. Default: the plugin's default provider. */\n provider?: string\n /** Show a title input. Default true (the file name is used when it's left empty). */\n showTitle?: boolean\n /** Poll with `POST /:id/sync` while processing (see `useVideoStatus`). Default false. */\n sync?: boolean\n}\n\nconst formatMB = (bytes: number) => `${(bytes / 1024 / 1024).toFixed(1)} MB`\n\n/**\n * An upload form for your site's frontend, e.g. members uploading their own videos: pick a file,\n * optionally a title, then follow the upload and the provider's processing until the video is ready.\n * Uses the logged-in user's session, so collection access and the plugin's upload rules apply.\n * Unstyled: target the `pvs-uploader*` class names or `data-phase`, or render your own UI with `children`.\n */\nexport const VideoUploader: React.FC<VideoUploaderProps> = ({\n accept = 'video/*',\n apiRoute = '/api',\n children,\n className,\n collectionSlug = 'videos',\n maxFileSize,\n onError,\n onReady,\n onUploaded,\n provider,\n showTitle = true,\n sync = false,\n}) => {\n const api = useMemo(() => createPluginApi(apiRoute, collectionSlug), [apiRoute, collectionSlug])\n const [state, setState] = useState<VideoUploaderState>({ phase: 'idle' })\n const [file, setFile] = useState<File | null>(null)\n const [title, setTitle] = useState('')\n const controller = useRef<null | VideoUploadController>(null)\n const processingId = state.phase === 'processing' ? state.id : null\n const status = useVideoStatus(processingId, { apiRoute, collectionSlug, sync })\n const callbacks = useRef({ onError, onReady, onUploaded })\n callbacks.current = { onError, onReady, onUploaded }\n\n // Settle once the polled document is ready or failed. While processing, the doc comes from `status`.\n useEffect(() => {\n if (processingId === null || !status.doc) {\n return\n }\n if (status.status === 'ready') {\n setState({ doc: status.doc, id: processingId, phase: 'ready' })\n callbacks.current.onReady?.(status.doc)\n } else if (status.status === 'error') {\n const message = status.doc.error?.message || 'The video could not be processed'\n setState({ error: message, id: processingId, phase: 'error' })\n callbacks.current.onError?.(message)\n }\n }, [processingId, status.doc, status.status])\n\n const view: VideoUploaderState = state.phase === 'processing' ? { ...state, doc: status.doc } : state\n\n useEffect(() => () => controller.current?.cancel(), [])\n\n const fail = (error: string) => {\n setState({ error, phase: 'error' })\n callbacks.current.onError?.(error)\n }\n\n const submit = async (event: React.FormEvent) => {\n event.preventDefault()\n if (!file) {\n return\n }\n if (maxFileSize !== undefined && file.size > maxFileSize) {\n fail(`This file is ${formatMB(file.size)}; the limit is ${formatMB(maxFileSize)}.`)\n return\n }\n setState({ canPause: false, loaded: 0, paused: false, phase: 'uploading', total: file.size })\n const upload = uploadVideoFile(\n api,\n file,\n { provider, title: title.trim() || undefined },\n {\n onCreated: (result) =>\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, canPause: result.upload.protocol !== 'post' } : prev)),\n onProgress: (loaded, total) => setState((prev) => (prev.phase === 'uploading' ? { ...prev, loaded, total } : prev)),\n },\n )\n controller.current = upload\n try {\n const result = await upload.done\n callbacks.current.onUploaded?.(result)\n setState({ doc: null, id: result.id, phase: 'processing' })\n } catch (err) {\n fail((err as Error).message || 'Upload failed')\n } finally {\n controller.current = null\n }\n }\n\n const controls: VideoUploaderControls = {\n cancel: () => controller.current?.cancel(),\n pause: () => {\n controller.current?.pause()\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, paused: true } : prev))\n },\n reset: () => {\n setFile(null)\n setTitle('')\n setState({ phase: 'idle' })\n },\n resume: () => {\n controller.current?.resume()\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, paused: false } : prev))\n },\n }\n\n const busy = state.phase === 'uploading' || state.phase === 'processing'\n\n return (\n <form className={['pvs-uploader', className].filter(Boolean).join(' ')} data-phase={view.phase} onSubmit={submit}>\n {state.phase === 'idle' || state.phase === 'error' ? (\n <>\n <input\n accept={accept}\n aria-label=\"Video file\"\n className=\"pvs-uploader-file\"\n name=\"file\"\n onChange={(e) => setFile(e.target.files?.[0] ?? null)}\n required\n type=\"file\"\n />\n {showTitle && (\n <input\n aria-label=\"Title\"\n className=\"pvs-uploader-title\"\n name=\"title\"\n onChange={(e) => setTitle(e.target.value)}\n placeholder=\"Title (optional)\"\n value={title}\n />\n )}\n <button className=\"pvs-uploader-submit\" disabled={!file || busy} type=\"submit\">\n Upload\n </button>\n </>\n ) : null}\n {children ? children(view, controls) : <DefaultStatus controls={controls} state={view} />}\n </form>\n )\n}\n\nconst DefaultStatus: React.FC<{ controls: VideoUploaderControls; state: VideoUploaderState }> = ({ controls, state }) => {\n switch (state.phase) {\n case 'error':\n return (\n <p className=\"pvs-uploader-error\" role=\"alert\">\n {state.error}\n </p>\n )\n case 'processing':\n return (\n <p className=\"pvs-uploader-status\" role=\"status\">\n Uploaded. Processing{state.doc?.progress ? ` (${Math.round(state.doc.progress)}%)` : ''}…\n </p>\n )\n case 'ready':\n return (\n <div className=\"pvs-uploader-status\" role=\"status\">\n <p>Your video is ready.</p>\n <button onClick={controls.reset} type=\"button\">\n Upload another\n </button>\n </div>\n )\n case 'uploading': {\n const pct = state.total ? Math.round((state.loaded / state.total) * 100) : 0\n return (\n <div className=\"pvs-uploader-status\" role=\"status\">\n <progress max={100} value={pct} />\n <span>\n {state.paused ? 'Paused' : 'Uploading'} {pct}%\n </span>\n {state.canPause && (\n <button onClick={state.paused ? controls.resume : controls.pause} type=\"button\">\n {state.paused ? 'Resume' : 'Pause'}\n </button>\n )}\n <button onClick={controls.cancel} type=\"button\">\n Cancel\n </button>\n </div>\n )\n }\n default:\n return null\n }\n}\n"],"names":["React","useEffect","useMemo","useRef","useState","createPluginApi","uploadVideoFile","useVideoStatus","formatMB","bytes","toFixed","VideoUploader","accept","apiRoute","children","className","collectionSlug","maxFileSize","onError","onReady","onUploaded","provider","showTitle","sync","api","state","setState","phase","file","setFile","title","setTitle","controller","processingId","id","status","callbacks","current","doc","message","error","view","cancel","fail","submit","event","preventDefault","undefined","size","canPause","loaded","paused","total","upload","trim","onCreated","result","prev","protocol","onProgress","done","err","controls","pause","reset","resume","busy","form","filter","Boolean","join","data-phase","onSubmit","input","aria-label","name","onChange","e","target","files","required","type","value","placeholder","button","disabled","DefaultStatus","p","role","progress","Math","round","div","onClick","pct","max","span"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAInE,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,eAAe,QAAoC,8BAA6B;AACzF,SAASC,cAAc,QAAQ,sBAAqB;AA8CpD,MAAMC,WAAW,CAACC,QAAkB,GAAG,AAACA,CAAAA,QAAQ,OAAO,IAAG,EAAGC,OAAO,CAAC,GAAG,GAAG,CAAC;AAE5E;;;;;CAKC,GACD,OAAO,MAAMC,gBAA8C,CAAC,EAC1DC,SAAS,SAAS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AAM;4BAAEuC,MAAK;sCAAS;;;;YAKtD;QACA;YACE,OAAO;IACX;AACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { VideoStatus } from '../core/status.js';
|
|
2
|
+
import type { VideoDoc } from '../types.js';
|
|
3
|
+
export type UseVideoStatusOptions = {
|
|
4
|
+
/** REST API base. Default `/api`. */
|
|
5
|
+
apiRoute?: string;
|
|
6
|
+
/** Default `videos`. */
|
|
7
|
+
collectionSlug?: string;
|
|
8
|
+
/** Polling interval in ms. Default 3000. */
|
|
9
|
+
intervalMs?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Ask the provider on every poll (`POST /:id/sync`) instead of reading the document. Use it when no
|
|
12
|
+
* webhook or sync-pending task updates videos; the user needs update access to the video. Default false.
|
|
13
|
+
*/
|
|
14
|
+
sync?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type UseVideoStatusResult = {
|
|
17
|
+
doc: null | VideoDoc;
|
|
18
|
+
/** The last request's error, e.g. when the video can't be read. Polling continues. */
|
|
19
|
+
error: null | string;
|
|
20
|
+
status: null | VideoStatus;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Follows a video until it's `ready` or `error`, e.g. after a member uploaded it, by polling the
|
|
24
|
+
* plugin's REST API with the user's session. Stops polling once settled or when `id` is null.
|
|
25
|
+
*/
|
|
26
|
+
export declare const useVideoStatus: (id: null | number | string | undefined, options?: UseVideoStatusOptions) => UseVideoStatusResult;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { createPluginApi } from '../components/api.js';
|
|
4
|
+
/**
|
|
5
|
+
* Follows a video until it's `ready` or `error`, e.g. after a member uploaded it, by polling the
|
|
6
|
+
* plugin's REST API with the user's session. Stops polling once settled or when `id` is null.
|
|
7
|
+
*/ export const useVideoStatus = (id, options = {})=>{
|
|
8
|
+
const { apiRoute = '/api', collectionSlug = 'videos', intervalMs = 3000, sync = false } = options;
|
|
9
|
+
const api = useMemo(()=>createPluginApi(apiRoute, collectionSlug), [
|
|
10
|
+
apiRoute,
|
|
11
|
+
collectionSlug
|
|
12
|
+
]);
|
|
13
|
+
const [state, setState] = useState({
|
|
14
|
+
doc: null,
|
|
15
|
+
error: null,
|
|
16
|
+
status: null
|
|
17
|
+
});
|
|
18
|
+
const timer = useRef(undefined);
|
|
19
|
+
useEffect(()=>{
|
|
20
|
+
setState({
|
|
21
|
+
doc: null,
|
|
22
|
+
error: null,
|
|
23
|
+
status: null
|
|
24
|
+
});
|
|
25
|
+
if (id === null || id === undefined || id === '') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let stopped = false;
|
|
29
|
+
const poll = async ()=>{
|
|
30
|
+
try {
|
|
31
|
+
const doc = sync ? (await api.sync(id)).doc : await api.get(id);
|
|
32
|
+
if (stopped) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setState({
|
|
36
|
+
doc,
|
|
37
|
+
error: null,
|
|
38
|
+
status: doc.status ?? null
|
|
39
|
+
});
|
|
40
|
+
if (doc.status === 'ready' || doc.status === 'error') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (stopped) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setState((prev)=>({
|
|
48
|
+
...prev,
|
|
49
|
+
error: err.message
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
timer.current = setTimeout(()=>void poll(), intervalMs);
|
|
53
|
+
};
|
|
54
|
+
void poll();
|
|
55
|
+
return ()=>{
|
|
56
|
+
stopped = true;
|
|
57
|
+
clearTimeout(timer.current);
|
|
58
|
+
};
|
|
59
|
+
}, [
|
|
60
|
+
api,
|
|
61
|
+
id,
|
|
62
|
+
intervalMs,
|
|
63
|
+
sync
|
|
64
|
+
]);
|
|
65
|
+
return state;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=useVideoStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/frontend/useVideoStatus.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { VideoStatus } from '../core/status.js'\nimport type { VideoDoc } from '../types.js'\n\nimport { createPluginApi } from '../components/api.js'\n\nexport type UseVideoStatusOptions = {\n /** REST API base. Default `/api`. */\n apiRoute?: string\n /** Default `videos`. */\n collectionSlug?: string\n /** Polling interval in ms. Default 3000. */\n intervalMs?: number\n /**\n * Ask the provider on every poll (`POST /:id/sync`) instead of reading the document. Use it when no\n * webhook or sync-pending task updates videos; the user needs update access to the video. Default false.\n */\n sync?: boolean\n}\n\nexport type UseVideoStatusResult = {\n doc: null | VideoDoc\n /** The last request's error, e.g. when the video can't be read. Polling continues. */\n error: null | string\n status: null | VideoStatus\n}\n\n/**\n * Follows a video until it's `ready` or `error`, e.g. after a member uploaded it, by polling the\n * plugin's REST API with the user's session. Stops polling once settled or when `id` is null.\n */\nexport const useVideoStatus = (id: null | number | string | undefined, options: UseVideoStatusOptions = {}): UseVideoStatusResult => {\n const { apiRoute = '/api', collectionSlug = 'videos', intervalMs = 3000, sync = false } = options\n const api = useMemo(() => createPluginApi(apiRoute, collectionSlug), [apiRoute, collectionSlug])\n const [state, setState] = useState<UseVideoStatusResult>({ doc: null, error: null, status: null })\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n\n useEffect(() => {\n setState({ doc: null, error: null, status: null })\n if (id === null || id === undefined || id === '') {\n return\n }\n let stopped = false\n const poll = async () => {\n try {\n const doc = sync ? (await api.sync(id)).doc : await api.get(id)\n if (stopped) {\n return\n }\n setState({ doc, error: null, status: doc.status ?? null })\n if (doc.status === 'ready' || doc.status === 'error') {\n return\n }\n } catch (err) {\n if (stopped) {\n return\n }\n setState((prev) => ({ ...prev, error: (err as Error).message }))\n }\n timer.current = setTimeout(() => void poll(), intervalMs)\n }\n void poll()\n return () => {\n stopped = true\n clearTimeout(timer.current)\n }\n }, [api, id, intervalMs, sync])\n\n return state\n}\n"],"names":["useEffect","useMemo","useRef","useState","createPluginApi","useVideoStatus","id","options","apiRoute","collectionSlug","intervalMs","sync","api","state","setState","doc","error","status","timer","undefined","stopped","poll","get","err","prev","message","current","setTimeout","clearTimeout"],"mappings":"AAAA;AAEA,SAASA,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAK5D,SAASC,eAAe,QAAQ,uBAAsB;AAuBtD;;;CAGC,GACD,OAAO,MAAMC,iBAAiB,CAACC,IAAwCC,UAAiC,CAAC,CAAC;IACxG,MAAM,EAAEC,WAAW,MAAM,EAAEC,iBAAiB,QAAQ,EAAEC,aAAa,IAAI,EAAEC,OAAO,KAAK,EAAE,GAAGJ;IAC1F,MAAMK,MAAMX,QAAQ,IAAMG,gBAAgBI,UAAUC,iBAAiB;QAACD;QAAUC;KAAe;IAC/F,MAAM,CAACI,OAAOC,SAAS,GAAGX,SAA+B;QAAEY,KAAK;QAAMC,OAAO;QAAMC,QAAQ;IAAK;IAChG,MAAMC,QAAQhB,OAAkDiB;IAEhEnB,UAAU;QACRc,SAAS;YAAEC,KAAK;YAAMC,OAAO;YAAMC,QAAQ;QAAK;QAChD,IAAIX,OAAO,QAAQA,OAAOa,aAAab,OAAO,IAAI;YAChD;QACF;QACA,IAAIc,UAAU;QACd,MAAMC,OAAO;YACX,IAAI;gBACF,MAAMN,MAAMJ,OAAO,AAAC,CAAA,MAAMC,IAAID,IAAI,CAACL,GAAE,EAAGS,GAAG,GAAG,MAAMH,IAAIU,GAAG,CAAChB;gBAC5D,IAAIc,SAAS;oBACX;gBACF;gBACAN,SAAS;oBAAEC;oBAAKC,OAAO;oBAAMC,QAAQF,IAAIE,MAAM,IAAI;gBAAK;gBACxD,IAAIF,IAAIE,MAAM,KAAK,WAAWF,IAAIE,MAAM,KAAK,SAAS;oBACpD;gBACF;YACF,EAAE,OAAOM,KAAK;gBACZ,IAAIH,SAAS;oBACX;gBACF;gBACAN,SAAS,CAACU,OAAU,CAAA;wBAAE,GAAGA,IAAI;wBAAER,OAAO,AAACO,IAAcE,OAAO;oBAAC,CAAA;YAC/D;YACAP,MAAMQ,OAAO,GAAGC,WAAW,IAAM,KAAKN,QAAQX;QAChD;QACA,KAAKW;QACL,OAAO;YACLD,UAAU;YACVQ,aAAaV,MAAMQ,OAAO;QAC5B;IACF,GAAG;QAACd;QAAKN;QAAII;QAAYC;KAAK;IAE9B,OAAOE;AACT,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
export { anyOf, approvedOrOwner, isApprovedVideo, isVideoOwner, ownerOr } from './access.js';
|
|
1
2
|
export { DEFAULT_VIDEO_BLOCK_SLUG, VIDEO_BLOCK_ASPECT_RATIOS, videoBlock, videoBlockReferences } from './blocks.js';
|
|
2
3
|
export type { VideoBlockArgs } from './blocks.js';
|
|
3
4
|
export { isProviderError, ProviderError, UnsupportedFeatureError } from './core/errors.js';
|
|
4
5
|
export { clientProviderInfo } from './core/provider.js';
|
|
5
|
-
export type { AssetPatch, AssetSettings, CaptionTrack, ClientProviderInfo, DirectUpload, Downloads, DownloadState, DownloadType, ImportInput, NeutralAsset, PlaybackOptions, PlaybackResult, PlaybackUrls, ProviderCapabilities, ProviderEndpoint, ProviderRef, ProviderWebhook, ServerUploadInput, StoredAsset, UploadInput, UploadProtocol, VideoProvider, WebhookEvent, WebhookResult, } from './core/provider.js';
|
|
6
|
+
export type { AssetPatch, AssetSettings, CaptionTrack, ClientProviderInfo, DirectUpload, Downloads, DownloadState, DownloadType, ImportInput, NeutralAsset, PlaybackOptions, PlaybackResult, PlaybackUrls, ProviderCapabilities, ProviderEndpoint, ProviderRef, ProviderWebhook, ServerUploadInput, StoredAsset, UploadInput, UploadProtocol, VideoProvider, WebhookEvent, WebhookResult, WebhookSetup, } from './core/provider.js';
|
|
6
7
|
export { ProviderRegistry, validateProvider } from './core/registry.js';
|
|
7
8
|
export { isVideoStatus, VIDEO_STATUS_LABELS, VIDEO_STATUSES } from './core/status.js';
|
|
8
9
|
export type { VideoStatus } from './core/status.js';
|
|
9
10
|
export { videoOptionsFromEnv } from './env.js';
|
|
10
11
|
export type { VideoOptionsFromEnvOverrides } from './env.js';
|
|
11
|
-
export { videoField } from './fields.js';
|
|
12
|
+
export { embeddedVideoIds, videoField } from './fields.js';
|
|
12
13
|
export type { VideoFieldArgs } from './fields.js';
|
|
13
14
|
export type { VideoPlayerOptions, VideoSource } from './frontend/source.js';
|
|
14
15
|
export { blockPlayerOptions, getVideoSource, isVideoSourceExpired, videoDocId, videoIframeSrc } from './frontend/source.js';
|
|
@@ -16,5 +17,5 @@ export { CF_STREAM_LEGACY_SLUG, cfStreamLegacyCollection, cfStreamLegacyFields,
|
|
|
16
17
|
export type { LegacyCfStreamDoc, MigrateFromCfStreamOptions, MigrateFromCfStreamResult } from './migrate/cfStream.js';
|
|
17
18
|
export { DEFAULT_COLLECTION_SLUG, resolveOptions } from './options.js';
|
|
18
19
|
export { videoPlugin } from './plugin.js';
|
|
19
|
-
export { assetToDocData, getVideo, SKIP_SYNC_CONTEXT_KEY, VideoService } from './service.js';
|
|
20
|
-
export type { AdoptExistingResult, CreateUploadResult, ResolvedVideoOptions, SyncPendingResult, VideoAccess, VideoAccessArgs, VideoDoc, VideoPlayback, VideoPluginOptions, } from './types.js';
|
|
20
|
+
export { assetToDocData, getVideo, matchesAllowedType, SKIP_SYNC_CONTEXT_KEY, VideoService } from './service.js';
|
|
21
|
+
export type { AdoptExistingResult, CreateUploadResult, ResolvedVideoOptions, SyncPendingResult, VideoAccess, VideoAccessArgs, VideoDoc, VideoLifecycleHook, VideoModerationStatus, VideoPlayback, VideoPluginOptions, VideoStatusChangeArgs, VideoUploadCheck, WebhookHealth, WebhookStatus, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
export { anyOf, approvedOrOwner, isApprovedVideo, isVideoOwner, ownerOr } from './access.js';
|
|
1
2
|
export { DEFAULT_VIDEO_BLOCK_SLUG, VIDEO_BLOCK_ASPECT_RATIOS, videoBlock, videoBlockReferences } from './blocks.js';
|
|
2
3
|
export { isProviderError, ProviderError, UnsupportedFeatureError } from './core/errors.js';
|
|
3
4
|
export { clientProviderInfo } from './core/provider.js';
|
|
4
5
|
export { ProviderRegistry, validateProvider } from './core/registry.js';
|
|
5
6
|
export { isVideoStatus, VIDEO_STATUS_LABELS, VIDEO_STATUSES } from './core/status.js';
|
|
6
7
|
export { videoOptionsFromEnv } from './env.js';
|
|
7
|
-
export { videoField } from './fields.js';
|
|
8
|
+
export { embeddedVideoIds, videoField } from './fields.js';
|
|
8
9
|
export { blockPlayerOptions, getVideoSource, isVideoSourceExpired, videoDocId, videoIframeSrc } from './frontend/source.js';
|
|
9
10
|
export { CF_STREAM_LEGACY_SLUG, cfStreamLegacyCollection, cfStreamLegacyFields, mapCfStreamDoc, mapCfStreamFields, migrateFromCfStream } from './migrate/cfStream.js';
|
|
10
11
|
export { DEFAULT_COLLECTION_SLUG, resolveOptions } from './options.js';
|
|
11
12
|
export { videoPlugin } from './plugin.js';
|
|
12
|
-
export { assetToDocData, getVideo, SKIP_SYNC_CONTEXT_KEY, VideoService } from './service.js';
|
|
13
|
+
export { assetToDocData, getVideo, matchesAllowedType, SKIP_SYNC_CONTEXT_KEY, VideoService } from './service.js';
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { DEFAULT_VIDEO_BLOCK_SLUG, VIDEO_BLOCK_ASPECT_RATIOS, videoBlock, videoBlockReferences } from './blocks.js'\nexport type { VideoBlockArgs } from './blocks.js'\nexport { isProviderError, ProviderError, UnsupportedFeatureError } from './core/errors.js'\nexport { clientProviderInfo } from './core/provider.js'\nexport type {\n AssetPatch,\n AssetSettings,\n CaptionTrack,\n ClientProviderInfo,\n DirectUpload,\n Downloads,\n DownloadState,\n DownloadType,\n ImportInput,\n NeutralAsset,\n PlaybackOptions,\n PlaybackResult,\n PlaybackUrls,\n ProviderCapabilities,\n ProviderEndpoint,\n ProviderRef,\n ProviderWebhook,\n ServerUploadInput,\n StoredAsset,\n UploadInput,\n UploadProtocol,\n VideoProvider,\n WebhookEvent,\n WebhookResult,\n} from './core/provider.js'\nexport { ProviderRegistry, validateProvider } from './core/registry.js'\nexport { isVideoStatus, VIDEO_STATUS_LABELS, VIDEO_STATUSES } from './core/status.js'\nexport type { VideoStatus } from './core/status.js'\nexport { videoOptionsFromEnv } from './env.js'\nexport type { VideoOptionsFromEnvOverrides } from './env.js'\nexport { videoField } from './fields.js'\nexport type { VideoFieldArgs } from './fields.js'\nexport type { VideoPlayerOptions, VideoSource } from './frontend/source.js'\nexport { blockPlayerOptions, getVideoSource, isVideoSourceExpired, videoDocId, videoIframeSrc } from './frontend/source.js'\nexport {\n CF_STREAM_LEGACY_SLUG,\n cfStreamLegacyCollection,\n cfStreamLegacyFields,\n mapCfStreamDoc,\n mapCfStreamFields,\n migrateFromCfStream,\n} from './migrate/cfStream.js'\nexport type { LegacyCfStreamDoc, MigrateFromCfStreamOptions, MigrateFromCfStreamResult } from './migrate/cfStream.js'\nexport { DEFAULT_COLLECTION_SLUG, resolveOptions } from './options.js'\nexport { videoPlugin } from './plugin.js'\nexport { assetToDocData, getVideo, SKIP_SYNC_CONTEXT_KEY, VideoService } from './service.js'\nexport type {\n AdoptExistingResult,\n CreateUploadResult,\n ResolvedVideoOptions,\n SyncPendingResult,\n VideoAccess,\n VideoAccessArgs,\n VideoDoc,\n VideoPlayback,\n VideoPluginOptions,\n} from './types.js'\n"],"names":["DEFAULT_VIDEO_BLOCK_SLUG","VIDEO_BLOCK_ASPECT_RATIOS","videoBlock","videoBlockReferences","isProviderError","ProviderError","UnsupportedFeatureError","clientProviderInfo","ProviderRegistry","validateProvider","isVideoStatus","VIDEO_STATUS_LABELS","VIDEO_STATUSES","videoOptionsFromEnv","videoField","blockPlayerOptions","getVideoSource","isVideoSourceExpired","videoDocId","videoIframeSrc","CF_STREAM_LEGACY_SLUG","cfStreamLegacyCollection","cfStreamLegacyFields","mapCfStreamDoc","mapCfStreamFields","migrateFromCfStream","DEFAULT_COLLECTION_SLUG","resolveOptions","videoPlugin","assetToDocData","getVideo","SKIP_SYNC_CONTEXT_KEY","VideoService"],"mappings":"AAAA,SAASA,wBAAwB,EAAEC,yBAAyB,EAAEC,UAAU,EAAEC,oBAAoB,QAAQ,cAAa;AAEnH,SAASC,eAAe,EAAEC,aAAa,EAAEC,uBAAuB,QAAQ,mBAAkB;AAC1F,SAASC,kBAAkB,QAAQ,qBAAoB;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { anyOf, approvedOrOwner, isApprovedVideo, isVideoOwner, ownerOr } from './access.js'\nexport { DEFAULT_VIDEO_BLOCK_SLUG, VIDEO_BLOCK_ASPECT_RATIOS, videoBlock, videoBlockReferences } from './blocks.js'\nexport type { VideoBlockArgs } from './blocks.js'\nexport { isProviderError, ProviderError, UnsupportedFeatureError } from './core/errors.js'\nexport { clientProviderInfo } from './core/provider.js'\nexport type {\n AssetPatch,\n AssetSettings,\n CaptionTrack,\n ClientProviderInfo,\n DirectUpload,\n Downloads,\n DownloadState,\n DownloadType,\n ImportInput,\n NeutralAsset,\n PlaybackOptions,\n PlaybackResult,\n PlaybackUrls,\n ProviderCapabilities,\n ProviderEndpoint,\n ProviderRef,\n ProviderWebhook,\n ServerUploadInput,\n StoredAsset,\n UploadInput,\n UploadProtocol,\n VideoProvider,\n WebhookEvent,\n WebhookResult,\n WebhookSetup,\n} from './core/provider.js'\nexport { ProviderRegistry, validateProvider } from './core/registry.js'\nexport { isVideoStatus, VIDEO_STATUS_LABELS, VIDEO_STATUSES } from './core/status.js'\nexport type { VideoStatus } from './core/status.js'\nexport { videoOptionsFromEnv } from './env.js'\nexport type { VideoOptionsFromEnvOverrides } from './env.js'\nexport { embeddedVideoIds, videoField } from './fields.js'\nexport type { VideoFieldArgs } from './fields.js'\nexport type { VideoPlayerOptions, VideoSource } from './frontend/source.js'\nexport { blockPlayerOptions, getVideoSource, isVideoSourceExpired, videoDocId, videoIframeSrc } from './frontend/source.js'\nexport {\n CF_STREAM_LEGACY_SLUG,\n cfStreamLegacyCollection,\n cfStreamLegacyFields,\n mapCfStreamDoc,\n mapCfStreamFields,\n migrateFromCfStream,\n} from './migrate/cfStream.js'\nexport type { LegacyCfStreamDoc, MigrateFromCfStreamOptions, MigrateFromCfStreamResult } from './migrate/cfStream.js'\nexport { DEFAULT_COLLECTION_SLUG, resolveOptions } from './options.js'\nexport { videoPlugin } from './plugin.js'\nexport { assetToDocData, getVideo, matchesAllowedType, SKIP_SYNC_CONTEXT_KEY, VideoService } from './service.js'\nexport type {\n AdoptExistingResult,\n CreateUploadResult,\n ResolvedVideoOptions,\n SyncPendingResult,\n VideoAccess,\n VideoAccessArgs,\n VideoDoc,\n VideoLifecycleHook,\n VideoModerationStatus,\n VideoPlayback,\n VideoPluginOptions,\n VideoStatusChangeArgs,\n VideoUploadCheck,\n WebhookHealth,\n WebhookStatus,\n} from './types.js'\n"],"names":["anyOf","approvedOrOwner","isApprovedVideo","isVideoOwner","ownerOr","DEFAULT_VIDEO_BLOCK_SLUG","VIDEO_BLOCK_ASPECT_RATIOS","videoBlock","videoBlockReferences","isProviderError","ProviderError","UnsupportedFeatureError","clientProviderInfo","ProviderRegistry","validateProvider","isVideoStatus","VIDEO_STATUS_LABELS","VIDEO_STATUSES","videoOptionsFromEnv","embeddedVideoIds","videoField","blockPlayerOptions","getVideoSource","isVideoSourceExpired","videoDocId","videoIframeSrc","CF_STREAM_LEGACY_SLUG","cfStreamLegacyCollection","cfStreamLegacyFields","mapCfStreamDoc","mapCfStreamFields","migrateFromCfStream","DEFAULT_COLLECTION_SLUG","resolveOptions","videoPlugin","assetToDocData","getVideo","matchesAllowedType","SKIP_SYNC_CONTEXT_KEY","VideoService"],"mappings":"AAAA,SAASA,KAAK,EAAEC,eAAe,EAAEC,eAAe,EAAEC,YAAY,EAAEC,OAAO,QAAQ,cAAa;AAC5F,SAASC,wBAAwB,EAAEC,yBAAyB,EAAEC,UAAU,EAAEC,oBAAoB,QAAQ,cAAa;AAEnH,SAASC,eAAe,EAAEC,aAAa,EAAEC,uBAAuB,QAAQ,mBAAkB;AAC1F,SAASC,kBAAkB,QAAQ,qBAAoB;AA4BvD,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,qBAAoB;AACvE,SAASC,aAAa,EAAEC,mBAAmB,EAAEC,cAAc,QAAQ,mBAAkB;AAErF,SAASC,mBAAmB,QAAQ,WAAU;AAE9C,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,cAAa;AAG1D,SAASC,kBAAkB,EAAEC,cAAc,EAAEC,oBAAoB,EAAEC,UAAU,EAAEC,cAAc,QAAQ,uBAAsB;AAC3H,SACEC,qBAAqB,EACrBC,wBAAwB,EACxBC,oBAAoB,EACpBC,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,QACd,wBAAuB;AAE9B,SAASC,uBAAuB,EAAEC,cAAc,QAAQ,eAAc;AACtE,SAASC,WAAW,QAAQ,cAAa;AACzC,SAASC,cAAc,EAAEC,QAAQ,EAAEC,kBAAkB,EAAEC,qBAAqB,EAAEC,YAAY,QAAQ,eAAc"}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { ResolvedVideoOptions, VideoPluginOptions } from './types.js';
|
|
2
2
|
export declare const DEFAULT_COLLECTION_SLUG = "videos";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Validates options and fills defaults. Throws descriptive errors for misconfiguration.
|
|
5
|
+
* @param context.adminUserSlug the config's `admin.user`, the default owner and moderator collection.
|
|
6
|
+
*/
|
|
7
|
+
export declare const resolveOptions: (options: VideoPluginOptions, context?: {
|
|
8
|
+
adminUserSlug?: string;
|
|
9
|
+
}) => ResolvedVideoOptions;
|