@cliff-studio/sanity-plugin-bunny-input 1.0.1 → 1.0.3
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/dist/_chunks-es/index.js +15 -1
- package/dist/_chunks-es/index.js.map +1 -1
- package/package.json +2 -1
- package/src/api.js +270 -0
- package/src/components/BunnyInput.jsx +278 -0
- package/src/components/BunnyPreview.jsx +101 -0
- package/src/components/index.js +2 -0
- package/src/index.js +63 -0
- package/src/schema.js +110 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {definePlugin} from 'sanity'
|
|
2
|
+
import {createBunnyVideoSchema} from './schema'
|
|
3
|
+
|
|
4
|
+
export {getThumbnailUrl, getPlaybackUrl, getMp4Url} from './api'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sanity plugin for Bunny Stream video uploads
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* // sanity.config.js
|
|
12
|
+
* import { bunnyInput } from 'sanity-plugin-bunny-input'
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* plugins: [
|
|
16
|
+
* bunnyInput({
|
|
17
|
+
* libraryId: 'your-library-id',
|
|
18
|
+
* cdnHostname: 'vz-abc123-xyz.b-cdn.net', // From Bunny dashboard
|
|
19
|
+
* collectionName: 'my-project-videos', // Optional: auto-create/use collection by name
|
|
20
|
+
* // collectionId: 'existing-collection-guid', // Optional: use existing collection directly
|
|
21
|
+
* apiKey: 'your-api-key', // Or use proxyEndpoint for security
|
|
22
|
+
* })
|
|
23
|
+
* ]
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Then use in your schemas:
|
|
28
|
+
* ```js
|
|
29
|
+
* defineField({
|
|
30
|
+
* name: 'video',
|
|
31
|
+
* title: 'Video',
|
|
32
|
+
* type: 'bunnyVideo'
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const bunnyInput = definePlugin((config) => {
|
|
37
|
+
if (!config.libraryId) {
|
|
38
|
+
throw new Error('sanity-plugin-bunny-input: libraryId is required')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!config.cdnHostname) {
|
|
42
|
+
throw new Error('sanity-plugin-bunny-input: cdnHostname is required (e.g., vz-abc123-xyz.b-cdn.net)')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!config.apiKey && !config.proxyEndpoint) {
|
|
46
|
+
throw new Error('sanity-plugin-bunny-input: Either apiKey or proxyEndpoint is required')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const normalizedCollectionName =
|
|
50
|
+
typeof config.collectionName === 'string' ? config.collectionName.trim() : undefined
|
|
51
|
+
|
|
52
|
+
const pluginConfig = {
|
|
53
|
+
...config,
|
|
54
|
+
...(normalizedCollectionName ? {collectionName: normalizedCollectionName} : {}),
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
name: 'sanity-plugin-bunny-input',
|
|
59
|
+
schema: {
|
|
60
|
+
types: [createBunnyVideoSchema(pluginConfig)],
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
})
|
package/src/schema.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { defineType, defineField } from 'sanity'
|
|
2
|
+
import { BunnyInput } from './components/BunnyInput'
|
|
3
|
+
import { BunnyPreview } from './components/BunnyPreview'
|
|
4
|
+
|
|
5
|
+
export const createBunnyVideoSchema = (config) => {
|
|
6
|
+
return defineType({
|
|
7
|
+
type: 'object',
|
|
8
|
+
title: 'Bunny Video',
|
|
9
|
+
name: 'bunnyVideo',
|
|
10
|
+
fields: [
|
|
11
|
+
defineField({
|
|
12
|
+
type: 'string',
|
|
13
|
+
title: 'Video ID',
|
|
14
|
+
name: 'videoId',
|
|
15
|
+
readOnly: true,
|
|
16
|
+
}),
|
|
17
|
+
defineField({
|
|
18
|
+
type: 'string',
|
|
19
|
+
title: 'Library ID',
|
|
20
|
+
name: 'libraryId',
|
|
21
|
+
readOnly: true,
|
|
22
|
+
}),
|
|
23
|
+
defineField({
|
|
24
|
+
type: 'string',
|
|
25
|
+
title: 'Collection ID',
|
|
26
|
+
name: 'collectionId',
|
|
27
|
+
readOnly: true,
|
|
28
|
+
}),
|
|
29
|
+
defineField({
|
|
30
|
+
type: 'string',
|
|
31
|
+
title: 'Collection name',
|
|
32
|
+
name: 'collectionName',
|
|
33
|
+
readOnly: true,
|
|
34
|
+
}),
|
|
35
|
+
defineField({
|
|
36
|
+
type: 'string',
|
|
37
|
+
title: 'Title',
|
|
38
|
+
name: 'title',
|
|
39
|
+
}),
|
|
40
|
+
defineField({
|
|
41
|
+
type: 'string',
|
|
42
|
+
title: 'Status',
|
|
43
|
+
name: 'status',
|
|
44
|
+
options: {
|
|
45
|
+
list: [
|
|
46
|
+
{title: 'Uploading', value: 'uploading'},
|
|
47
|
+
{title: 'Processing', value: 'processing'},
|
|
48
|
+
{title: 'Ready', value: 'ready'},
|
|
49
|
+
{title: 'Error', value: 'error'},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
readOnly: true,
|
|
53
|
+
}),
|
|
54
|
+
defineField({
|
|
55
|
+
type: 'number',
|
|
56
|
+
title: 'Video width',
|
|
57
|
+
name: 'videoWidth',
|
|
58
|
+
readOnly: true,
|
|
59
|
+
}),
|
|
60
|
+
defineField({
|
|
61
|
+
type: 'number',
|
|
62
|
+
title: 'Video height',
|
|
63
|
+
name: 'videoHeight',
|
|
64
|
+
readOnly: true,
|
|
65
|
+
}),
|
|
66
|
+
defineField({
|
|
67
|
+
type: 'string',
|
|
68
|
+
title: 'Thumbnail URL',
|
|
69
|
+
name: 'thumbnailUrl',
|
|
70
|
+
readOnly: true,
|
|
71
|
+
}),
|
|
72
|
+
defineField({
|
|
73
|
+
type: 'string',
|
|
74
|
+
title: 'Playback URL',
|
|
75
|
+
name: 'playbackUrl',
|
|
76
|
+
readOnly: true,
|
|
77
|
+
}),
|
|
78
|
+
defineField({
|
|
79
|
+
type: 'string',
|
|
80
|
+
title: 'MP4 URL',
|
|
81
|
+
name: 'mp4Url',
|
|
82
|
+
readOnly: true,
|
|
83
|
+
}),
|
|
84
|
+
defineField({
|
|
85
|
+
type: 'number',
|
|
86
|
+
title: 'Duration (seconds)',
|
|
87
|
+
name: 'duration',
|
|
88
|
+
readOnly: true,
|
|
89
|
+
}),
|
|
90
|
+
defineField({
|
|
91
|
+
type: 'string',
|
|
92
|
+
title: 'Error Message',
|
|
93
|
+
name: 'errorMessage',
|
|
94
|
+
readOnly: true,
|
|
95
|
+
hidden: true,
|
|
96
|
+
}),
|
|
97
|
+
],
|
|
98
|
+
components: {
|
|
99
|
+
input: (props) => BunnyInput({...props, config}),
|
|
100
|
+
preview: BunnyPreview,
|
|
101
|
+
},
|
|
102
|
+
preview: {
|
|
103
|
+
select: {
|
|
104
|
+
title: 'title',
|
|
105
|
+
status: 'status',
|
|
106
|
+
thumbnailUrl: 'thumbnailUrl',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
}
|