From dcda8671b3d7836074b18334393dd766ba46a86c Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Wed, 20 Jan 2021 17:00:19 +0800 Subject: [PATCH 1/4] FIX pipeline model schma --- app/models/ci/pipeline.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 9448512b7..f4d5f2dae 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -4,13 +4,13 @@ # # id :integer not null, primary key # pipeline_name :string(255) not null +# pipeline_status :string(255) default("unknown"), not null # file_name :string(255) not null # created_at :datetime not null # updated_at :datetime not null -# pipeline_status :string(50) default("unknown"), not null # login :string(255) # sync :integer default("0"), not null -# project_id :integer +# identifier :string(255) # class Ci::Pipeline < Ci::LocalBase From 3b7d425198fd4ebc894f6da3e5534de5cde0a69f Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 26 Jan 2021 14:49:02 +0800 Subject: [PATCH 2/4] ADD upload avatar api with support multiple image formats --- app/libs/base64_image_converter.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/libs/base64_image_converter.rb b/app/libs/base64_image_converter.rb index 2dc9aa41e..b2563e434 100644 --- a/app/libs/base64_image_converter.rb +++ b/app/libs/base64_image_converter.rb @@ -1,5 +1,7 @@ class Base64ImageConverter - BASE64_HEAD = 'data:image/jpeg;base64,'.freeze + # BASE64_HEAD = 'data:image/jpeg;base64,'.freeze + BASE64_HEAD_ARRAY = ['data:image/jpeg;base64,', 'data:image/jpg;base64,', + 'data:image/png;base64,', 'data:image/gif;base64,'] Error = Class.new(StandardError) OutLimit = Class.new(Error) @@ -27,11 +29,20 @@ class Base64ImageConverter private def valid_base64?(data) - data&.start_with?(BASE64_HEAD) + # data&.start_with?(BASE64_HEAD) + BASE64_HEAD_ARRAY.include? base64_head_data(data) + end + + def base64_head_data(data) + data&.split(',')[0] + ',' + end + + def base64_head(data) + valid_base64?(data) ? base64_head_data(data) : '' end def image_data(data) - data[BASE64_HEAD.size..-1] + data[base64_head(data).size..-1] end def size_limit @@ -74,4 +85,4 @@ class Base64ImageConverter data[0,2] == 0x89.chr + 80.chr end end -end \ No newline at end of file +end From a93baa908f831a22c4cb6301f2a3c2c6decc47f2 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Wed, 27 Jan 2021 17:22:16 +0800 Subject: [PATCH 3/4] FIX CORS problem for develop --- config/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index a09b08def..62d95dbf2 100644 --- a/config/application.rb +++ b/config/application.rb @@ -42,7 +42,7 @@ module Educoderplus allow do origins '*' # location of your api - resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put] + resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put, :patch] end end end From 458fca9992281d88c704761305446ef369f6c7ea Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 28 Jan 2021 15:11:47 +0800 Subject: [PATCH 4/4] fix change stoage file derictory --- app/controllers/attachments_controller.rb | 12 ++++++------ app/controllers/users_controller.rb | 3 ++- app/helpers/application_helper.rb | 10 +++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 16842fb55..14e53b3e2 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -28,8 +28,8 @@ class AttachmentsController < ApplicationController update_downloads(@file) end - - def get_file + + def get_file normal_status(-1, "参数缺失") if params[:download_url].blank? url = URI.encode(params[:download_url].to_s.gsub("http:", "https:")) response = Faraday.get(url) @@ -45,7 +45,7 @@ class AttachmentsController < ApplicationController uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}") raise "未上传文件" unless upload_file - folder = edu_setting('attachment_folder') + folder = file_storage_directory raise "存储目录未定义" unless folder.present? month_folder = current_month_folder @@ -108,7 +108,7 @@ class AttachmentsController < ApplicationController end # 附件为视频时,点击播放 - def preview_attachment + def preview_attachment attachment = Attachment.find_by(id: params[:id]) dir_path = "#{Rails.root}/public/preview" Dir.mkdir(dir_path) unless Dir.exist?(dir_path) @@ -118,10 +118,10 @@ class AttachmentsController < ApplicationController else normal_status(-1, "出现错误,请稍后重试") end - else + else if system("rm -rf #{dir_path}/#{attachment.disk_filename}") normal_status(1, "操作成功") - else + else normal_status(-1, "出现错误,请稍后重试") end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4a67fd413..d5ca638a6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + include ApplicationHelper include Ci::DbConnectable before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users] @@ -79,7 +80,7 @@ class UsersController < ApplicationController def attachment_show file_name = params[:file_name] - path = params[:path] || edu_setting('attachment_folder') + path = params[:path] || file_storage_directory send_file "#{path}/#{file_name}", :filename => "#{file_name}", :type => 'game', :disposition => 'attachment' #inline can open in browser diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1ac9a85b7..75532188e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -322,7 +322,15 @@ module ApplicationHelper end def absolute_path(file_path) - File.join(edu_setting('attachment_folder'), file_path) + file_root_directory + File.join(edu_setting('attachment_folder'), file_path) + end + + def file_root_directory + Rails.root.to_s + end + + def file_storage_directory + file_root_directory + edu_setting('attachment_folder') end def local_path(file)