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.
educoder/app/controllers/users/videos_controller.rb

62 lines
1.6 KiB

6 years ago
class Users::VideosController < Users::BaseController
6 years ago
before_action :private_user_resources!, :check_account
before_action :require_teacher!
6 years ago
before_action :require_auth_teacher!, except: [:index, :review]
6 years ago
helper_method :current_video
def index
videos = Users::VideoQuery.call(observed_user, search_params)
@count = videos.count
@videos = paginate videos
end
def update
return render_error('该状态下不能编辑视频信息') unless current_video.published?
current_video.update!(title: params[:title])
AliyunVod::Service.update_video_info(current_video.uuid, Title: current_video.title) rescue nil
end
def cancel
video = observed_user.videos.find_by(uuid: params[:video_id])
return render_not_found if video.blank?
return render_error('该状态下不能删除视频') unless video.pending?
video.destroy!
AliyunVod::Service.delete_video([video.uuid]) rescue nil
render_ok
end
def review
params[:status] = 'processing'
videos = Users::VideoQuery.call(observed_user, params)
@count = videos.count
@videos = paginate videos
end
def batch_publish
Videos::BatchPublishService.call(observed_user, batch_publish_params)
render_ok
rescue Videos::BatchPublishService::Error => ex
render_error(ex.message)
6 years ago
end
private
def current_video
@_current_video ||= observed_user.videos.find_by(id: params[:id])
end
def search_params
params.permit(:keyword, :sort_by, :sort_direction)
end
def batch_publish_params
params.permit(videos: %i[video_id title])
6 years ago
end
end