class Deploy
Attributes
access_key_id[R]
access_key_secret[R]
bucket_name[R]
endpoint[R]
expired_in[R]
skip_exist[R]
Public Class Methods
new(params = {})
click to toggle source
# File lib/oss/deploy.rb, line 9 def initialize(params = {}) @access_key_id = params["OSS_ID"] @access_key_secret = params["OSS_SECRET"] @endpoint = params["endpoint"] @bucket_name = params["bucket_name"] @expired_in = params["expired_in"] || 365 @skip_exist = params["skip_exist"] end
Public Instance Methods
bucket()
click to toggle source
# File lib/oss/deploy.rb, line 26 def bucket @bucket ||= client.get_bucket(bucket_name) end
cache_control()
click to toggle source
# File lib/oss/deploy.rb, line 73 def cache_control max_age = expired_in.to_i * 24 * 60 * 60 "max-age=" + max_age.to_s end
client()
click to toggle source
# File lib/oss/deploy.rb, line 18 def client @client ||= Aliyun::OSS::Client.new( endpoint: endpoint, access_key_id: access_key_id, access_key_secret: access_key_secret ) end
expires()
click to toggle source
# File lib/oss/deploy.rb, line 78 def expires expire_date = Date.today + expired_in.to_i expire_date.to_time.getgm end
local_objects(paths)
click to toggle source
# File lib/oss/deploy.rb, line 39 def local_objects(paths) files = [] paths.each do |path| if File.file?(path) files << path elsif File.directory?(path) Find.find(path) do |file| files << file if File.file?(file) end end end files.compact end
objects()
click to toggle source
文件列表
# File lib/oss/deploy.rb, line 31 def objects bucket.list_objects end
remote_objects()
click to toggle source
# File lib/oss/deploy.rb, line 35 def remote_objects objects.map(&:key) end
upload(paths, remote_path)
click to toggle source
# File lib/oss/deploy.rb, line 53 def upload(paths, remote_path) objects = local_objects(paths) objects.each do |object| remote = remote_path.call(object) if skip_exist and remote_objects.include?(remote) Jekyll.logger.info "Skip exist file: #{remote}" next end Jekyll.logger.info "Upload file: #{remote}" bucket.put_object( remote, :file => object, :headers => { "Cache-Control": cache_control, "Expires": expires } ) end end