Browse Source

add: get user image action

pull/313/head
yystopf 4 years ago
parent
commit
fc3cf01d3f
4 changed files with 18 additions and 1 deletions
  1. +7
    -0
      app/controllers/users_controller.rb
  2. +9
    -0
      app/helpers/application_helper.rb
  3. +1
    -1
      app/views/users/get_user_info.json.jbuilder
  4. +1
    -0
      config/routes.rb

+ 7
- 0
app/controllers/users_controller.rb View File

@@ -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


+ 9
- 0
app/helpers/application_helper.rb View File

@@ -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"))


+ 1
- 1
app/views/users/get_user_info.json.jbuilder View File

@@ -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

+ 1
- 0
config/routes.rb View File

@@ -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


Loading…
Cancel
Save