-
-
Notifications
You must be signed in to change notification settings - Fork 641
[6.x] Support more video providers, including Cloudflare Stream #11871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edalzell
wants to merge
45
commits into
statamic:6.x
Choose a base branch
from
edalzell:feature/add-cf-to-video-fieldtype
base: 6.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+506
−63
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
d6edd27
Merge branch 'ui' into feature/add-cf-to-video-fieldtype
edalzell 095fe97
Merge branch 'ui' into feature/add-cf-to-video-fieldtype
edalzell f35b6a1
video providers
edalzell e373489
move the provider/embed logic to the fieldtype
edalzell caa2ded
move the provider/embed logic to the fieldtype
edalzell 63ed860
wip
edalzell 8548d67
don’t know how to identify a CF stream id
edalzell 738f475
move it inside the input group
edalzell f1c2c6b
Merge branch 'master' into feature/add-cf-to-video-fieldtype
edalzell 0e357ef
wip
edalzell 74f8f9d
wip
edalzell 0f8fd0b
Merge branch 'master' into feature/add-cf-to-video-fieldtype
edalzell 37d64b2
some sugar
edalzell 51c3fa8
wip
edalzell 8a831e7
Discard changes to src/Fields/Fieldtype.php
edalzell 2f3c41b
Discard changes to resources/js/components/fieldtypes/Fieldtype.vue
edalzell 76e7e45
actually set the id
edalzell a769861
don’t debounce, for now
edalzell e84848c
tidy
edalzell a9aa392
fix providers
edalzell 78bbdf5
this gets rid of width/height
edalzell 87141a1
fix CF sizing
edalzell e884b3a
Not supported
edalzell 994e93b
Merge branch 'master' into pr/11871
duncanmcclean 3924b52
Merge branch 'master' into pr/11871
duncanmcclean 41056dc
null be null
edalzell 6d0ae6f
Merge branch '6.x' into feature/add-cf-to-video-fieldtype
edalzell 5548b80
fix bad merge
edalzell 18650f0
wip
edalzell b5f0be3
tidy
edalzell 2caaf6d
better display of embed
edalzell 3fcbbf7
tidy
edalzell 560c3fb
tidy
edalzell 5f5d215
tidy
edalzell 6ee9392
set/show the value properly
edalzell 6370ad2
Tests
edalzell f10c70b
Merge branch '6.x' into feature/add-cf-to-video-fieldtype
edalzell 8007863
Merge branch '6.x' into feature/add-cf-to-video-fieldtype
edalzell 1567689
Merge remote-tracking branch 'upstream/6.x' into feature/add-cf-to-vi…
edalzell 4943837
Escape Cloudflare ID in embed HTML
edalzell b3f32c6
Send the stored value to the video details endpoint
edalzell 471ebe0
Restore lazy-loading, handle failed lookups, and stop the provider wa…
edalzell 25c29dd
Remove copy-pasted Text fieldtype tests
edalzell 6845c55
Fix unsafe new static usage
edalzell 932accb
Merge branch '6.x' into feature/add-cf-to-video-fieldtype
edalzell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| .embera-embed-responsive { | ||
| position: relative; | ||
| display: block; | ||
| width: 100%; | ||
| padding: 0; | ||
| overflow: hidden; | ||
| padding-bottom: 50%; | ||
| } | ||
|
|
||
| .embera-embed-responsive-item { | ||
| position: absolute; | ||
| top: 0; | ||
| bottom: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| border: 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
resources/js/tests/components/fieldtypes/VideoFieldtype.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { flushPromises, mount } from '@vue/test-utils'; | ||
| import { afterEach, beforeEach, expect, test, vi } from 'vitest'; | ||
| import VideoFieldtype from '@/components/fieldtypes/VideoFieldtype.vue'; | ||
| import { publishContextKey } from '@/components/ui'; | ||
|
|
||
| window.__ = (key) => key; | ||
|
|
||
| let intersect; | ||
| let axios; | ||
| let toast; | ||
|
|
||
| beforeEach(() => { | ||
| window.IntersectionObserver = class { | ||
| constructor(callback) { | ||
| intersect = () => callback([{ isIntersecting: true, intersectionRatio: 1 }]); | ||
| } | ||
| observe() {} | ||
| disconnect() {} | ||
| }; | ||
|
|
||
| axios = { get: vi.fn() }; | ||
| toast = { error: vi.fn() }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| const stub = (tag) => ({ | ||
| props: ['modelValue'], | ||
| emits: ['update:modelValue'], | ||
| template: `<${tag} :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" />`, | ||
| }); | ||
|
|
||
| const mountVideoField = (props = {}) => { | ||
| return mount(VideoFieldtype, { | ||
| props: { | ||
| handle: 'video', | ||
| config: {}, | ||
| meta: { | ||
| url: '/cp/video/details', | ||
| providers: [{ provider: 'Cloudflare' }, { provider: 'Youtube' }], | ||
| }, | ||
| ...props, | ||
| }, | ||
| global: { | ||
| provide: { [publishContextKey]: {} }, | ||
| mocks: { $axios: axios, $toast: toast }, | ||
| stubs: { | ||
| 'ui-combobox': stub('select'), | ||
| 'ui-input': stub('input'), | ||
| }, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| test('cloudflare id is sent with the cloudflare prefix', async () => { | ||
| axios.get.mockResolvedValue({ data: { embed: '<iframe></iframe>', provider: 'Cloudflare' } }); | ||
|
|
||
| const wrapper = mountVideoField({ meta: { url: '/cp/video/details', providers: [], provider: 'Cloudflare' } }); | ||
|
|
||
| await wrapper.find('input').setValue('1234'); | ||
| await flushPromises(); | ||
|
|
||
| expect(axios.get).toHaveBeenCalledWith('/cp/video/details', { params: { url: 'cloudflare:1234' } }); | ||
| expect(wrapper.emitted('update:value')[0]).toEqual(['cloudflare:1234']); | ||
| }); | ||
|
|
||
| test('embed survives the provider being corrected by the lookup', async () => { | ||
| axios.get.mockResolvedValue({ data: { embed: '<iframe></iframe>', provider: 'Youtube' } }); | ||
|
|
||
| const wrapper = mountVideoField(); | ||
| intersect(); | ||
|
|
||
| await wrapper.find('input').setValue('https://www.youtube.com/watch?v=FK3dav4bA4s'); | ||
| await flushPromises(); | ||
|
|
||
| expect(wrapper.vm.provider).toBe('Youtube'); | ||
| expect(wrapper.find('input').element.value).toBe('https://www.youtube.com/watch?v=FK3dav4bA4s'); | ||
| expect(wrapper.find('iframe').exists()).toBe(true); | ||
| }); | ||
|
|
||
| test('changing the provider clears the embed and url', async () => { | ||
| const wrapper = mountVideoField({ | ||
| value: 'https://www.youtube.com/watch?v=FK3dav4bA4s', | ||
| meta: { url: '/cp/video/details', providers: [], provider: 'Youtube', embed: '<iframe></iframe>' }, | ||
| }); | ||
| intersect(); | ||
| await flushPromises(); | ||
| expect(wrapper.find('iframe').exists()).toBe(true); | ||
|
|
||
| await wrapper.find('select').setValue('Cloudflare'); | ||
|
|
||
| expect(wrapper.find('iframe').exists()).toBe(false); | ||
| expect(wrapper.vm.url).toBeNull(); | ||
| }); | ||
|
|
||
| test('embed is not rendered until the field is visible', async () => { | ||
| const wrapper = mountVideoField({ | ||
| value: 'cloudflare:1234', | ||
| meta: { url: '/cp/video/details', providers: [], provider: 'Cloudflare', embed: '<iframe></iframe>' }, | ||
| }); | ||
|
|
||
| expect(wrapper.find('iframe').exists()).toBe(false); | ||
|
|
||
| intersect(); | ||
| await flushPromises(); | ||
|
|
||
| expect(wrapper.find('iframe').exists()).toBe(true); | ||
| }); | ||
|
|
||
| test('failed lookup clears the embed and shows an error', async () => { | ||
| axios.get.mockRejectedValue({ response: { data: { message: 'Nope' } } }); | ||
|
|
||
| const wrapper = mountVideoField({ | ||
| value: 'cloudflare:1234', | ||
| meta: { url: '/cp/video/details', providers: [], provider: 'Cloudflare', embed: '<iframe></iframe>' }, | ||
| }); | ||
| intersect(); | ||
|
|
||
| await wrapper.find('input').setValue('5678'); | ||
| await flushPromises(); | ||
|
|
||
| expect(wrapper.find('iframe').exists()).toBe(false); | ||
| expect(toast.error).toHaveBeenCalledWith('Nope'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.