lib/carrierwave/storage/aliyun_file.rb in carrierwave-aliyun-0.9.0 vs lib/carrierwave/storage/aliyun_file.rb in carrierwave-aliyun-1.0.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module CarrierWave module Storage class AliyunFile < CarrierWave::SanitizedFile attr_reader :path @@ -8,13 +10,13 @@ @path = URI.encode(path) @base = base end def read - res = bucket.get(@path) - @headers = res.headers.deep_transform_keys { |k| k.underscore.to_sym rescue key } - res.body + object, body = bucket.get(@path) + @headers = object.headers + body end def delete bucket.delete(@path) true @@ -28,19 +30,19 @@ # Generate file url # params # :thumb - Aliyun OSS Image Processor option, etc: @100w_200h_95q # def url(opts = {}) - if @uploader.aliyun_private_read + if bucket.mode == :private bucket.private_get_url(@path, opts) else bucket.path_to_url(@path, opts) end end def content_type - headers[:content_type].first + headers[:content_type] end def content_type=(new_content_type) headers[:content_type] = new_content_type end @@ -53,13 +55,13 @@ @headers ||= {} end private - def bucket - return @bucket if defined? @bucket + def bucket + return @bucket if defined? @bucket - @bucket = CarrierWave::Aliyun::Bucket.new(@uploader) - end + @bucket = CarrierWave::Aliyun::Bucket.new(@uploader) + end end end end