还原部分代码

gitlab v20150523_2
sw 10 years ago
parent 26cb6225c5
commit 9e4f303742

@ -29,43 +29,51 @@ class AvatarController < ApplicationController
end end
if @temp_file && (@temp_file.size > 0) if @temp_file && (@temp_file.size > 0)
diskfile=disk_filename(@source_type,@source_id) if @temp_file.size > Setting.upload_avatar_max_size.to_i
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) @status = 1
@msg = l(:error_upload_avatar_to_large, :max_size => number_to_human_size(Setting.upload_avatar_max_size.to_i))
elsif Trustie::Utils::Image.new(@temp_file.tempfile.path).image?
diskfile=disk_filename(@source_type,@source_id)
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file))
# 用户头像上传时进行特别处理 # 用户头像上传时进行特别处理
if @source_type == 'User' if @source_type == 'User'
diskfile += "temp" diskfile += "temp"
@urlfile += "temp" @urlfile += "temp"
end end
logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)") logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)")
path = File.dirname(diskfile) path = File.dirname(diskfile)
unless File.directory?(path) unless File.directory?(path)
FileUtils.mkdir_p(path) FileUtils.mkdir_p(path)
end end
md5 = Digest::MD5.new md5 = Digest::MD5.new
File.open(diskfile, "wb") do |f| File.open(diskfile, "wb") do |f|
if @temp_file.respond_to?(:read) if @temp_file.respond_to?(:read)
buffer = "" buffer = ""
while (buffer = @temp_file.read(8192)) while (buffer = @temp_file.read(8192))
f.write(buffer) f.write(buffer)
md5.update(buffer) md5.update(buffer)
end
else
f.write(@temp_file)
md5.update(@temp_file)
end end
else
f.write(@temp_file)
md5.update(@temp_file)
end end
Trustie::Utils::Image.new(diskfile,true).compress(300)
@status = 0
@msg = ''
else
@status = 2
@msg = l(:not_valid_image_file)
end end
# self.digest = md5.hexdigest
end end
@temp_file = nil @temp_file = nil
image = Trustie::Utils::Image.new(diskfile,true)
image.compress(300)
respond_to do |format| respond_to do |format|
format.json{ format.json{
render :inline => "#{@urlfile.to_s}?#{Time.now.to_i}",:content_type => 'text/html' render :inline => {status: @status, message:@msg, url:"#{@urlfile.to_s}?#{Time.now.to_i}"}.to_json,:content_type => 'text/html'
return return
} }
format.js format.js

Loading…
Cancel
Save