merge from pre_trustie_server
This commit is contained in:
commit
35a0307667
|
@ -1,6 +1,7 @@
|
||||||
# 代码溯源 导出pdf
|
# 代码溯源 导出pdf
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'zip'
|
||||||
|
|
||||||
class Trace::PdfReportService < Trace::ClientService
|
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)
|
content = open("#{domain}#{base_url}#{url}?task_id=#{task_id}", "Authorization" => token)
|
||||||
if content.is_a?(Tempfile)
|
if content.is_a?(Tempfile)
|
||||||
check_file_path
|
check_file_path
|
||||||
IO.copy_stream(content, "#{save_path}/#{task_id}.pdf")
|
IO.copy_stream(content, "#{save_path}/report.zip")
|
||||||
return {code: 200, download_url: "/trace_task_results/#{task_id}.pdf"}
|
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
|
else
|
||||||
return {code: 404}
|
return {code: 404}
|
||||||
end
|
end
|
||||||
|
@ -28,7 +37,7 @@ class Trace::PdfReportService < Trace::ClientService
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_path
|
def save_path
|
||||||
"public/trace_task_results"
|
"public/trace_task_results/#{task_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
|
|
|
@ -43,7 +43,7 @@ module Gitlink
|
||||||
# origins '*'
|
# origins '*'
|
||||||
origins /http:\/\/localhost(:\d+)?\z/, /^(http|https):\/\/(.*(gitlink.org.cn))$/, /^(http|https):\/\/(.*(trustie.net))$/
|
origins /http:\/\/localhost(:\d+)?\z/, /^(http|https):\/\/(.*(gitlink.org.cn))$/, /^(http|https):\/\/(.*(trustie.net))$/
|
||||||
# location of your api
|
# location of your api
|
||||||
resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put], credentials: true
|
resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put, :patch], credentials: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue