Class: Balloon::Storage::Upyun

Inherits:
Store
  • Object
show all
Defined in:
lib/balloon/storage/upyun.rb

Instance Method Summary collapse

Methods inherited from Store

basic_auth, conn_option, #connection, get_basic_auth, get_option, #initialize, #set_upload_name, #store_name, token_auth, #upload_dir, #upload_file

Constructor Details

This class inherits a constructor from Balloon::Storage::Store

Instance Method Details

#delete!Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/balloon/storage/upyun.rb', line 52

def delete!
  _store_path = store_path
  store_original_file = ::File.join _store_path, store_filename
  response = connection.delete(store_original_file)
  if !@uploader.upyun_is_image && @uploader.respond_to?(:uploader_size)
    @uploader.uploader_size.each do |s, o|
      store_file = ::File.join _store_path, store_filename(s)
      connection.delete(store_file)
    end
  end
end

#retrieve!(size_name = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/balloon/storage/upyun.rb', line 41

def retrieve!(size_name = nil)
  if !@uploader.upyun_is_image || size_name.nil?
    path = ::File.join upload_dir, store_filename(size_name)
    @uploader.upyun_domain + "/" + path
  else
    filename = store_filename + @uploader.upyun_thumb_symbol + size_name.to_s
    path = ::File.join upload_dir, filename
    @uploader.upyun_domain + "/" + path
  end
end

#store!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/balloon/storage/upyun.rb', line 17

def store!
  _store_path = store_path
  cache_meta = @uploader.cache_meta
  original_file = set_upload_name

  store_original_file = ::File.join _store_path, original_file       
  cache_original_file = ::File.join @uploader.cache_path, cache_meta[:filename]
  file = ::File.new cache_original_file
  response = connection.put(store_original_file, file.read, file.size)
  raise "Connection errors" if response.nil?

  if !@uploader.upyun_is_image && @uploader.respond_to?(:uploader_size)
    @uploader.uploader_size.each do |s, o|
      store_file = ::File.join _store_path, set_upload_name(s)
      cache_file = ::File.join @uploader.cache_path, cache_meta[:basename]+ "_#{s}"+"."+ cache_meta[:extension]
      file = ::File.new cache_file
      connection.put(store_file, file.read, file.size)
    end
  end

  FileUtils.remove_dir(@uploader.cache_path)
  return { filename: original_file, basename: store_name }
end