discourse/lib/avatar_upload_service.rb

24 lines
560 B
Ruby
Raw Normal View History

2014-04-14 15:55:57 -05:00
require_dependency "file_helper"
class AvatarUploadService
attr_accessor :source
2014-04-14 15:55:57 -05:00
attr_reader :filesize, :filename, :file
def initialize(file, source)
@source = source
2014-04-14 15:55:57 -05:00
@file, @filename, @filesize = construct(file)
end
def construct(file)
case source
when :url
2014-04-14 15:55:57 -05:00
tmp = FileHelper.download(file, SiteSetting.max_image_size_kb.kilobytes, "discourse-avatar")
[tmp, File.basename(URI.parse(file).path), File.size(tmp)]
when :image
2014-04-14 15:55:57 -05:00
[file.tempfile, file.original_filename, File.size(file.tempfile)]
end
end
end