From 25ff4cd65453536c9559cfcbca76e6bd55e87b52 Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 22 Jun 2021 15:05:10 +0800 Subject: [PATCH] FIX merge confilicts --- app/controllers/application_controller.rb | 24 +++++++++++++++++++++++ config/configuration.yml.example | 1 + 2 files changed, 25 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 29595dc6..07c07c52 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -770,6 +770,30 @@ class ApplicationController < ActionController::Base @repository ||= load_project&.repository end + def base_url + Rails.application.config_for(:configuration)['platform_url'] || request.base_url + end + + def convert_image! + @image = params[:image] || user_params[:image] + return unless @image.present? + max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M + if @image.class == ActionDispatch::Http::UploadedFile + render_error('请上传文件') if @image.size.zero? + render_error('文件大小超过限制') if @image.size > max_size.to_i + else + image = @image.to_s.strip + return render_error('请上传正确的图片') if image.blank? + @image = Util.convert_base64_image(image, max_size: max_size.to_i) + end + rescue Base64ImageConverter::Error => ex + render_error(ex.message) + end + + def avatar_path(object) + ApplicationController.helpers.disk_filename(object.class, object.id) + end + private def object_not_found uid_logger("Missing template or cant't find record, responding with 404") diff --git a/config/configuration.yml.example b/config/configuration.yml.example index 823d8547..61d461cf 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -1,6 +1,7 @@ default: &default # 用户登入的时候设置/登出的时候清空 autologin_cookie_name: 'autologin_trustie' + platform_url: 'http://localhost:3000' #附件上传路径