Sha256: 76d1352a7af90c639032e39f3c6fcfa78e0b615f528afca9ca724b32dcf4070f

Contents?: true

Size: 697 Bytes

Versions: 23

Compression:

Stored size: 697 Bytes

Contents

class SingleUseLink < ActiveRecord::Base

  attr_accessible :downloadKey, :expires, :itemId, :path

    
  
  def self.create_show(item_id)
     create_path(item_id, Sufia::Engine.routes.url_helpers.generic_file_path(item_id) )     
  end

  def self.create_download(item_id)
     create_path(item_id, Sufia::Engine.routes.url_helpers.download_path(item_id) )
  end
  
  def expired?
     now = DateTime.now
     return (now > expires)
  end
  
  protected
  def self.create_path(itemId, path)
     expires = DateTime.now.advance(hours:24)
     key = Digest::SHA2.new << DateTime.now.to_f.to_s      
     return create({downloadKey:key.to_s, expires:expires, path:path, itemId:itemId} )
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
sufia-2.0.1 sufia-models/app/models/single_use_link.rb
sufia-models-2.0.1 app/models/single_use_link.rb
sufia-2.0.0 sufia-models/app/models/single_use_link.rb
sufia-models-2.0.0 app/models/single_use_link.rb
sufia-models-0.1.2 app/models/single_use_link.rb
sufia-models-0.1.1 app/models/single_use_link.rb
sufia-1.3.0 app/models/single_use_link.rb
sufia-models-0.1.0 app/models/single_use_link.rb
sufia-models-0.0.2 app/models/single_use_link.rb
sufia-models-0.0.1 app/models/single_use_link.rb
sufia-1.2.0 app/models/single_use_link.rb
sufia-1.1.0 app/models/single_use_link.rb
sufia-1.0.0 app/models/single_use_link.rb
sufia-0.1.0 app/models/single_use_link.rb
sufia-0.0.8 app/models/single_use_link.rb
sufia-0.0.7 app/models/single_use_link.rb
sufia-0.0.6 app/models/single_use_link.rb
sufia-0.0.5 app/models/single_use_link.rb
sufia-0.0.4 app/models/single_use_link.rb
sufia-0.0.3 app/models/single_use_link.rb