app/controllers/download/releases_controller.rb
# frozen_string_literal: true
# frozen_string_literal: true
class Download::ReleasesController < ApplicationController
before_action :set_release
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_entity_response
def show
return render_not_found_entity_response unless File.exist?(@release.file.path.to_s)
redirect_to filename_download_release_url(@release, @release.download_filename)
end
def download
# 触发 web_hook
@release.channel.perform_web_hook('download_events', current_user&.id)
headers['Content-Length'] = @release.file.size
send_file @release.file.path,
filename: @release.download_filename,
disposition: 'attachment'
end
private
def render_not_found_entity_response
render json: {
error: t('.not_found')
}, status: :not_found
end
def set_release
@release = Release.find(params[:id])
end
end