lib/auto-ali-cdn/oss.rb in 2cdn-0.1.2 vs lib/auto-ali-cdn/oss.rb in 2cdn-0.1.3
- old
+ new
@@ -65,12 +65,12 @@
upload_c = ->(res_path) do
Dir.foreach(res_path) do |name|
next if name =~ /^(\.)|(\.\.)$/
file_path = res_path+"/#{name}"
file_md5 = Digest::MD5.hexdigest(File.read(file_path))
- res_type = res_path.gsub(/^.*\//, '')
- object_key = config.site_resource_path+"/#{res_type}/#{name.gsub(/\./, "-#{file_md5}.")}"
+ suffix = name.split(/\./).last
+ object_key = config.site_resource_path+"/#{res_type}/#{name.gsub(/#{suffix}$/, "-#{file_md5}#{suffix}")}"
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)
@@ -111,11 +111,12 @@
Dir.foreach(res_path) do |name|
next if name =~ /^(\.)|(\.\.)$/
file_path = res_path+"/#{name}"
file_md5 = Digest::MD5.hexdigest(File.read(file_path))
res_type = res_path.gsub(/^.*\//, '')
- object_key = config.site_resource_path+"/#{res_type}/#{name.gsub(/\./, "-#{file_md5}.")}"
+ suffix = name.split(/\./).last
+ object_key = config.site_resource_path+"/#{res_type}/#{name.gsub(/#{suffix}$/, "-#{file_md5}#{suffix}")}"
if bucket.object_exists?(object_key)
replace_res_path.call(config.domain_name+'/'+object_key, res_type+'/'+name)
puts "#{object_key.color(:red)} --> #{"#{res_type}/#{name}".color(:cyan)}"
end
end
@@ -125,6 +126,6 @@
debug_c.call(javascripts_path)
debug_c.call(css_path)
end
end
-end
\ No newline at end of file
+end