2013-06-05 06:34:53 +08:00
|
|
|
module LocalStore
|
|
|
|
|
2013-06-18 04:16:14 +08:00
|
|
|
def self.store_file(file, sha1, image_info, upload_id)
|
2013-06-05 06:34:53 +08:00
|
|
|
clean_name = Digest::SHA1.hexdigest("#{Time.now.to_s}#{file.original_filename}")[0,16] + ".#{image_info.type}"
|
|
|
|
url_root = "/uploads/#{RailsMultisite::ConnectionManagement.current_db}/#{upload_id}"
|
|
|
|
path = "#{Rails.root}/public#{url_root}"
|
|
|
|
|
|
|
|
FileUtils.mkdir_p path
|
|
|
|
# not using cause mv, cause permissions are no good on move
|
|
|
|
File.open("#{path}/#{clean_name}", "wb") do |f|
|
|
|
|
f.write File.read(file.tempfile)
|
|
|
|
end
|
|
|
|
|
|
|
|
# url
|
|
|
|
return Discourse::base_uri + "#{url_root}/#{clean_name}"
|
|
|
|
end
|
|
|
|
|
2013-06-20 03:51:41 +08:00
|
|
|
def self.remove_file(url)
|
|
|
|
File.delete("#{Rails.root}/public#{url}")
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
end
|
|
|
|
|
2013-06-15 17:52:40 +08:00
|
|
|
end
|