-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding R2 video source, chapters, & captions in preparation for…
… Cloudflare R2 testing
- Loading branch information
Showing
20 changed files
with
582 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,36 @@ | ||
import Post from '#models/post' | ||
import { postValidator } from '#validators/post' | ||
import { TransactionClientContract } from '@adonisjs/lucid/types/database' | ||
import { Infer } from '@vinejs/vine/types' | ||
|
||
type Params = { | ||
post: Post | ||
captions: Infer<typeof postValidator>['captions'] | ||
} | ||
|
||
export default class SyncCaptions { | ||
static async handle({ post, captions }: Params, trx: TransactionClientContract) { | ||
if (!captions?.length) { | ||
await post.related('captions').query().delete() | ||
return | ||
} | ||
|
||
const promises = captions.map(async (caption, index) => { | ||
if (!caption.id) { | ||
return post.related('captions').create(caption, { client: trx }) | ||
} | ||
|
||
const row = await post.related('captions').query().where('id', caption.id).firstOrFail() | ||
|
||
row.useTransaction(trx) | ||
row.merge({ | ||
sortOrder: index, | ||
...caption, | ||
}) | ||
|
||
return row.save() | ||
}) | ||
|
||
await Promise.all(promises) | ||
} | ||
} |
This file contains 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,36 @@ | ||
import Post from '#models/post' | ||
import { postValidator } from '#validators/post' | ||
import { TransactionClientContract } from '@adonisjs/lucid/types/database' | ||
import { Infer } from '@vinejs/vine/types' | ||
|
||
type Params = { | ||
post: Post | ||
chapters: Infer<typeof postValidator>['chapters'] | ||
} | ||
|
||
export default class SyncChapters { | ||
static async handle({ post, chapters }: Params, trx: TransactionClientContract) { | ||
if (!chapters?.length) { | ||
await post.related('chapters').query().delete() | ||
return | ||
} | ||
|
||
const promises = chapters.map(async (chapter, index) => { | ||
if (!chapter.id) { | ||
return post.related('chapters').create(chapter, { client: trx }) | ||
} | ||
|
||
const row = await post.related('chapters').query().where('id', chapter.id).firstOrFail() | ||
|
||
row.useTransaction(trx) | ||
row.merge({ | ||
sortOrder: index, | ||
...chapter, | ||
}) | ||
|
||
return row.save() | ||
}) | ||
|
||
await Promise.all(promises) | ||
} | ||
} |
This file contains 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 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 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,34 @@ | ||
import { BaseModelDto } from '@adocasts.com/dto/base' | ||
import PostCaption from '#models/post_caption' | ||
import CaptionTypes from '#enums/caption_types' | ||
import CaptionLanguages from '#enums/caption_languages' | ||
import PostDto from '#dtos/post' | ||
|
||
export default class PostCaptionDto extends BaseModelDto { | ||
declare id: number | ||
declare postId: number | ||
declare type: CaptionTypes | ||
declare label: string | ||
declare language: CaptionLanguages | ||
declare filename: string | ||
declare sortOrder: number | ||
declare createdAt: string | ||
declare updatedAt: string | ||
declare post: PostDto | null | ||
|
||
constructor(postCaption?: PostCaption) { | ||
super() | ||
|
||
if (!postCaption) return | ||
this.id = postCaption.id | ||
this.postId = postCaption.postId | ||
this.type = postCaption.type | ||
this.label = postCaption.label | ||
this.language = postCaption.language | ||
this.filename = postCaption.filename | ||
this.sortOrder = postCaption.sortOrder | ||
this.createdAt = postCaption.createdAt.toISO()! | ||
this.updatedAt = postCaption.updatedAt.toISO()! | ||
this.post = postCaption.post && new PostDto(postCaption.post) | ||
} | ||
} |
This file contains 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,34 @@ | ||
import { BaseModelDto } from '@adocasts.com/dto/base' | ||
import PostChapter from '#models/post_chapter' | ||
import PostDto from '#dtos/post' | ||
|
||
export default class PostChapterDto extends BaseModelDto { | ||
declare id: number | ||
declare postId: number | ||
declare start: string | ||
declare end: string | ||
declare text: string | ||
declare sortOrder: number | ||
declare createdAt: string | ||
declare updatedAt: string | ||
declare post: PostDto | null | ||
declare startSeconds: number | ||
declare endSeconds: number | ||
|
||
constructor(postChapter?: PostChapter) { | ||
super() | ||
|
||
if (!postChapter) return | ||
this.id = postChapter.id | ||
this.postId = postChapter.postId | ||
this.start = postChapter.start | ||
this.end = postChapter.end | ||
this.text = postChapter.text | ||
this.sortOrder = postChapter.sortOrder | ||
this.createdAt = postChapter.createdAt.toISO()! | ||
this.updatedAt = postChapter.updatedAt.toISO()! | ||
this.post = postChapter.post && new PostDto(postChapter.post) | ||
this.startSeconds = postChapter.startSeconds | ||
this.endSeconds = postChapter.endSeconds | ||
} | ||
} |
This file contains 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 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,17 @@ | ||
enum CaptionLanguages { | ||
ENGLISH = 'en', | ||
SPANISH = 'es', | ||
FRENCH = 'fr', | ||
GERMAN = 'de', | ||
PORTUGUESE = 'pt', | ||
} | ||
|
||
export const CaptionLanguageDesc: Record<CaptionLanguages, string> = { | ||
[CaptionLanguages.ENGLISH]: 'English', | ||
[CaptionLanguages.SPANISH]: 'Spanish', | ||
[CaptionLanguages.FRENCH]: 'French', | ||
[CaptionLanguages.GERMAN]: 'German', | ||
[CaptionLanguages.PORTUGUESE]: 'Portuguese', | ||
} | ||
|
||
export default CaptionLanguages |
This file contains 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,11 @@ | ||
enum CaptionTypes { | ||
SRT = 'srt', | ||
VTT = 'vtt', | ||
} | ||
|
||
export const CaptionTypeDesc: Record<CaptionTypes, string> = { | ||
[CaptionTypes.SRT]: 'SRT', | ||
[CaptionTypes.VTT]: 'VTT', | ||
} | ||
|
||
export default CaptionTypes |
This file contains 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.