软删除视频

courseware
anke1460 5 years ago
parent a6f222934f
commit 7634d075dc

@ -132,7 +132,6 @@ class CoursesController < ApplicationController
tip_exception(404, "找不到资源") if video.blank?
tip_exception(403, "...") unless (video.user_id == current_user.id || current_user.admin_or_business?)
video.destroy!
AliyunVod::Service.delete_video([video.uuid]) rescue nil
end
render_ok

@ -26,7 +26,6 @@ class Users::VideosController < Users::BaseController
return render_error('该状态下不能删除视频') unless video.pending?
video.destroy!
AliyunVod::Service.delete_video([video.uuid]) rescue nil
render_ok
end
@ -61,8 +60,6 @@ class Users::VideosController < Users::BaseController
video.destroy!
AliyunVod::Service.delete_video([video.uuid]) rescue nil
render_ok
end

@ -1,6 +1,13 @@
class Video < ApplicationRecord
include AASM
alias_method :hard_destroy, :destroy
default_scope -> { where(delete_state: nil) }
scope :deleted, -> { unscope(where: :delete_state).where.not(delete_state: nil) }
BEGIN_DELETE = 1 # 标记软删除
FINISH_DELETE = 2 # 视频资源完成删除
# 标准视频转码组
NORMAL_TRANSCODE_GROUP_ID = 'a0277c5c0c7458458e171b0cee6ebf5e'
@ -41,4 +48,21 @@ class Video < ApplicationRecord
def video_play_duration
(play_duration / (60*60.0)).ceil
end
def destroy
run_callbacks(:destroy) do
if persisted?
update_column(:delete_state, Video::BEGIN_DELETE)
# result = AliyunVod::Service.delete_video([self.uuid])
# if result && result['RequestId']
# update_column(:delete_state, Video::FINISH_DELETE)
# end
end
@destroyed = true
end
freeze
end
end

@ -23,6 +23,8 @@ class Videos::DispatchCallbackService < ApplicationService
when 'StreamTranscodeComplete' then # 转码完成
return if video.play_url.present?
video.update!(play_url: params['FileUrl'], transcoded: true)
when 'DeleteMediaComplete' #完成云端视频删除
video.update_column(:delete_state, Video::FINISH_DELETE)
end
rescue => ex

@ -0,0 +1,6 @@
class AddDeleteStateToVideo < ActiveRecord::Migration[5.2]
def change
add_column :videos, :delete_state, :integer
add_index :videos, :delete_state
end
end
Loading…
Cancel
Save