docbrown/app/controllers/videos_controller.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

28 lines
993 B
Ruby

class VideosController < ApplicationController
after_action :verify_authorized
def new
authorize :video
end
def create
authorize :video
@article = Article.new(body_markdown: "---\ntitle: Unpublished Video ~ #{rand(100000).to_s(26)}\npublished: false\ndescription: \ntags: \n---\n\n", processed_html: "")
@article.user_id = current_user.id
@article.show_comments = true
assign_video_attributes
@article.save!
render action: "js_response"
end
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"
end
end
end