diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 5027ba88e..994163e3d 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -93,7 +93,6 @@ class ArticlesController < ApplicationController if @article.update(article_params.merge(edited_at: edited_at_date)) handle_org_assignment handle_hiring_tag - assign_video_attributes if @article.published Notification.send_all(@article, "Published") if @article.previous_changes.include?("published") path = @article.path @@ -101,10 +100,6 @@ class ArticlesController < ApplicationController Notification.remove_all(@article, "Published") path = "/#{@article.username}/#{@article.slug}?preview=#{@article.password}" end - if params[:article][:video] - render action: "video_upload" - return - end redirect_to (params[:destination] || path) else render :edit @@ -186,18 +181,6 @@ class ArticlesController < ApplicationController :video, :video_code, :video_source_url, :video_thumbnail_url) 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" - @article.save - - end - end - def job_opportunity_params return nil unless params[:article][:job_opportunity].present? params[:article].require(:job_opportunity).permit( diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb new file mode 100644 index 000000000..622ccccc5 --- /dev/null +++ b/app/controllers/videos_controller.rb @@ -0,0 +1,32 @@ +class VideosController < ApplicationController + before_action :check_video_permission + + def new + end + + def create + @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] && current_user.has_role?(:video_permission) + @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 + + private + + def check_video_permission + redirect_to "/enter" unless current_user&.has_role?(:video_permission) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e6672f9b8..99d29070f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,6 +22,7 @@ module ApplicationHelper controller_name == "pages" || controller_name == "dashboards"|| controller_name == "moderations"|| + controller_name == "videos"|| controller_name == "stories" || controller_name == "comments" || controller_name == "notifications" || diff --git a/app/models/article.rb b/app/models/article.rb index 3cb5ac44f..602790a17 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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 + validate :validate_video validates :video_state, inclusion: { in: %w(PROGRESSING COMPLETED) }, allow_nil: true before_validation :evaluate_markdown @@ -380,6 +381,12 @@ class Article < ApplicationRecord end end + def validate_video + if published && video_state == "PROGRESSING" + return errors.add(:published, "cannot be set to true if video is still processing") + end + end + def create_slug if slug.blank? && title.present? && !published self.slug = title_to_slug + "-temp-slug-#{rand(10_000_000)}" diff --git a/app/models/role.rb b/app/models/role.rb index ab7e4e1ec..d33286eae 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -25,6 +25,7 @@ class Role < ApplicationRecord level_2_member level_1_member workshop_pass + video_permission ), } scopify diff --git a/app/views/articles/edit.html.erb b/app/views/articles/edit.html.erb index d20d64426..2d14e13e3 100644 --- a/app/views/articles/edit.html.erb +++ b/app/views/articles/edit.html.erb @@ -1,64 +1,37 @@ <% title "Edit Article - DEV" %> - <% if params[:beta_form] %> - <%= render 'react_form' %> - <% else %> - <% if @article.body_html && @article.body_html.size > 10 %> - <%= render 'inline_form' %> - <% else %> - <%= render 'articles/markdown_form' %> - <% end %> - <% end %> - -<% if @user.has_role?(:super_admin) %> -
-
+ + You'll get an email when it's finished. Contact ben@dev.to if the email never comes, or if anything else is broken. 😱 +
++ This is an unpublished article with a video. Publish it as usual when the video is done processing. +
++ Video is beta. Max 500mb, email ben@dev.to if you have any problems. +
+