mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat(player): let editors upload subtitles for a version
Subtitle tracks hang off a version rather than off a video, because re-editing a cut shifts every cue. The file always lands in our own S3-compatible storage whatever hosts the video, so a Bunny-hosted cut and an R2 one take the same path: both already play through our own video element, so a track element is all it takes. Uploads are normalised before they are stored. Whatever arrives, SRT or WebVTT, is parsed into cues and re-serialised as a canonical WebVTT file, and anything we did not understand is dropped rather than passed through. That is what makes it safe to serve a user-supplied text file from our own origin. Files saved out of Windows editors are decoded as windows-1254 or windows-1252 when they are not valid UTF-8, rather than refused. A YouTube version cannot carry an uploaded track, so the same CC menu drives YouTube's own captions through the iframe module API. The embed hides YouTube's controls, so until now those captions were unreachable even when the video had them. Uploading and deleting take the editor permission rather than the commenter one: a subtitle is part of the delivered cut, not a comment attachment.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
-- Subtitle tracks hang off a version, not off the video: re-editing a cut shifts
|
||||
-- every cue, so a track attached to the parent would be wrong for every version
|
||||
-- but the one it was written against.
|
||||
CREATE TABLE "video_subtitles" (
|
||||
"id" TEXT NOT NULL,
|
||||
"versionId" TEXT NOT NULL,
|
||||
"language" TEXT NOT NULL,
|
||||
"label" TEXT NOT NULL,
|
||||
"sourceUrl" TEXT NOT NULL,
|
||||
"size_bytes" BIGINT NOT NULL DEFAULT 0,
|
||||
"billedUserId" TEXT NOT NULL,
|
||||
"uploadedByUserId" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "video_subtitles_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- One stored object belongs to exactly one row, so the reference check that runs
|
||||
-- before an object delete cannot be fooled by a second row pointing at the file.
|
||||
CREATE UNIQUE INDEX "video_subtitles_sourceUrl_key" ON "video_subtitles"("sourceUrl");
|
||||
|
||||
-- Re-uploading a language replaces the track rather than stacking a second one,
|
||||
-- which would leave the player with two tracks labelled the same.
|
||||
CREATE UNIQUE INDEX "video_subtitles_versionId_language_key" ON "video_subtitles"("versionId", "language");
|
||||
|
||||
CREATE INDEX "video_subtitles_versionId_idx" ON "video_subtitles"("versionId");
|
||||
|
||||
-- The storage quota sums this column per billed user on every upload.
|
||||
CREATE INDEX "video_subtitles_billedUserId_idx" ON "video_subtitles"("billedUserId");
|
||||
|
||||
ALTER TABLE "video_subtitles" ADD CONSTRAINT "video_subtitles_versionId_fkey"
|
||||
FOREIGN KEY ("versionId") REFERENCES "video_versions"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "video_subtitles" ADD CONSTRAINT "video_subtitles_billedUserId_fkey"
|
||||
FOREIGN KEY ("billedUserId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "video_subtitles" ADD CONSTRAINT "video_subtitles_uploadedByUserId_fkey"
|
||||
FOREIGN KEY ("uploadedByUserId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -42,6 +42,8 @@ model User {
|
||||
comments Comment[]
|
||||
uploadedVideoAssets VideoAsset[] @relation("VideoAssetUploadedBy")
|
||||
billedVideoAssets VideoAsset[] @relation("VideoAssetBilledTo")
|
||||
uploadedVideoSubtitles VideoSubtitle[] @relation("VideoSubtitleUploadedBy")
|
||||
billedVideoSubtitles VideoSubtitle[] @relation("VideoSubtitleBilledTo")
|
||||
projectMemberships ProjectMember[]
|
||||
notificationSetting NotificationSetting?
|
||||
watchProgress WatchProgress[]
|
||||
@@ -383,6 +385,7 @@ model VideoVersion {
|
||||
comments Comment[]
|
||||
watchProgress WatchProgress[]
|
||||
approvalRequests ApprovalRequest[]
|
||||
subtitles VideoSubtitle[]
|
||||
|
||||
@@unique([videoParentId, versionNumber])
|
||||
@@index([videoParentId])
|
||||
@@ -418,6 +421,34 @@ model VideoAsset {
|
||||
@@map("video_assets")
|
||||
}
|
||||
|
||||
/// A subtitle track for one cut. Timings belong to a version rather than to the
|
||||
/// video: re-editing shifts every cue, so a track attached to the parent would be
|
||||
/// wrong for every version but the one it was written against.
|
||||
model VideoSubtitle {
|
||||
id String @id @default(cuid())
|
||||
versionId String
|
||||
version VideoVersion @relation(fields: [versionId], references: [id], onDelete: Cascade)
|
||||
/// BCP-47 tag, lowercased primary subtag, e.g. `tr`, `en-US`.
|
||||
language String
|
||||
label String
|
||||
/// Always an /api/upload/subtitle/<uuid>.vtt path. The file itself lives in
|
||||
/// S3-compatible storage whatever the video's own provider is, so a Bunny-hosted
|
||||
/// video and an R2-hosted one take the same path through the player.
|
||||
sourceUrl String @unique
|
||||
sizeBytes BigInt @default(0) @map("size_bytes")
|
||||
billedUserId String
|
||||
billedUser User @relation("VideoSubtitleBilledTo", fields: [billedUserId], references: [id], onDelete: Cascade)
|
||||
uploadedByUserId String?
|
||||
uploadedByUser User? @relation("VideoSubtitleUploadedBy", fields: [uploadedByUserId], references: [id], onDelete: SetNull)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([versionId, language])
|
||||
@@index([versionId])
|
||||
@@index([billedUserId])
|
||||
@@map("video_subtitles")
|
||||
}
|
||||
|
||||
model Comment {
|
||||
id String @id @default(cuid())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user