You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
869 B
41 lines
869 B
6 years ago
|
class Videos::CreateAuthService < ApplicationService
|
||
|
Error = Class.new(StandardError)
|
||
|
|
||
|
attr_reader :user, :params
|
||
|
|
||
|
def initialize(user, params)
|
||
|
@user = user
|
||
|
@params = params.clone
|
||
|
end
|
||
|
|
||
|
def call
|
||
|
validate!
|
||
|
|
||
|
result = upload_video_result
|
||
|
|
||
|
Video.create!(user: user, uuid: result['VideoId'], title: title, cover_url: params[:cover_url])
|
||
|
|
||
|
result
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def title
|
||
|
@_title ||= params.delete(:title).to_s.strip
|
||
|
end
|
||
|
|
||
|
def filename
|
||
|
@_filename ||= params.delete(:file_name).to_s.strip
|
||
|
end
|
||
|
|
||
|
def validate!
|
||
|
raise Error, '视频标题不能为空' if title.blank?
|
||
|
raise Error, '源文件名不能为空' if filename.blank?
|
||
|
end
|
||
|
|
||
|
def upload_video_result
|
||
|
AliyunVod::Service.create_upload_video(title, filename, params)
|
||
|
rescue AliyunVod::Error => _
|
||
|
raise Error, '获取视频上传凭证失败'
|
||
|
end
|
||
|
end
|