Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit f79218d

Browse files
committed
adding support for bunny stream videos.
1 parent eb4ad3e commit f79218d

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

app/Models/Post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class Post extends AppBaseModel {
7575
public videoUrl: string | null
7676

7777
@column()
78-
public videoBunnyPath: string | null
78+
public videoBunnyId: string | null
7979

8080
@column()
8181
public livestreamUrl: string | null

app/Services/PostService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class PostService {
9999

100100
public async populateVideoProperties(post: Partial<Post>) {
101101
if (!post.videoTypeId || post.videoTypeId === VideoTypes.YOUTUBE) return
102-
if (!post.videoBunnyPath) return
102+
if (!post.videoBunnyId) return
103103

104104
// TODO: get video's duration from bunny stream api
105105
}

app/Validators/PostStoreValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class PostStoreValidator extends BaseValidator {
3232
livestreamUrl: schema.string.optional({ trim: true }, [rules.maxLength(255), rules.url()]),
3333
videoTypeId: schema.number.optional(),
3434
videoUrl: schema.string.optional({ trim: true }, [rules.maxLength(255), rules.url()]),
35-
videoBunnyPath: schema.string.optional({ trim: true }, [rules.maxLength(500)]),
35+
videoBunnyId: schema.string.optional({ trim: true }, [rules.maxLength(500)]),
3636
videoSeconds: schema.number.optional(),
3737
timezone: schema.string.optional({ trim: true }),
3838
publishAtDate: schema.date.optional({ format: 'yyyy-MM-dd' }),

resources/views/components/form/input/alt.edge

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
{{ readonly && 'readonly' }}
4949
oninput="{{ onInput ?? undefined }}"
5050
@focus="focused = true"
51-
@blur="focused = false"
51+
@blur="focused = false; $dispatch('updated', $el.value)"
5252
></textarea>
5353
@elseif(type === 'group')
5454
@if($slots.input)
@@ -73,7 +73,7 @@
7373
{{ readonly && 'readonly disabled' }}
7474
{{{ attrs }}}
7575
@focus="focused = true"
76-
@blur="focused = false">
76+
@blur="focused = false; $dispatch('updated', $el.value)">
7777
{{{ await $slots.main() }}}
7878
</select>
7979
@else
@@ -101,7 +101,7 @@
101101
{{ readonly && 'readonly' }}
102102
oninput="{{ onInput ?? undefined }}"
103103
@focus="focused = true"
104-
@blur="focused = false">
104+
@blur="focused = false; $dispatch('updated', $el.value)">
105105
@endif
106106

107107
@if(error && type !== 'group' && type !== 'password')

resources/views/studio/posts/createOrEdit.edge

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,44 @@
218218
<option value="{{ VideoTypes.BUNNY }}">Bunny Stream</option>
219219
@end
220220

221-
<div x-show="videoTypeId == {{ VideoTypes.BUNNY }}">
222-
@!form.input.alt({
223-
label: 'Video Path',
224-
name: 'videoBunnyPath',
225-
help: "Enter video path on Bunny Stream Storage",
226-
placeholder: 'Enter videos path or url',
227-
value: flashMessages.get('videoBunnyPath') ?? post?.videoBunnyPath ?? '',
228-
errors: flashMessages.get('errors.videoBunnyPath'),
221+
<div x-show="videoTypeId == {{ VideoTypes.BUNNY }}" x-data="{
222+
showEmbed: {{ !!post?.videoBunnyId }},
223+
videoId: '{{ post?.videoBunnyId }}',
224+
onBlur({ detail }) {
225+
this.videoId = detail
226+
this.showEmbed = !!detail
227+
},
228+
syncDuration(el) {
229+
console.log({ el, duration: el.duration })
230+
document.forms[0].videoSeconds.value = Math.round(el.duration)
231+
}
232+
}" @updated="onBlur">
233+
@form.input.alt({
234+
label: 'Bunny Video Id',
235+
name: 'videoBunnyId',
236+
help: "Enter the Bunny Stream Video Id",
237+
placeholder: 'Enter video id',
238+
value: flashMessages.get('videoBunnyId') ?? post?.videoBunnyId ?? '',
239+
errors: flashMessages.get('errors.videoBunnyId'),
229240
max: 500
230241
})
242+
@slot('after')
243+
<div id="bunnyPreview" class="aspect-w-16 aspect-h-9 rounded overflow-hidden bg-gray-100 shadow-inner mt-6">
244+
<div x-show="!showEmbed">
245+
<div class="text-gray-700 flex flex-col h-full w-full items-center justify-center">
246+
<svg class="w-12 h-12" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
247+
<h4 class="font-semibold">No Video</h4>
248+
<p class="text-xs">Enter a valid video id to add a video to this post</p>
249+
</div>
250+
</div>
251+
<template x-if="showEmbed">
252+
<video controls @loadedmetadata="syncDuration($el)">
253+
<source :src="`https://videos.adocasts.com/${videoId}/play_360p.mp4`" size="360" type="video/mp4" />
254+
</video>
255+
</template>
256+
</div>
257+
@endslot
258+
@end
231259
</div>
232260

233261
<div x-show="videoTypeId == {{ VideoTypes.YOUTUBE }}">
@@ -255,7 +283,9 @@
255283
</div>
256284
@endslot
257285
@end
286+
</div>
258287

288+
<div x-show="videoTypeId">
259289
@!form.input.alt({
260290
label: 'Video Length (in seconds)',
261291
name: 'videoSeconds',

0 commit comments

Comments
 (0)