From 347dc166324c108b4a9c25c5ab03222a2f42b1d0 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 23 Jul 2017 13:19:32 -0500 Subject: VerifiedKeyWithExpiration no longer needed Thanks to rails/rails#29854! This does mean that we now depend on rails/rails master. --- app/models/active_storage/service/disk_service.rb | 3 +-- .../active_storage/verified_key_with_expiration.rb | 22 ---------------------- 2 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 app/models/active_storage/verified_key_with_expiration.rb (limited to 'app/models/active_storage') diff --git a/app/models/active_storage/service/disk_service.rb b/app/models/active_storage/service/disk_service.rb index 905f41c138..c7c45e2146 100644 --- a/app/models/active_storage/service/disk_service.rb +++ b/app/models/active_storage/service/disk_service.rb @@ -2,7 +2,6 @@ require "fileutils" require "pathname" require "digest/md5" require "active_support/core_ext/numeric/bytes" -require "active_storage/verified_key_with_expiration" class ActiveStorage::Service::DiskService < ActiveStorage::Service attr_reader :root @@ -54,7 +53,7 @@ class ActiveStorage::Service::DiskService < ActiveStorage::Service def url(key, expires_in:, disposition:, filename:) instrument :url, key do |payload| - verified_key_with_expiration = ActiveStorage::VerifiedKeyWithExpiration.encode(key, expires_in: expires_in) + verified_key_with_expiration = ActiveStorage.verifier.generate(key, expires_in: expires_in) generated_url = if defined?(Rails) && defined?(Rails.application) diff --git a/app/models/active_storage/verified_key_with_expiration.rb b/app/models/active_storage/verified_key_with_expiration.rb deleted file mode 100644 index 5cb07c6988..0000000000 --- a/app/models/active_storage/verified_key_with_expiration.rb +++ /dev/null @@ -1,22 +0,0 @@ -class ActiveStorage::VerifiedKeyWithExpiration - class << self - def encode(key, expires_in: nil) - ActiveStorage.verifier.generate([ key, expires_at(expires_in) ]) - end - - def decode(encoded_key) - key, expires_at = ActiveStorage.verifier.verified(encoded_key) - - key if key && fresh?(expires_at) - end - - private - def expires_at(expires_in) - expires_in ? Time.now.utc.advance(seconds: expires_in) : nil - end - - def fresh?(expires_at) - expires_at.nil? || Time.now.utc < expires_at - end - end -end -- cgit v1.2.3