修复: 代码溯源pdf只需下载一次

This commit is contained in:
yystopf 2022-07-21 10:52:21 +08:00
parent 0364f81bb3
commit 6244a713ae
1 changed files with 11 additions and 5 deletions

View File

@ -69,13 +69,19 @@ class Traces::ProjectsController < Traces::BaseController
def task_pdf def task_pdf
return render_error("task_id错误") if params[:task_id].blank? task_id = params[:task_id]
result = Trace::PdfReportService.call(current_user.trace_token, params[:task_id]) return render_error("task_id错误") if task_id.blank?
file_save_path = "public/trace_task_results/#{task_id}/report.pdf"
if File.exists?(file_save_path)
redirect_to "/trace_task_results/#{task_id}/report.pdf"
else
result = Trace::PdfReportService.call(current_user.trace_token, task_id)
if result.is_a?(Hash) && result[:code] == 200 if result.is_a?(Hash) && result[:code] == 200
redirect_to result[:download_url] redirect_to result[:download_url]
else else
render_error("下载报告失败!") render_error("下载报告失败!")
end end
end
rescue Exception => exception rescue Exception => exception
puts exception.message puts exception.message
normal_status(-1, exception.message) normal_status(-1, exception.message)