From fc0d0f0f2cd0bab56c2173a38e2a68c4cba2039b Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Mon, 27 Oct 2014 22:42:38 +0800 Subject: [PATCH 01/15] bump version to v0.4.2 --- lib/carrierwave/webdav/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/webdav/version.rb b/lib/carrierwave/webdav/version.rb index 7f0057b..ed0e0dd 100644 --- a/lib/carrierwave/webdav/version.rb +++ b/lib/carrierwave/webdav/version.rb @@ -1,5 +1,5 @@ module CarrierWave module WebDAV - VERSION = "0.4.1" + VERSION = "0.4.2" end end From a212ac93f72c2620e49a6caeb81f26eae3961f71 Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Thu, 29 Sep 2016 19:33:29 +0300 Subject: [PATCH 02/15] Fix behaviour when asset_host is set --- lib/carrierwave/storage/webdav.rb | 6 +++++- spec/lib/webdav_spec.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/storage/webdav.rb b/lib/carrierwave/storage/webdav.rb index 8f6e8e8..69c8871 100644 --- a/lib/carrierwave/storage/webdav.rb +++ b/lib/carrierwave/storage/webdav.rb @@ -100,7 +100,11 @@ def delete end def url - "#{server}/#{path}" + if host = uploader.asset_host + host.respond_to?(:call) ? host.call(self) : [host, path].join('/') + else + "#{server}/#{path}" + end end alias :content_length :length diff --git a/spec/lib/webdav_spec.rb b/spec/lib/webdav_spec.rb index 924736b..0eaf188 100644 --- a/spec/lib/webdav_spec.rb +++ b/spec/lib/webdav_spec.rb @@ -91,4 +91,33 @@ expect(@file.read).to eq(webdav_file.read) end + describe '#image_url' do + let(:root) { Pathname.new(@file.path).dirname } + let(:path) { @uploader.path.sub(root.to_path, '') } + + before do + CarrierWave.configure do |config| + config.asset_host = host + config.root = root + end + end + + context 'when asset_host is set' do + let(:host) { 'http://asset.host' } + + it 'path contains asset_host' do + @uploader.cache!(@file) + expect(@uploader.url).to eq [host, path].join + end + end + + context 'when asset_host is not set' do + let(:host) { nil } + + it 'path does not contain asset_host' do + @uploader.cache!(@file) + expect(@uploader.url).to eq path + end + end + end end From 0303ab30294ab322859e266a353fbfe7100f7624 Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Fri, 30 Sep 2016 11:03:14 +0300 Subject: [PATCH 03/15] Fix describe name --- spec/lib/webdav_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/webdav_spec.rb b/spec/lib/webdav_spec.rb index 0eaf188..45b8ac6 100644 --- a/spec/lib/webdav_spec.rb +++ b/spec/lib/webdav_spec.rb @@ -91,7 +91,7 @@ expect(@file.read).to eq(webdav_file.read) end - describe '#image_url' do + describe 'File#url' do let(:root) { Pathname.new(@file.path).dirname } let(:path) { @uploader.path.sub(root.to_path, '') } From 581e88e9b63781e8aa075cdf348c177893884e23 Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Fri, 30 Sep 2016 13:03:26 +0300 Subject: [PATCH 04/15] Url fixes --- lib/carrierwave/storage/webdav.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/carrierwave/storage/webdav.rb b/lib/carrierwave/storage/webdav.rb index 69c8871..a6c6496 100644 --- a/lib/carrierwave/storage/webdav.rb +++ b/lib/carrierwave/storage/webdav.rb @@ -56,7 +56,7 @@ def initialize(uploader, path) end def read - res = HTTParty.get(url, options) + res = HTTParty.get(read_url, options) if res.code != 200 raise CarrierWave::IntegrityError.new("Can't download a file: #{res.inspect}") end @@ -64,7 +64,7 @@ def read end def headers - res = HTTParty.head(url, options) + res = HTTParty.head(read_url, options) if res.code != 200 raise CarrierWave::IntegrityError.new("Can't headers for a file: #{res.inspect}") end @@ -103,7 +103,7 @@ def url if host = uploader.asset_host host.respond_to?(:call) ? host.call(self) : [host, path].join('/') else - "#{server}/#{path}" + read_url end end @@ -113,8 +113,12 @@ def url private + def read_url + "#{server}/#{path}" + end + def write_url - @write_server ? "#{@write_server}/#{path}" : url + @write_server ? "#{@write_server}/#{path}" : read_url end def mkcol From c664b6ed3d54e4cf19bb7c7292a40fb3cceb2ff4 Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Fri, 30 Sep 2016 21:23:45 +0800 Subject: [PATCH 05/15] upgrade travis ruby version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 11a115a..8349955 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: ruby rvm: - - 1.9.3 + - 2.0.0 From c02dddd43ee3d231dc57e4b228c930f6831e1c5f Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Fri, 30 Sep 2016 21:31:12 +0800 Subject: [PATCH 06/15] bump version to 0.4.3 --- .travis.yml | 2 +- lib/carrierwave/webdav/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8349955..23a0abe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: ruby rvm: - - 2.0.0 + - 2.2.2 diff --git a/lib/carrierwave/webdav/version.rb b/lib/carrierwave/webdav/version.rb index ed0e0dd..7895265 100644 --- a/lib/carrierwave/webdav/version.rb +++ b/lib/carrierwave/webdav/version.rb @@ -1,5 +1,5 @@ module CarrierWave module WebDAV - VERSION = "0.4.2" + VERSION = "0.4.3" end end From 47f4d881d8bea2d54ac9fc70172a88f3d71955ad Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Mon, 30 Jan 2017 11:00:15 +0300 Subject: [PATCH 07/15] Allow to use webdav storage as cache storage --- Gemfile | 2 +- carrierwave-webdav.gemspec | 1 - lib/carrierwave/storage/webdav.rb | 157 +++++++++++------------------- lib/carrierwave/webdav/file.rb | 110 +++++++++++++++++++++ 4 files changed, 166 insertions(+), 104 deletions(-) create mode 100644 lib/carrierwave/webdav/file.rb diff --git a/Gemfile b/Gemfile index 7ff0da7..b3138bf 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,4 @@ gemspec gem 'rake' gem 'rspec' gem 'webmock', :require => 'webmock/rspec' -gem 'coveralls', require: false \ No newline at end of file +gem 'coveralls', require: false diff --git a/carrierwave-webdav.gemspec b/carrierwave-webdav.gemspec index 267e6e0..6784d0d 100644 --- a/carrierwave-webdav.gemspec +++ b/carrierwave-webdav.gemspec @@ -19,5 +19,4 @@ Gem::Specification.new do |gem| gem.add_dependency 'carrierwave' gem.add_dependency 'httparty' - end diff --git a/lib/carrierwave/storage/webdav.rb b/lib/carrierwave/storage/webdav.rb index a6c6496..524d957 100644 --- a/lib/carrierwave/storage/webdav.rb +++ b/lib/carrierwave/storage/webdav.rb @@ -1,8 +1,57 @@ require 'carrierwave/httparty_monkey' +require 'carrierwave/webdav/file' module CarrierWave module Storage class WebDAV < Abstract + # Store file in WebDAV cache directory + # + # === Parameters + # + # [ file (CarrierWave::SanitizedFile) ] the file to store + # + # === Returns + # + # [ CarrierWave::Storage::WebDAV::File ] a sanitized file + # + def cache!(file) + cached = build_webdav_file(uploader.cache_path) + cached.write(file.read) + cached + end + + # Retrieve file with given cache identifier from WebDAV + # + # === Parameters + # + # [ identifier (String) ] cache identifier + # + # === Returns + # + # [ CarrierWave::Storage::WebDAV::File ] a sanitized file + # + def retrieve_from_cache!(identifier) + build_webdav_file(uploader.cache_path(identifier)) + end + + # Delete cache directory from WebDAV + # + # === Parameters + # + # [ path (String) ] cache path + # + # === Returns + # + # [ HTTParty::Response ] httparty response object + # + # === Raises + # + # [ CarrierWave::IntegrityError ] + # + def delete_dir!(path) + cached = build_webdav_file(path) + cached.delete_dir + end # Store the file in WebDAV # @@ -12,10 +61,10 @@ class WebDAV < Abstract # # === Returns # - # [ CarrierWave::SanitizedFile ] a sanitized file + # [ CarrierWave::Store::WebDAV::File ] a sanitized file # def store!(file) - stored = CarrierWave::Storage::WebDAV::File.new(uploader, uploader.store_path) + stored = build_webdav_file(uploader.store_path) stored.write(file.read) stored end @@ -31,110 +80,14 @@ def store!(file) # [ CarrierWave::Store::WebDAV::File ] a sanitized file # def retrieve!(identifier) - CarrierWave::Storage::WebDAV::File.new(uploader, uploader.store_path(identifier)) + build_webdav_file(uploader.store_path(identifier)) end - class File - attr_reader :path - attr_reader :uploader - attr_reader :options - attr_reader :server # Like 'https://www.WebDAV.com/dav' - - def initialize(uploader, path) - @path = path - @path.sub! /^\//, '' - @uploader = uploader - @server = uploader.webdav_server - @server.sub! /\/$/, '' - @write_server = uploader.webdav_write_server - @write_server.sub!(/\/$/, '') if @write_server - @username = uploader.webdav_username - @password = uploader.webdav_password || '' - @options = {} - @options = { basic_auth: { username: @username, password: @password } } if @username - @create_dirs = !uploader.webdav_autocreates_dirs - end - - def read - res = HTTParty.get(read_url, options) - if res.code != 200 - raise CarrierWave::IntegrityError.new("Can't download a file: #{res.inspect}") - end - res.body - end - - def headers - res = HTTParty.head(read_url, options) - if res.code != 200 - raise CarrierWave::IntegrityError.new("Can't headers for a file: #{res.inspect}") - end - res.headers - end - - def write(file) - if @create_dirs - res = mkcol - end - - res = HTTParty.put(write_url, options.merge({ body: file })) - if res.code != 201 and res.code != 204 - raise CarrierWave::IntegrityError.new("Can't put a new file: #{res.inspect}") - end - res - end - - def length - read.bytesize - end - - def content_type - headers.content_type - end - - def delete - res = HTTParty.delete(write_url, options) - if res.code != 200 and res.code != 204 and res.code != 404 - raise CarrierWave::IntegrityError.new("Can't delete a file: #{res.inspect}") - end - res - end - - def url - if host = uploader.asset_host - host.respond_to?(:call) ? host.call(self) : [host, path].join('/') - else - read_url - end - end - - alias :content_length :length - alias :file_length :length - alias :size :length - private - def read_url - "#{server}/#{path}" - end - - def write_url - @write_server ? "#{@write_server}/#{path}" : read_url - end - - def mkcol - dirs = [] - path.split('/')[0...-1].each do |dir| - dirs << "#{dirs[-1]}/#{dir}" - end # Make path like a/b/c/t.txt to array ['/a', '/a/b', '/a/b/c'] - use_server = @write_server ? @write_server : server - dirs.each do |dir| - res = HTTParty.mkcol("#{use_server}#{dir}", options) - unless [200, 201, 207, 409].include? res.code - raise CarrierWave::IntegrityError.new("Can't create a new collection: #{res.inspect}") - end - end # Make collections recursively - end - end # File + def build_webdav_file(path) + CarrierWave::WebDAV::File.new(uploader, path) + end end # WebDAV end # Storage end # CarrierWave diff --git a/lib/carrierwave/webdav/file.rb b/lib/carrierwave/webdav/file.rb new file mode 100644 index 0000000..e6a85e3 --- /dev/null +++ b/lib/carrierwave/webdav/file.rb @@ -0,0 +1,110 @@ +module CarrierWave + module WebDAV + class File + attr_reader :path + attr_reader :uploader + attr_reader :options + attr_reader :server # Like 'https://www.WebDAV.com/dav' + + def initialize(uploader, path) + @path = path + @path.sub! /^\//, '' + @uploader = uploader + @server = uploader.webdav_server + @server.sub! /\/$/, '' + @write_server = uploader.webdav_write_server + @write_server.sub!(/\/$/, '') if @write_server + @username = uploader.webdav_username + @password = uploader.webdav_password || '' + @options = {} + @options = { basic_auth: { username: @username, password: @password } } if @username + @create_dirs = !uploader.webdav_autocreates_dirs + end + + def read + res = HTTParty.get(read_url, options) + if res.code != 200 + raise CarrierWave::IntegrityError.new("Can't download a file: #{res.inspect}") + end + res.body + end + + def headers + res = HTTParty.head(read_url, options) + if res.code != 200 + raise CarrierWave::IntegrityError.new("Can't headers for a file: #{res.inspect}") + end + res.headers + end + + def write(file) + if @create_dirs + res = mkcol + end + + res = HTTParty.put(write_url, options.merge({ body: file })) + if res.code != 201 and res.code != 204 + raise CarrierWave::IntegrityError.new("Can't put a new file: #{res.inspect}") + end + res + end + + def length + read.bytesize + end + + def content_type + headers.content_type + end + + def delete + res = HTTParty.delete(write_url, options) + if res.code != 200 and res.code != 204 and res.code != 404 + raise CarrierWave::IntegrityError.new("Can't delete a file: #{res.inspect}") + end + res + end + + def delete_dir + @path += '/' unless path.end_with?('/') + delete + end + + def url + if host = uploader.asset_host + host.respond_to?(:call) ? host.call(self) : [host, path].join('/') + else + read_url + end + end + + alias :content_length :length + alias :file_length :length + alias :size :length + + private + + def read_url + "#{server}/#{path}" + end + + def write_url + @write_server ? "#{@write_server}/#{path}" : read_url + end + + def mkcol + dirs = [] + path.split('/')[0...-1].each do |dir| + dirs << "#{dirs[-1]}/#{dir}" + end # Make path like a/b/c/t.txt to array ['/a', '/a/b', '/a/b/c'] + use_server = @write_server ? @write_server : server + dirs.each do |dir| + res = HTTParty.mkcol("#{use_server}#{dir}", options) + unless [200, 201, 207, 409].include? res.code + raise CarrierWave::IntegrityError.new("Can't create a new collection: #{res.inspect}") + end + end # Make collections recursively + end + end # File + end # WebDAV +end # CarrierWave From d31997223f70d0874cea20bd6433ec128ec3b20b Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Mon, 30 Jan 2017 11:01:30 +0300 Subject: [PATCH 08/15] Add specs --- spec/fixtures/tmp_test.txt | 1 + spec/lib/webdav_file_spec.rb | 41 ++++++++ ...{webdav_spec.rb => webdav_storage_spec.rb} | 97 +++++++++++-------- spec/spec_helper.rb | 2 +- 4 files changed, 98 insertions(+), 43 deletions(-) create mode 100644 spec/fixtures/tmp_test.txt create mode 100644 spec/lib/webdav_file_spec.rb rename spec/lib/{webdav_spec.rb => webdav_storage_spec.rb} (51%) diff --git a/spec/fixtures/tmp_test.txt b/spec/fixtures/tmp_test.txt new file mode 100644 index 0000000..27c7b93 --- /dev/null +++ b/spec/fixtures/tmp_test.txt @@ -0,0 +1 @@ +Hello, this is tmp test data. diff --git a/spec/lib/webdav_file_spec.rb b/spec/lib/webdav_file_spec.rb new file mode 100644 index 0000000..a8a1cd4 --- /dev/null +++ b/spec/lib/webdav_file_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe CarrierWave::WebDAV::File do + describe '#url' do + let(:webdav_server) { 'https://your.webdavserver.com/dav/' } + + before do + CarrierWave.configure do |config| + config.storage = :webdav + config.cache_storage = :webdav + config.webdav_server = webdav_server + config.asset_host = host + + config.webdav_autocreates_dirs = true + end + + @uploader = CarrierWave::Uploader::Base.new + @file = File.open(file_path('test.txt')) + + stub_request(:put, %r{#{Regexp.escape(webdav_server)}}).to_return(status: 201) + end + + context 'when asset_host is set' do + let(:host) { 'http://asset.host' } + + it 'path contains asset_host' do + @uploader.cache!(@file) + expect(@uploader.file.url).to eq [host, @uploader.file.path].join('/') + end + end + + context 'when asset_host is not set' do + let(:host) { nil } + + it 'path does not contain asset_host' do + @uploader.cache!(@file) + expect(@uploader.file.url).to eq [webdav_server, @uploader.file.path].join('/') + end + end + end +end diff --git a/spec/lib/webdav_spec.rb b/spec/lib/webdav_storage_spec.rb similarity index 51% rename from spec/lib/webdav_spec.rb rename to spec/lib/webdav_storage_spec.rb index 45b8ac6..49cbc73 100644 --- a/spec/lib/webdav_spec.rb +++ b/spec/lib/webdav_storage_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'carrierwave/webdav' require 'uri' describe CarrierWave::Storage::WebDAV do @@ -13,15 +12,46 @@ end @uploader = CarrierWave::Uploader::Base.new - @uploader.stub store_path: 'uploads/test.txt' + + allow(@uploader).to receive(:store_path) { 'uploads/test.txt' } + allow(@uploader).to receive(:cache_path) { 'uploads/tmp_test.txt' } @storage = CarrierWave::Storage::WebDAV.new(@uploader) @file = CarrierWave::SanitizedFile.new(file_path('test.txt')) - @uri = URI(@uploader.webdav_server) - @uri.user = @uploader.webdav_username - @uri.password = @uploader.webdav_password - @uri.merge! @uploader.store_path + # NOTE: specs fail with this options + # + # @uri.user = @uploader.webdav_username + # @uri.password = @uploader.webdav_password + + @uri = URI(File.join(@uploader.webdav_server, @uploader.store_path)) + @cache_uri = URI(File.join(@uploader.webdav_server, @uploader.cache_path)) + end + + describe '#cache!' do + it 'should cache from WebDAV' do + stub_mkcol @cache_uri + stub_put @cache_uri + webdav_file = @storage.cache!(@file) + stub_get @cache_uri + expect(@file.read).to eq(webdav_file.read) + end + end + + describe '#retrieve_from_cache!' do + it 'should retreive a cache file from WebDAV' do + stub_get @cache_uri + webdav_file = @storage.retrieve_from_cache!('tmp_test.txt') + expect(@file.read).to eq(webdav_file.read) + end + end + + describe '#delete_dir!' do + it 'should delete cache directory' do + stub_delete File.join(@uploader.webdav_server, 'uploads/') + result = @storage.delete_dir!('uploads') + expect(Net::HTTPOK).to eq(result.response.class) + end end it 'should store from WebDAV' do @@ -73,51 +103,34 @@ expect("#{@uploader.webdav_server}/#{@uploader.store_path}").to eq(webdav_file.url) end - it 'should save through secure server' do - CarrierWave.configure do |config| - config.webdav_write_server = 'https://secure.your.webdavserver.com/dav/' - end - - secure_uri = URI(@uploader.webdav_write_server) - secure_uri.user = @uploader.webdav_username - secure_uri.password = @uploader.webdav_password - secure_uri.merge! @uploader.store_path - - stub_mkcol secure_uri - stub_put secure_uri - webdav_file = @storage.store!(@file) - - stub_get @uri - expect(@file.read).to eq(webdav_file.read) - end - - describe 'File#url' do - let(:root) { Pathname.new(@file.path).dirname } - let(:path) { @uploader.path.sub(root.to_path, '') } - + context 'when use write server' do before do CarrierWave.configure do |config| - config.asset_host = host - config.root = root + config.webdav_write_server = 'https://secure.your.webdavserver.com/dav/' end end - context 'when asset_host is set' do - let(:host) { 'http://asset.host' } - - it 'path contains asset_host' do - @uploader.cache!(@file) - expect(@uploader.url).to eq [host, path].join + after do + CarrierWave.configure do |config| + config.webdav_write_server = nil end end - context 'when asset_host is not set' do - let(:host) { nil } + it 'should save through secure server' do + secure_uri = URI(File.join(@uploader.webdav_write_server, @uploader.store_path)) - it 'path does not contain asset_host' do - @uploader.cache!(@file) - expect(@uploader.url).to eq path - end + # NOTE: specs fail with this options + # + # secure_uri.user = @uploader.webdav_username + # secure_uri.password = @uploader.webdav_password + + stub_mkcol secure_uri + stub_put secure_uri + webdav_file = @storage.store!(@file) + + stub_get @uri + expect(@file.read).to eq(webdav_file.read) end end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0a2f8d2..e7bb23e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ Dir['spec/supports/**/*.rb'].each { |f| require File.expand_path(f) } require 'carrierwave' +require 'carrierwave/webdav' if ENV['TRAVIS'] require 'coveralls' @@ -14,4 +15,3 @@ WebMock.disable_net_connect! config.include Helpers end - From 1bf9e5db78219c2914e9a88e3d1b858d7eb3187e Mon Sep 17 00:00:00 2001 From: Alexey Pokhozhaev Date: Mon, 30 Jan 2017 11:04:36 +0300 Subject: [PATCH 09/15] Fix namespaces --- lib/carrierwave/storage/webdav.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/carrierwave/storage/webdav.rb b/lib/carrierwave/storage/webdav.rb index 524d957..81b4c34 100644 --- a/lib/carrierwave/storage/webdav.rb +++ b/lib/carrierwave/storage/webdav.rb @@ -12,7 +12,7 @@ class WebDAV < Abstract # # === Returns # - # [ CarrierWave::Storage::WebDAV::File ] a sanitized file + # [ CarrierWave::WebDAV::File ] a sanitized file # def cache!(file) cached = build_webdav_file(uploader.cache_path) @@ -28,7 +28,7 @@ def cache!(file) # # === Returns # - # [ CarrierWave::Storage::WebDAV::File ] a sanitized file + # [ CarrierWave::WebDAV::File ] a sanitized file # def retrieve_from_cache!(identifier) build_webdav_file(uploader.cache_path(identifier)) @@ -61,7 +61,7 @@ def delete_dir!(path) # # === Returns # - # [ CarrierWave::Store::WebDAV::File ] a sanitized file + # [ CarrierWave::WebDAV::File ] a sanitized file # def store!(file) stored = build_webdav_file(uploader.store_path) @@ -77,7 +77,7 @@ def store!(file) # # === Returns # - # [ CarrierWave::Store::WebDAV::File ] a sanitized file + # [ CarrierWave::WebDAV::File ] a sanitized file # def retrieve!(identifier) build_webdav_file(uploader.store_path(identifier)) From cf87fbcdc00fc79374e0a11b726cb683ba0e8c7e Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Tue, 31 Jan 2017 17:11:09 +0800 Subject: [PATCH 10/15] update coveralls' token, bump version to 0.5.0 --- .coveralls.yml | 2 +- lib/carrierwave/webdav/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.coveralls.yml b/.coveralls.yml index b9b942b..380531e 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1 +1 @@ -repo_token: vED8szM0CKiJzSUuQmmbuuWStRxi3wMSV \ No newline at end of file +repo_token: 9Fl9auxZBvbw6mQ2MDCN6HAs0qeBSANwg diff --git a/lib/carrierwave/webdav/version.rb b/lib/carrierwave/webdav/version.rb index 7895265..a084bd2 100644 --- a/lib/carrierwave/webdav/version.rb +++ b/lib/carrierwave/webdav/version.rb @@ -1,5 +1,5 @@ module CarrierWave module WebDAV - VERSION = "0.4.3" + VERSION = "0.5.0" end end From c770c64494b65ae312bd9b67a4a038ad82ceb589 Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Tue, 31 Jan 2017 17:15:06 +0800 Subject: [PATCH 11/15] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5279d1c..2d723d1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # CarrierWave for WebDAV [![Build Status](https://travis-ci.org/qinix/carrierwave-webdav.png?branch=master)](https://travis-ci.org/qinix/carrierwave-webdav) +[![Coverage Status](https://coveralls.io/repos/github/qinix/carrierwave-webdav/badge.svg?branch=master)](https://coveralls.io/github/qinix/carrierwave-webdav?branch=master) This gem adds support for WebDAV to [CarrierWave](https://github.com/carrierwaveuploader/carrierwave/) @@ -57,4 +58,3 @@ them yourself. In Rails for example, you could use the `send_data` method. 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request - From ba7611e6913b0011207b6212b3ea2cc9d82bd42c Mon Sep 17 00:00:00 2001 From: "ian.norris" Date: Wed, 6 Apr 2016 16:16:59 -0700 Subject: [PATCH 12/15] fixing issue where webdav tries to recreate report folders --- lib/carrierwave/httparty_monkey.rb | 10 +++++++++- lib/carrierwave/webdav/file.rb | 32 ++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/carrierwave/httparty_monkey.rb b/lib/carrierwave/httparty_monkey.rb index d9a79b1..ab9956b 100644 --- a/lib/carrierwave/httparty_monkey.rb +++ b/lib/carrierwave/httparty_monkey.rb @@ -7,7 +7,7 @@ module HTTParty class Request - SupportedHTTPMethods << Net::HTTP::Mkcol + SupportedHTTPMethods += [Net::HTTP::Mkcol, Net::HTTP::Propfind] end module ClassMethods @@ -15,6 +15,11 @@ module ClassMethods def mkcol(path, options = {}, &block) perform_request Net::HTTP::Mkcol, path, options, &block end + + def propfind(path, options, &block) + perform_request Net::HTTP::Propfind, path, options, &block + end + end class Basement @@ -24,5 +29,8 @@ class Basement def self.mkcol(*args, &block) Basement.mkcol(*args, &block) end + def self.propfind(*args, &block) + Basement.propfind(*args, &block) + end end # HTTParty diff --git a/lib/carrierwave/webdav/file.rb b/lib/carrierwave/webdav/file.rb index e6a85e3..0fbe1da 100644 --- a/lib/carrierwave/webdav/file.rb +++ b/lib/carrierwave/webdav/file.rb @@ -18,7 +18,6 @@ def initialize(uploader, path) @password = uploader.webdav_password || '' @options = {} @options = { basic_auth: { username: @username, password: @password } } if @username - @create_dirs = !uploader.webdav_autocreates_dirs end def read @@ -38,9 +37,7 @@ def headers end def write(file) - if @create_dirs - res = mkcol - end + mkcol res = HTTParty.put(write_url, options.merge({ body: file })) if res.code != 201 and res.code != 204 @@ -82,7 +79,7 @@ def url alias :file_length :length alias :size :length - private + private def read_url "#{server}/#{path}" @@ -93,18 +90,33 @@ def write_url end def mkcol - dirs = [] - path.split('/')[0...-1].each do |dir| - dirs << "#{dirs[-1]}/#{dir}" - end # Make path like a/b/c/t.txt to array ['/a', '/a/b', '/a/b/c'] + return if dirs_to_create.empty? + use_server = @write_server ? @write_server : server - dirs.each do |dir| + + dirs_to_create.each do |dir| res = HTTParty.mkcol("#{use_server}#{dir}", options) unless [200, 201, 207, 409].include? res.code raise CarrierWave::IntegrityError.new("Can't create a new collection: #{res.inspect}") end end # Make collections recursively end + + def dirs_to_create + dirs = [] + path.split('/')[0...-1].each do |dir| + dirs << "#{dirs[-1]}/#{dir}" + end # Make path like a/b/c/t.txt to array ['/a', '/a/b', '/a/b/c'] + + find_dirs_that_dont_exist dirs + end + + def find_dirs_that_dont_exist(dirs) + dirs.reject do |dir| + res = HTTParty.propfind("#{server}/#{dir}", options) + [200,201,207].include? res.code + end + end end # File end # WebDAV end # CarrierWave From f7efd724ab0e291bf222d9b5e8457c584186fa15 Mon Sep 17 00:00:00 2001 From: Jacob Frautschi Date: Wed, 27 Jul 2016 15:55:46 -0700 Subject: [PATCH 13/15] Fix warning about altering Ruby constant carrierwave-webdav/lib/carrierwave/httparty_monkey.rb:10: warning: already initialized constant HTTParty::Request::SupportedHTTPMethods httparty-0.13.7/lib/httparty/request.rb:3: warning: previous definition of SupportedHTTPMethods was here --- lib/carrierwave/httparty_monkey.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/httparty_monkey.rb b/lib/carrierwave/httparty_monkey.rb index ab9956b..aa72a7f 100644 --- a/lib/carrierwave/httparty_monkey.rb +++ b/lib/carrierwave/httparty_monkey.rb @@ -7,7 +7,7 @@ module HTTParty class Request - SupportedHTTPMethods += [Net::HTTP::Mkcol, Net::HTTP::Propfind] + SupportedHTTPMethods << Net::HTTP::Mkcol << Net::HTTP::Propfind end module ClassMethods From 268a486bef8b9e2b51ae338f642ce51332776df3 Mon Sep 17 00:00:00 2001 From: Jacob Frautschi and Layne McNish Date: Wed, 27 Jul 2016 19:01:54 -0700 Subject: [PATCH 14/15] add '.idea' to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d87d4be..2de3904 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +.idea From 328f18fa4a755e74675f663497f5f77bd6d12e5f Mon Sep 17 00:00:00 2001 From: Jacob Frautschi and Layne McNish Date: Wed, 27 Jul 2016 20:41:30 -0700 Subject: [PATCH 15/15] remove unused config --- lib/carrierwave/webdav.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/carrierwave/webdav.rb b/lib/carrierwave/webdav.rb index 86ed645..6bf299d 100644 --- a/lib/carrierwave/webdav.rb +++ b/lib/carrierwave/webdav.rb @@ -8,7 +8,6 @@ class CarrierWave::Uploader::Base add_config :webdav_password add_config :webdav_server add_config :webdav_write_server - add_config :webdav_autocreates_dirs configure do |config| config.storage_engines[:webdav] = 'CarrierWave::Storage::WebDAV'