Class: Service::ImageKitIoService
- Inherits:
-
Service
- Object
- Service
- Service::ImageKitIoService
- Includes:
- ImageKitIo::Constantable
- Defined in:
- lib/active_storage/service/image_kit_io_service.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #delete_prefixed(prefix) ⇒ Object
- #download(key, &block) ⇒ Object
- #download_chunk(key, range) ⇒ Object
- #exist?(key) ⇒ Boolean
- #headers_for_direct_upload(key, content_type:, checksum:, **options) ⇒ Object
-
#initialize(**options) ⇒ ImageKitIoService
constructor
A new instance of ImageKitIoService.
- #open(*args, **options, &block) ⇒ Object
- #path_for(key) ⇒ Object
- #upload(key, io, checksum: nil, **options) ⇒ Object
- #url(key, filename: nil, content_type: '', **options) ⇒ Object
- #url_for_direct_upload(key, **options) ⇒ Object
Methods included from ImageKitIo::Constantable
Constructor Details
#initialize(**options) ⇒ ImageKitIoService
Returns a new instance of ImageKitIoService.
67 68 69 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 67 def initialize(**) @options = end |
Class Method Details
.delete_ik_file(blob) ⇒ Object
54 55 56 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 54 def delete_ik_file(blob) ik_file(blob).delete end |
.ik_file(blob) ⇒ Object
62 63 64 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 62 def ik_file(blob) self.new.send(:ik_file).new(blob.) end |
.remote_file(blob) ⇒ Object
58 59 60 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 58 def remote_file(blob) ik_file(blob) end |
Instance Method Details
#delete(key) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 97 def delete(key) instrument :delete, key: key do # image kit file is already deleted on before blob destroy callback key end end |
#delete_prefixed(prefix) ⇒ Object
104 105 106 107 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 104 def delete_prefixed(prefix) # delete the variants files puts 'Not implemented delete_prefixed' end |
#download(key, &block) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 81 def download(key, &block) if block_given? instrument :stream_file, key: key do stream_file(key, &block) end else instrument :download, key: key do image_kit_file(key) end end end |
#download_chunk(key, range) ⇒ Object
93 94 95 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 93 def download_chunk(key, range) puts 'Not implemented download_chunk' end |
#exist?(key) ⇒ Boolean
109 110 111 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 109 def exist?(key) image_kit_file(key).exist? end |
#headers_for_direct_upload(key, content_type:, checksum:, **options) ⇒ Object
124 125 126 127 128 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 124 def headers_for_direct_upload(key, content_type:, checksum:, **) { 'Content-Type' => content_type } end |
#open(*args, **options, &block) ⇒ Object
138 139 140 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 138 def open(*args, **, &block) DownloaderExtension.new(self).open(*args, **, &block) end |
#path_for(key) ⇒ Object
130 131 132 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 130 def path_for(key) image_kit_file(key).path end |
#upload(key, io, checksum: nil, **options) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 71 def upload(key, io, checksum: nil, **) instrument :upload, key: key, checksum: checksum do blob = storage_blob(key) response = client.upload_file(file: io, file_name: blob.filename.to_s) if response[:error].nil? blob.update_columns(metadata: response[:response].transform_keys(&:to_sym)) end end end |
#url(key, filename: nil, content_type: '', **options) ⇒ Object
134 135 136 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 134 def url(key, filename: nil, content_type: '', **) image_kit_file(key).url end |
#url_for_direct_upload(key, **options) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_storage/service/image_kit_io_service.rb', line 113 def url_for_direct_upload(key, **) instrument :url, key: key do |payload| .delete(:content_length) .delete(:checksum) url = "#{constants.BASE_URL}#{constants.UPLOAD}" generated_url = client.url(src: url) payload[:url] = generated_url generated_url end end |