2017-03-21 23:15:11 +08:00
|
|
|
class ZipExportsController < ApplicationController
|
2017-03-27 16:38:28 +08:00
|
|
|
before_action :load_var, only: :download
|
2018-09-17 02:28:26 +08:00
|
|
|
before_action :load_var_export_all, only: :download_export_all_zip
|
2017-03-27 16:38:28 +08:00
|
|
|
before_action :check_edit_permissions, only: :download
|
2017-03-21 23:15:11 +08:00
|
|
|
|
|
|
|
def download
|
2017-03-23 22:45:02 +08:00
|
|
|
if @zip_export.stored_on_s3?
|
|
|
|
redirect_to @zip_export.presigned_url(download: true), status: 307
|
|
|
|
else
|
|
|
|
send_file @zip_export.zip_file.path,
|
|
|
|
filename: URI.unescape(@zip_export.zip_file_file_name),
|
2017-04-26 19:23:30 +08:00
|
|
|
type: 'application/zip'
|
2017-03-23 22:45:02 +08:00
|
|
|
end
|
2017-03-21 23:15:11 +08:00
|
|
|
end
|
|
|
|
|
2018-09-17 02:28:26 +08:00
|
|
|
def download_export_all_zip
|
|
|
|
download
|
|
|
|
end
|
|
|
|
|
2017-03-29 15:32:23 +08:00
|
|
|
def file_expired; end
|
2017-03-27 16:38:28 +08:00
|
|
|
|
2017-03-21 23:15:11 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def load_var
|
|
|
|
@zip_export = ZipExport.find_by_id(params[:id])
|
2017-03-27 16:38:28 +08:00
|
|
|
redirect_to(file_expired_url, status: 301) and return unless @zip_export
|
2017-03-21 23:15:11 +08:00
|
|
|
end
|
|
|
|
|
2018-09-17 02:28:26 +08:00
|
|
|
def load_var_export_all
|
|
|
|
@zip_export = TeamZipExport.find_by_id(params[:id])
|
|
|
|
redirect_to(file_expired_url, status: 301) and return unless @zip_export
|
|
|
|
end
|
|
|
|
|
2017-03-21 23:15:11 +08:00
|
|
|
def check_edit_permissions
|
|
|
|
render_403 unless @zip_export.user == current_user
|
|
|
|
end
|
|
|
|
end
|