class Callbacks::AliyunVodsController < Callbacks::BaseController
  before_action :check_signature_valid!

  def create
    Videos::DispatchCallbackService.call(params)
    render_ok
  end

  private

  def check_signature_valid!
    return if AliyunVod::Sign.verify?(header_signature, header_timestamp)

    render_not_acceptable
  end

  def header_timestamp
    request.headers['X-VOD-TIMESTAMP']
  end

  def header_signature
    request.headers['X-VOD-SIGNATURE']
  end
end