Class: CarrierWave::Storage::Aliyun

Inherits:
Abstract
  • Object
show all
Defined in:
lib/carrierwave/storage/aliyun.rb

Instance Method Summary collapse

Instance Method Details

#cache!(new_file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/carrierwave/storage/aliyun.rb', line 21

def cache!(new_file)
  f = AliyunFile.new(uploader, self, uploader.cache_path)
  headers = {
    content_type: new_file.content_type,
    content_disposition: uploader.try(:content_disposition)
  }

  f.store(new_file, headers)
  f
end

#clean_cache!(_seconds) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/carrierwave/storage/aliyun.rb', line 40

def clean_cache!(_seconds)
  will_remove_keys = []
  bucket.list_objects(prefix: uploader.cache_path).each do |file|
    next unless file.is_a?(Object)
    time = file.key.scan(/(\d+)-\d+-\d+(?:-\d+)?/).first.map { |t| t.to_i }
    time = Time.at(*time)
    will_remove_keys << item.key if time < (Time.now.utc - seconds)
  end
  bucket.batch_delete_objects(will_remove_keys)
end

#delete_dir!(path) ⇒ Object



36
37
38
# File 'lib/carrierwave/storage/aliyun.rb', line 36

def delete_dir!(path)
  # do nothing, because there's no such things as 'empty directory'
end

#retrieve!(identifier) ⇒ Object



17
18
19
# File 'lib/carrierwave/storage/aliyun.rb', line 17

def retrieve!(identifier)
  AliyunFile.new(uploader, self, uploader.store_path(identifier))
end

#retrieve_from_cache!(identifier) ⇒ Object



32
33
34
# File 'lib/carrierwave/storage/aliyun.rb', line 32

def retrieve_from_cache!(identifier)
  AliyunFile.new(uploader, self, uploader.cache_path(identifier))
end

#store!(new_file) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/carrierwave/storage/aliyun.rb', line 6

def store!(new_file)
  f = AliyunFile.new(uploader, self, uploader.store_path)
  headers = {
    content_type: new_file.content_type,
    content_disposition: uploader.try(:content_disposition)
  }

  f.store(new_file, headers)
  f
end