class ActiveStorage::Service::WebDAVService
Public Class Methods
new(args)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 7 def initialize(args) @path = args[:url] return @webdav = args[:net_dav] if args[:net_dav] @webdav = Net::DAV.new args[:url] end
Public Instance Methods
delete(key)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 48 def delete(key) instrument :delete, key: key do begin @webdav.delete path_for key rescue StandardError # Ignore files already deleted end end end
delete_prefixed(prefix)
click to toggle source
Delete files at keys starting with the prefix
.
# File lib/active_storage/service/web_dav_service.rb, line 59 def delete_prefixed(prefix) instrument :delete_prefixed, prefix: prefix do files = prefixed_filenames prefix files.each do |filename| url = path_for filename @webdav.delete url end end end
download(key, &block)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 69 def download(key, &block) full_path = path_for key if block_given? instrument :streaming_download, key: key do @webdav.get(full_path, &block) end else instrument :download, key: key do @webdav.get(full_path) end end end
download_chunk(key, range)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 82 def download_chunk(key, range) instrument :download_chunk, key: key, range: range do range_end = range.exclude_end? ? range.end - 1 : range.end range_for_dav = "bytes=#{range.begin}-#{range_end}" full_path = path_for key @webdav.get(full_path, 'Range' => range_for_dav) end end
exist?(key)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 40 def exist?(key) instrument :exist, key: key do |payload| answer = @webdav.exists? path_for key payload[:exist] = answer answer end end
upload(key, io, checksum: nil, **)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 13 def upload(key, io, checksum: nil, **) instrument :upload, key: key, checksum: checksum do begin full_path = path_for key answer = @webdav.put(full_path, io, File.size(io)) rescue StandardError raise ActiveStorage::IntegrityError end end end
url(key, expires_in:, disposition:, filename:, content_type:)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 24 def url(key, expires_in:, disposition:, filename:, content_type:) instrument :url, key: key do |payload| full_path = path_for key payload[:url] = full_path full_path end end
url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 32 def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:) instrument :url, key: key do |payload| full_path = path_for key payload[:url] = full_path full_path end end
Private Instance Methods
path_for(key)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 109 def path_for(key) return key unless @path URI.join(@path, key) end
prefixed_filenames(prefix)
click to toggle source
# File lib/active_storage/service/web_dav_service.rb, line 94 def prefixed_filenames(prefix) options = <<XML <?xml version="1.0"?> <a:propfind xmlns:a="DAV:"> <a:prop><a:resourcetype/></a:prop> </a:propfind> XML answer = @webdav.propfind(@path, options) answer.xpath('//D:href').select do |href| href = href.to_s.sub('<D:href>', '').sub('</D:href>', '').split('/').last href if href.scan(prefix).size > 0 end end