|
|
|
@@ -1,6 +1,7 @@ |
|
|
|
# 代码溯源 导出pdf |
|
|
|
require 'open-uri' |
|
|
|
require 'fileutils' |
|
|
|
require 'zip' |
|
|
|
|
|
|
|
class Trace::PdfReportService < Trace::ClientService |
|
|
|
|
|
|
|
@@ -15,8 +16,16 @@ class Trace::PdfReportService < Trace::ClientService |
|
|
|
content = open("#{domain}#{base_url}#{url}?task_id=#{task_id}", "Authorization" => token) |
|
|
|
if content.is_a?(Tempfile) |
|
|
|
check_file_path |
|
|
|
IO.copy_stream(content, "#{save_path}/#{task_id}.pdf") |
|
|
|
return {code: 200, download_url: "/trace_task_results/#{task_id}.pdf"} |
|
|
|
IO.copy_stream(content, "#{save_path}/report.zip") |
|
|
|
Zip::File.open("#{save_path}/report.zip") do |zip_file| |
|
|
|
zip_file.each do |f| |
|
|
|
name = f.name.force_encoding('utf-8') |
|
|
|
next unless name == '/report.pdf' |
|
|
|
fpath = File.join(save_path, name) |
|
|
|
zip_file.extract(f, fpath) |
|
|
|
end |
|
|
|
end |
|
|
|
return {code: 200, download_url: "/trace_task_results/#{task_id}/report.pdf"} |
|
|
|
else |
|
|
|
return {code: 404} |
|
|
|
end |
|
|
|
@@ -28,7 +37,7 @@ class Trace::PdfReportService < Trace::ClientService |
|
|
|
end |
|
|
|
|
|
|
|
def save_path |
|
|
|
"public/trace_task_results" |
|
|
|
"public/trace_task_results/#{task_id}" |
|
|
|
end |
|
|
|
|
|
|
|
def url |
|
|
|
|