Skip to content

Commit a413df4

Browse files
committed
feat: Upload captions
1 parent 9312bf7 commit a413df4

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed

apps/cf/lib/actions/action_creator.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule CF.Actions.ActionCreator do
1010
alias DB.Schema.Speaker
1111
alias DB.Schema.Statement
1212
alias DB.Schema.Comment
13+
alias DB.Schema.VideoCaption
1314
alias CF.Actions.ReputationChange
1415

1516
# Create
@@ -175,6 +176,19 @@ defmodule CF.Actions.ActionCreator do
175176
)
176177
end
177178

179+
def action_upload_video_captions(user_id, video_id, caption = %VideoCaption{}) do
180+
action(
181+
user_id,
182+
:video_caption,
183+
:upload,
184+
video_id: video_id,
185+
changes: %{
186+
"format" => caption.format,
187+
"parsed" => caption.parsed
188+
}
189+
)
190+
end
191+
178192
def action_revert_vote(user_id, video_id, vote_type, comment = %Comment{})
179193
when vote_type in [:revert_vote_up, :revert_vote_down, :revert_self_vote] do
180194
action(

apps/cf_graphql/lib/resolvers/videos.ex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ defmodule CF.Graphql.Resolvers.Videos do
115115
{:ok, video}
116116
end
117117

118+
118119
def edit(_root, %{id: id, unlisted: unlisted}, %{
119120
context: %{user: user}
120121
}) do
@@ -136,5 +137,32 @@ defmodule CF.Graphql.Resolvers.Videos do
136137
{:error, _} ->
137138
{:error, "Failed to update video"}
138139
end
140+
141+
def set_captions(_root, %{video_id: video_id, captions: captions_input}, %{
142+
context: %{user: user}
143+
}) do
144+
video = DB.Repo.get!(DB.Schema.Video, video_id)
145+
146+
Multi.new()
147+
|> Multi.insert(
148+
:caption,
149+
VideoCaption.changeset(%VideoCaption{
150+
video_id: video.id,
151+
raw: captions_input,
152+
parsed: captions_input,
153+
format: "user-provided"
154+
})
155+
)
156+
|> Multi.run(
157+
:action,
158+
fn _repo, %{caption: caption} ->
159+
CF.Actions.ActionCreator.action_upload_video_captions(user.id, video.id, caption)
160+
|> DB.Repo.insert!()
161+
162+
{:ok, caption}
163+
end
164+
)
165+
166+
{:ok, video}
139167
end
140168
end

apps/cf_graphql/lib/schema/input_objects.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule CF.Graphql.Schema.InputObjects do
33

44
import_types(CF.Graphql.Schema.InputObjects.{
55
VideoFilter,
6-
StatementFilter
6+
StatementFilter,
7+
VideoCaption
78
})
89
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule CF.Graphql.Schema.InputObjects.VideoCaption do
2+
use Absinthe.Schema.Notation
3+
use Absinthe.Ecto, repo: DB.Repo
4+
5+
input_object :video_caption_input do
6+
field(:text, non_null(:string))
7+
field(:start, non_null(:float))
8+
field(:duration, :float)
9+
end
10+
end

apps/cf_graphql/lib/schema/schema.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ defmodule CF.Graphql.Schema do
109109
arg(:unlisted, non_null(:boolean))
110110

111111
resolve(&Resolvers.Videos.edit/3)
112-
end
112+
end
113+
114+
field :set_video_captions, :video do
115+
middleware(Middleware.RequireAuthentication)
116+
middleware(Middleware.RequireReputation, 450)
117+
118+
arg(:video_id, non_null(:id))
119+
arg(:captions, non_null(list_of(:video_caption_input)))
120+
121+
resolve(&Resolvers.Videos.set_captions/3)
122+
113123
end
114124
end

apps/cf_jobs/config/config.exs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ config :cf_jobs, CF.Jobs.Scheduler,
3838
schedule: {:extended, "*/5"},
3939
task: {CF.Jobs.CreateNotifications, :update, []},
4040
overlap: false
41-
]
4241
# Captions
4342
# download_captions: [
44-
# # every minute
45-
# schedule: "*/1 * * * *",
43+
# schedule: "@daily",
4644
# task: {CF.Jobs.DownloadCaptions, :update, []},
4745
# overlap: false
4846
# ]

0 commit comments

Comments
 (0)