* Rubocop enabled style/alias * Enabled Style/ArrayJoin Cop * Enabled Style/Attr * Enabled Case Equality * Enabled CharacterLiteral * Enabled ColonMethodCall Cop * Enabled CommentAnnotation cop * Enabled PreferredHashMethods Cop * Enabled DoubleNegation Cop * Enabled EachWithObject Cop * Enabled EmptyLiteral Cop * Enabled EvenOdd Cop * Enabled IfWithSemicolon Cop * Enabled Lambda and LambdaCall Cop * Enabled LineEndConcatenation Cop * Enabled ModuleFunction Cop; * Enable NegatedIf and NegatedWhile Cop * Enabled NilComparison Cop * Enabled Not Cop * Enabled NumericLiterals Cop * Enabled OneLineConditional Cop * Enabled PercentLiteralDelimiters Cop * Excluded internal/users_controller from negated_if cop * Reverted the double negation change from github_issue_tag and github_issue.rb" * Enabled PerlBackrefs Cop * Changed Regexp.last_match(1) to Regexp.last_match(0) * Enabled proc cop * Enabled RaiseArgs Cop * Reverted Regexp.last_match(0) to Regexp.last_match(1) * Enabled SelfAssignment Cop * Enabled SingleLineMethods Cop * Enabled SpecialGlobalVars Cop * Enabled VariableInterpolation Cop * Enabled WhenThen Cop * Enabled WhileUntilModifier Cop * Enabled WordArray Cop * Enabled IfUnlessModifier Cop * Enabled GuardClause Cop
42 lines
1.2 KiB
Ruby
42 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# rubocop:disable Layout/TrailingWhitespace
|
|
class ArticleWithVideoCreationService
|
|
VIDEO_SERVICE_URL = "https://dw71fyauz7yz9.cloudfront.net"
|
|
|
|
def initialize(article_params, current_user)
|
|
@article_params = article_params
|
|
@current_user = current_user
|
|
end
|
|
|
|
def create!
|
|
Article.create! do |article|
|
|
article.body_markdown = <<~BODY
|
|
---
|
|
title: Unpublished Video ~ #{rand(100_000).to_s(26)}
|
|
published: false
|
|
description:
|
|
tags:
|
|
---
|
|
|
|
BODY
|
|
|
|
article.processed_html = ""
|
|
article.user_id = @current_user.id
|
|
article.show_comments = true
|
|
|
|
if @article_params[:video].present?
|
|
article.video = @article_params[:video]
|
|
article.video_state = "PROGRESSING"
|
|
|
|
video_code = article.video.split("dev-to-input-v0/")[1]
|
|
article.video_code = video_code
|
|
article.video_source_url = "#{VIDEO_SERVICE_URL}/#{video_code}/#{video_code}.m3u8"
|
|
|
|
thumb_name = "thumbs-#{video_code}-00001"
|
|
article.video_thumbnail_url = "#{VIDEO_SERVICE_URL}/#{video_code}/#{thumb_name}.png"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
# rubocop:enable Layout/TrailingWhitespace
|