discourse/lib/avatar_upload_service.rb

24 lines
548 B
Ruby
Raw Normal View History

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