From 0c34e186abc7f02156e4b5debe66d9e948acd673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Tue, 19 Jul 2022 17:47:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fixed=20=E4=BF=AE=E6=94=B9=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application.rb | 99 ++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/config/application.rb b/config/application.rb index e1f4f22e..4d226c5a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,49 +1,50 @@ -require_relative 'boot' - -require 'rails/all' - -# Require the gems listed in Gemfile, including any gems -# you've limited to :test, :development, or :production. -Bundler.require(*Rails.groups) - -module Gitlink - class Application < Rails::Application - # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.2 - - # Settings in config/environments/* take precedence over those specified here. - # Application configuration can go into files in config/initializers - # -- all .rb files in that directory are automatically loaded after loading - # the framework and any gems in your application. - # - # - # config.gitlink = config_for(:configuration) - - # Custom directories with classes and modules you want to be autoloadable. - - config.active_record.default_timezone = :utc - config.time_zone = 'Beijing' - - # I18n - config.i18n.default_locale = 'zh-CN' - config.i18n.load_path += Dir[Rails.root.join('config/locales', '**', '*.yml').to_s] - - # job - config.active_job.queue_adapter = :sidekiq - - # disable actioncable development nend true - # config.action_cable.disable_request_forgery_protection = true - - config.middleware.use OmniAuth::Builder do - provider :cas, url: 'https://urp.tfswufe.edu.cn/cas' - end - - config.middleware.insert_before 0, Rack::Cors do - allow do - origins '*' - # location of your api - resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put, :patch] - end - end - end -end +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Gitlink + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.2 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + # + # + # config.gitlink = config_for(:configuration) + + # Custom directories with classes and modules you want to be autoloadable. + + config.active_record.default_timezone = :utc + config.time_zone = 'Beijing' + + # I18n + config.i18n.default_locale = 'zh-CN' + config.i18n.load_path += Dir[Rails.root.join('config/locales', '**', '*.yml').to_s] + + # job + config.active_job.queue_adapter = :sidekiq + + # disable actioncable development nend true + # config.action_cable.disable_request_forgery_protection = true + + config.middleware.use OmniAuth::Builder do + provider :cas, url: 'https://urp.tfswufe.edu.cn/cas' + end + + config.middleware.insert_before 0, Rack::Cors do + allow do + # origins '*' + origins /http:\/\/localhost(:\d+)?\z/, /^(http|https):\/\/(.*(gitlink.org.cn))$/ + # location of your api + resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put, :patch] + end + end + end +end From 0364f81bb3378a23a7b161da055896dd8a7c175a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Jul 2022 10:41:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=BA=AF=E6=BA=90pdf=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/trace/pdf_report_service.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/services/trace/pdf_report_service.rb b/app/services/trace/pdf_report_service.rb index aa731273..7f994762 100644 --- a/app/services/trace/pdf_report_service.rb +++ b/app/services/trace/pdf_report_service.rb @@ -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