lib/auto-ali-cdn/oss.rb in 2cdn-0.1.5 vs lib/auto-ali-cdn/oss.rb in 2cdn-0.1.6

- old
+ new

@@ -34,11 +34,11 @@ bucket.put_object(config.site_resource_path+"/javascripts/.start.js") { |stream| stream << "console.log('start from here')" } bucket.put_object(config.site_resource_path+"/css/.start.css") { |stream| stream << "body{padding:0;}" } end #upload local files to server - def self.oss_upload(config_path, app_path) + def self.oss_upload(config_path, app_path,rename=false) config = oss_config(config_path) images_path = app_path+'/images' javascripts_path = app_path+'/javascripts' css_path = app_path+'/css' @@ -67,10 +67,11 @@ next if name =~ /^(\.)|(\.\.)$/ file_path = res_path+"/#{name}" file_md5 = Digest::MD5.hexdigest(File.read(file_path)) res_type = res_path.gsub(/^.*\//, '') suffix = "."+name.split(/\./).last - object_key = config.site_resource_path+"/#{res_type}/#{name.gsub(/#{suffix}$/, "-#{file_md5}#{suffix}")}" + new_name = rename ? name.gsub(/#{suffix}$/, "-#{file_md5}#{suffix}"): name + object_key = config.site_resource_path+"/#{res_type}/#{new_name}" if bucket.object_exists?(object_key) puts "#{name} --> #{object_key}".color(:dimgray) replace_res_path.call(res_type+'/'+name, config.domain_name+'/'+object_key) else bucket.put_object(object_key, :file => file_path)