diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-23 11:05:20 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-23 11:05:20 -0500 |
commit | 46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea (patch) | |
tree | bc19d2f900055e39de21f62ec27e9079723cfa5f /app/models | |
parent | 8f20624820ed0922b33fceb4013d3ff11015b366 (diff) | |
download | rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.tar.gz rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.tar.bz2 rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.zip |
Switch to simpler signed_id for blob rather than full GlobalID
We don't need to lookup multiple different classes, so no need to use a globalid.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/active_storage/blob.rb | 9 | ||||
-rw-r--r-- | app/models/active_storage/service/disk_service.rb | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/app/models/active_storage/blob.rb b/app/models/active_storage/blob.rb index 6bd3941cd8..7b45d3ad25 100644 --- a/app/models/active_storage/blob.rb +++ b/app/models/active_storage/blob.rb @@ -2,6 +2,7 @@ require "active_storage/service" require "active_storage/filename" require "active_storage/purge_job" require "active_storage/variant" +require "active_storage/variation" # Schema: id, key, filename, content_type, metadata, byte_size, checksum, created_at class ActiveStorage::Blob < ActiveRecord::Base @@ -13,6 +14,10 @@ class ActiveStorage::Blob < ActiveRecord::Base class_attribute :service class << self + def find_signed(id) + find ActiveStorage.verifier.verify(id) + end + def build_after_upload(io:, filename:, content_type: nil, metadata: nil) new.tap do |blob| blob.filename = filename @@ -33,6 +38,10 @@ class ActiveStorage::Blob < ActiveRecord::Base end + def signed_id + ActiveStorage.verifier.generate(id) + end + def key # We can't wait until the record is first saved to have a key for it self[:key] ||= self.class.generate_unique_secure_token diff --git a/app/models/active_storage/service/disk_service.rb b/app/models/active_storage/service/disk_service.rb index a2a27528c1..905f41c138 100644 --- a/app/models/active_storage/service/disk_service.rb +++ b/app/models/active_storage/service/disk_service.rb @@ -2,6 +2,7 @@ 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 |