Add video state column and change endpoint (#286)
This commit is contained in:
parent
7c59c3aaf4
commit
0b6d850ac1
13 changed files with 79 additions and 4 deletions
|
|
@ -189,6 +189,7 @@ class ArticlesController < ApplicationController
|
|||
def assign_video_attributes
|
||||
if params[:article][:video]
|
||||
@article.video = params[:article][:video]
|
||||
@article.video_state = "PROGRESSING"
|
||||
@article.video_code = @article.video.split("dev-to-input-v0/")[1]
|
||||
@article.video_source_url = "https://dw71fyauz7yz9.cloudfront.net/#{@article.video_code}/#{@article.video_code}.m3u8"
|
||||
@article.video_thumbnail_url = "https://dw71fyauz7yz9.cloudfront.net/#{@article.video_code}/thumbs-#{@article.video_code}-00001.png"
|
||||
|
|
|
|||
20
app/controllers/video_states_controller.rb
Normal file
20
app/controllers/video_states_controller.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
class VideoStatesController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token
|
||||
def create
|
||||
unless valid_user
|
||||
render json: { message: "invalid_user" }, :status => 422
|
||||
return
|
||||
end
|
||||
@article = Article.find_by_video_code(params[:input][:key])
|
||||
@article.update(video_state: "COMPLETED") #Only is called on completion
|
||||
NotifyMailer.video_upload_complete_email(@article).deliver
|
||||
render json: { message: "Video state updated" }
|
||||
end
|
||||
|
||||
def valid_user
|
||||
user = User.find_by_secret(params[:key])
|
||||
user = nil if !user.has_role?(:super_admin)
|
||||
user
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -35,4 +35,10 @@ class NotifyMailer < ApplicationMailer
|
|||
subject = "🔥 You have #{@unread_notifications_count} unread notifications on dev.to"
|
||||
mail(to: @user.email, subject: subject)
|
||||
end
|
||||
|
||||
def video_upload_complete_email(article)
|
||||
@article = article
|
||||
@user = @article.user
|
||||
mail(to: @user.email, subject: "Your video upload is complete")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ class Article < ApplicationRecord
|
|||
# validates :description, length: { in: 10..170, if: :published? }
|
||||
validates :body_markdown, uniqueness: { scope: :user_id }
|
||||
validate :validate_tag
|
||||
validates :video_state, inclusion: { in: %w(PROGRESSING COMPLETED) }, allow_nil: true
|
||||
|
||||
before_validation :evaluate_markdown
|
||||
before_validation :create_slug
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
playerInstance.setup({
|
||||
file: "<%= article.video_source_url %>",
|
||||
mediaid: "<%= article.video_code %>",
|
||||
image: "<%= cloudinary(article.video_thumbnail_url + "bust=" + article.updated_at.to_i.to_s, 880) %>",
|
||||
image: "<%= cloudinary(article.video_thumbnail_url, 880) %>",
|
||||
playbackRateControls: true,
|
||||
tracks: [{
|
||||
file: "<%= article.video_closed_caption_track_url %>",
|
||||
|
|
|
|||
|
|
@ -13,11 +13,15 @@
|
|||
<% if @user.has_role?(:super_admin) %>
|
||||
<center>
|
||||
<%= stylesheet_link_tag 's3_direct_upload', media: 'all' %>
|
||||
<% if @article.video %>
|
||||
<% if @article.video_state == "PROGRESSING" %>
|
||||
<h2>Video Transcoding In Progress</h2>
|
||||
<img src="https://media.giphy.com/media/xf20D8HzvTQzu/giphy.gif" />
|
||||
<br/><br/><br/><br/>
|
||||
<% elsif @article.video_state == "COMPLETED" %>
|
||||
<h2>Video uploaded - <%= @article.video_code %></h2>
|
||||
<%= render "articles/video_player", meta_tags: false, article: @article %>
|
||||
<h2>Thumbnail:</h2>
|
||||
<img width="300" src="<%= cloudinary(@article.video_thumbnail_url, 880) %>" />
|
||||
<img style="max-width:100%" src="<%= cloudinary(@article.video_thumbnail_url, 880) %>" />
|
||||
<h2>Change thumbnail:</h2>
|
||||
<%= form_for(@article) do |f| %>
|
||||
<%= f.text_field :video_thumbnail_url, placeholder: "New Thumbnail URL" %>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<p>
|
||||
Hey <%= @user.name %>, your video is finished processing.
|
||||
</p>
|
||||
|
||||
<h2>
|
||||
🎥 <a href="https://dev.to<%= @article.path %>/edit">Finalize and publish your video</a> 😊
|
||||
</h2>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Your video is finished being processed. Check it out here:
|
||||
|
||||
https://dev.to<%= @article.path %>/edit
|
||||
|
|
@ -93,6 +93,7 @@ Rails.application.routes.draw do
|
|||
resources :buffered_articles, only: [:index]
|
||||
resources :events, only: [:index, :show]
|
||||
resources :additional_content_boxes, only: [:index]
|
||||
resources :video_states, only: [:create]
|
||||
get "/notifications/:username" => "notifications#index"
|
||||
patch "/onboarding_update" => "users#onboarding_update"
|
||||
get "email_subscriptions/unsubscribe"
|
||||
|
|
|
|||
5
db/migrate/20180507191509_add_video_state_to_articles.rb
Normal file
5
db/migrate/20180507191509_add_video_state_to_articles.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddVideoStateToArticles < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_column :articles, :video_state, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20180502174301) do
|
||||
ActiveRecord::Schema.define(version: 20180507191509) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
|
@ -107,6 +107,7 @@ ActiveRecord::Schema.define(version: 20180502174301) do
|
|||
t.string "video_closed_caption_track_url"
|
||||
t.string "video_code"
|
||||
t.string "video_source_url"
|
||||
t.string "video_state"
|
||||
t.string "video_thumbnail_url"
|
||||
t.index ["boost_states"], name: "index_articles_on_boost_states", using: :gin
|
||||
t.index ["featured_number"], name: "index_articles_on_featured_number"
|
||||
|
|
|
|||
|
|
@ -15,4 +15,8 @@ class NotifyMailerPreview < ActionMailer::Preview
|
|||
def new_mention_email
|
||||
NotifyMailer.new_mention_email(Mention.last)
|
||||
end
|
||||
|
||||
def video_upload_complete_email
|
||||
NotifyMailer.video_upload_complete_email(Article.last)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
22
spec/requests/video_states_update_spec.rb
Normal file
22
spec/requests/video_states_update_spec.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# http://localhost:3000/api/comments?a_id=23
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "VideoStatesUpdate", type: :request do
|
||||
before do
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.update(secret:"TEST_SECRET")
|
||||
@user.add_role(:super_admin)
|
||||
@article = FactoryBot.create(:article, video_code: "DUMMY_VID_CODE")
|
||||
end
|
||||
describe "POST /video_states" do
|
||||
it "updates video state" do
|
||||
post "/video_states?key=#{@user.secret}", params: {input: {key: Article.last.video_code}}
|
||||
expect(Article.last.video_state).to eq("COMPLETED")
|
||||
end
|
||||
it "rejects non-authorized users" do
|
||||
@user.remove_role(:super_admin)
|
||||
post "/video_states?key=#{@user.secret}", params: {input: {key: Article.last.video_code}}
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue