From fc3cf01d3f6f730d9ae82b5da0a9ee66164d50ed Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Apr 2022 13:49:08 +0800 Subject: [PATCH] add: get user image action --- app/controllers/users_controller.rb | 7 +++++++ app/helpers/application_helper.rb | 9 +++++++++ app/views/users/get_user_info.json.jbuilder | 2 +- config/routes.rb | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 00ea926fd..acc826614 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -97,6 +97,13 @@ class UsersController < ApplicationController render_error(-1, '头像修改失败!') end + def get_image + return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) + return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) + + redirect_to Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(@user).to_s + end + def me @user = current_user end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f2a9f93b6..e7f8611e7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -147,6 +147,15 @@ module ApplicationHelper end end + def url_to_avatar_with_platform_url(source) + platform_url = Rails.application.config_for(:configuration)['platform_url'] + if platform_url + return Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(source).to_s + else + return url_to_avatar(source).to_s + end + end + # 主页banner图 def banner_img(source_type) if File.exist?(disk_filename(source_type, "banner")) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 2f96c6969..5fa4df167 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -22,4 +22,4 @@ json.city @user.city json.custom_department @user.custom_department json.description @user.description json.(@user, :show_email, :show_department, :show_location) -json.message_unread_total @message_unread_total +json.message_unread_total @message_unread_total diff --git a/config/routes.rb b/config/routes.rb index 7e280820a..da63dab64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,6 +214,7 @@ Rails.application.routes.draw do get :fan_users get :hovercard put :update_image + get :get_image end collection do post :following