lib/paperclip/storage/qiniu.rb in paperclip-qiniu-0.0.1 vs lib/paperclip/storage/qiniu.rb in paperclip-qiniu-0.0.2
- old
+ new
@@ -51,13 +51,20 @@
@queued_for_delete = []
end
def public_url(style = default_style)
init
- res = ::Qiniu::RS.get(bucket, path(style))
- return res["url"] if res
- nil
+ if @options[:qiniu_host]
+ "#{dynamic_fog_host_for_style(style)}/#{path(style)}"
+ else
+ res = ::Qiniu::RS.get(bucket, path(style))
+ if res
+ res["url"]
+ else
+ nil
+ end
+ end
end
private
def init
@@ -73,14 +80,21 @@
:key => path,
:bucket => bucket,
:mime_type => file.content_type,
:enable_crc32_check => true}
::Qiniu::RS.upload opts
- log ::Qiniu::RS.get(bucket, path)
end
def bucket
@options[:bucket] || raise("bucket is nil")
+ end
+
+ def dynamic_fog_host_for_style(style)
+ if @options[:qiniu_host].respond_to?(:call)
+ @options[:qiniu_host].call(self)
+ else
+ @options[:qiniu_host]
+ end
end
end
end
end