mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-21 20:25:45 +08:00
add: download pdf from trace server
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
# 代码溯源 导出pdf
|
||||
require 'open-uri'
|
||||
require 'fileutils'
|
||||
|
||||
class Trace::PdfReportService < Trace::ClientService
|
||||
|
||||
attr_accessor :token, :task_id
|
||||
@@ -9,15 +12,23 @@ class Trace::PdfReportService < Trace::ClientService
|
||||
end
|
||||
|
||||
def call
|
||||
result = authed_get(token, url, request_params)
|
||||
response = render_response(result)
|
||||
content = URI.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}.zip")
|
||||
return {code: 200, download_url: "/trace_task_results/#{task_id}.zip"}
|
||||
else
|
||||
return {code: 404}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def request_params
|
||||
{
|
||||
task_id: task_id
|
||||
}
|
||||
def check_file_path
|
||||
FileUtils.mkdir_p save_path
|
||||
end
|
||||
|
||||
def save_path
|
||||
"public/trace_task_results"
|
||||
end
|
||||
|
||||
def url
|
||||
|
||||
Reference in New Issue
Block a user