Compare commits
2 Commits
match-impo
...
prevent-su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d160bb320 | ||
|
|
a7b90c223b |
@@ -8,11 +8,16 @@ $(document).on "turbolinks:load", ->
|
||||
# Called when the subscription has been terminated by the server
|
||||
|
||||
received: (data) ->
|
||||
return unless document.querySelector("meta[name=broadcast-token][content='#{broadcastToken}']")
|
||||
switch data.event
|
||||
when "broadcast_stream_update" then @refreshBroadcastVideo(data)
|
||||
when "stream_recording_ready" then @showBroadcastRecordings(data)
|
||||
when "file_upload_update" then @refreshBroadcastFilesTab(data)
|
||||
when "broadcast_stream_update"
|
||||
return unless document.querySelector("meta[name=broadcast-token][current=true][content='#{broadcastToken}']")
|
||||
@refreshBroadcastVideo(data)
|
||||
when "stream_recording_ready"
|
||||
return unless document.querySelector("meta[name=broadcast-token][current=true][content='#{broadcastToken}']")
|
||||
@showBroadcastRecordings(data)
|
||||
when "file_upload_update"
|
||||
return unless document.querySelector("meta[name=broadcast-token][content='#{broadcastToken}']")
|
||||
@refreshBroadcastFilesTab(data)
|
||||
|
||||
refreshBroadcastVideo: (data) ->
|
||||
$("#broadcast_updates").html data.status_content
|
||||
|
||||
@@ -3,15 +3,25 @@
|
||||
class Api::DirectUploadsController < Api::ApiController
|
||||
include ActiveStorage::SetCurrent
|
||||
|
||||
deserializable_resource :direct_upload, only: [:create]
|
||||
|
||||
def create
|
||||
blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args)
|
||||
blob = ActiveStorage::Blob.create_before_direct_upload!(blob_params)
|
||||
render jsonapi: DirectUpload.new(blob)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def blob_args
|
||||
params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, :metadata).to_h.symbolize_keys
|
||||
def blob_params
|
||||
params.
|
||||
require(:direct_upload).
|
||||
permit(:type, :filename, :byte_size, :checksum, :content_type, :metadata).
|
||||
except(:type).
|
||||
to_h.symbolize_keys
|
||||
end
|
||||
|
||||
class DeserializableDirectUpload < JSONAPI::Deserializable::Resource
|
||||
attributes :filename, :byte_size, :checksum, :content_type, :metadata
|
||||
end
|
||||
|
||||
class SerializableDirectUpload < JSONAPI::Serializable::Resource
|
||||
|
||||
@@ -23,7 +23,7 @@ class HeadshotCollection
|
||||
collection_uid: collection_uid.to_s,
|
||||
bucket_name: aws_bucket_name,
|
||||
ids_to_images: map_ids_to_images,
|
||||
}.reject { |_, v| v.blank? }
|
||||
}.reject { |k, v| v.blank? && k != :ids_to_images }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= bootstrap_form_for model, layout: :inline, remote: true do |form| %>
|
||||
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, wrapper_class: "w-65 mr-2", id: "broadcast_files_#{token}" %>
|
||||
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, required: true, wrapper_class: "w-65 mr-2", id: "broadcast_files_#{token}" %>
|
||||
<%= form.button fa_icon("upload", text: "Add File"), class: "btn btn-primary", type: :submit, data: { disable_with: fa_icon("spinner", text: "Adding File") } %>
|
||||
<% end %>
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
<meta name="project-id" content="<%= @project.id %>">
|
||||
<% end %>
|
||||
<% if @broadcast %>
|
||||
<meta name="broadcast-token" content="<%= @broadcast.token %>">
|
||||
<meta name="broadcast-token" current="true" content="<%= @broadcast.token %>">
|
||||
<% end %>
|
||||
<% # Subscribe to Action Cable for every broadcast including those in multi-view %>
|
||||
<% @multi_view_broadcasts.each do |multi_view_broadcast| %>
|
||||
<% if multi_view_broadcast.token != @broadcast.token %>
|
||||
<meta name="broadcast-token" content="<%= multi_view_broadcast.token %>">
|
||||
<meta name="broadcast-token" current="false" content="<%= multi_view_broadcast.token %>">
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= bootstrap_form_for model, url: broadcast_url(token: token), layout: :inline, remote: true do |form| %>
|
||||
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, wrapper_class: "w-65 mr-2", id: "broadcast_files_#{token}" %>
|
||||
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, required: true, wrapper_class: "w-65 mr-2", id: "broadcast_files_#{token}" %>
|
||||
<%= form.button fa_icon("upload", text: "Add File"), class: "btn btn-primary", type: :submit, data: { disable_with: fa_icon("spinner", text: "Adding File") } %>
|
||||
<% end %>
|
||||
@@ -10,7 +10,7 @@ RSpec.describe Api::DirectUploadsController, type: :controller do
|
||||
|
||||
describe '#create' do
|
||||
it 'returns data for a direct upload' do
|
||||
post :create, params: { blob: blob_params }
|
||||
post :create, params: { direct_upload: direct_upload_params }
|
||||
|
||||
expect(response).to be_successful
|
||||
expect(response_body_data_attributes).to include('id', 'key', 'signed_id', 'url', 'headers')
|
||||
@@ -19,7 +19,7 @@ RSpec.describe Api::DirectUploadsController, type: :controller do
|
||||
|
||||
private
|
||||
|
||||
def blob_params
|
||||
def direct_upload_params
|
||||
file = file_fixture("video_file.mp4")
|
||||
checksum = Digest::MD5.base64digest(StringIO.new(file.read).to_s)
|
||||
|
||||
|
||||
@@ -40,12 +40,12 @@ feature "User managing broadcasts" do
|
||||
scenario "visit show page of broadcast", js: true do
|
||||
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
|
||||
recording = create(:broadcast_recording, broadcast: broadcast)
|
||||
|
||||
|
||||
visit project_broadcast_path(project, broadcast)
|
||||
|
||||
expect(page).to have_content("Live stream is waiting to begin.")
|
||||
expect(page).to have_content("Copy URL")
|
||||
|
||||
|
||||
within "#files" do
|
||||
expect(page).to have_content("contract.pdf")
|
||||
end
|
||||
@@ -54,6 +54,17 @@ feature "User managing broadcasts" do
|
||||
expect(page).to have_content(recording.download_file_name)
|
||||
end
|
||||
|
||||
scenario "form will not submit if user clicks Add files without selected files", js: true do
|
||||
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
|
||||
|
||||
visit project_broadcast_path(project, broadcast)
|
||||
|
||||
expect(page).to have_content("Live stream is waiting to begin.")
|
||||
expect(page).to have_content add_file_button
|
||||
|
||||
click_on add_file_button
|
||||
end
|
||||
|
||||
scenario "visit multi-view broadcast page", js: true do
|
||||
broadcast_one = create(:broadcast, :with_stream, :with_files, name: "Broadcast 1", project: project)
|
||||
broadcast_two = create(:broadcast, :with_stream, :with_files, name: "Broadcast 2", project: project)
|
||||
@@ -80,8 +91,13 @@ feature "User managing broadcasts" do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def add_file_button
|
||||
'Add File'
|
||||
end
|
||||
|
||||
def broadcast_name_field
|
||||
"broadcast[name]"
|
||||
end
|
||||
|
||||
@@ -97,6 +97,18 @@ describe HeadshotCollection do
|
||||
expect(hash.keys).not_to include(:collection_uid)
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are no releasables" do
|
||||
it "includes a blank hash value for the ids_to_images key" do
|
||||
releases = []
|
||||
collection = HeadshotCollection.new(nil, releases)
|
||||
|
||||
hash = collection.to_hash
|
||||
|
||||
expect(hash.keys).to include(:ids_to_images)
|
||||
expect(hash[:ids_to_images]).to eq(Hash.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user