Sha256: 7fc2f192ff9e86d4af4d3c0ea8ee45ed46e24876fb02589ac48a5960f0f11a35
Contents?: true
Size: 1.52 KB
Versions: 1
Compression:
Stored size: 1.52 KB
Contents
require 'nft/client' module ActiveStorage class Service::NftService < Service attr_accessor :client def initialize(api_key:, gateway_endpoint:) @client = Nft::Client.new api_key, gateway_endpoint end # File is uploaded to NFT.storage and a hash # is returned which is used to retrieve the file # Change the key of the blob to that of the hash def upload(key, io, checksum: nil, **) instrument :upload, key: key, checksum: checksum do cid_key = @client.add io.path Blob.find_by_key(key).update key: cid_key end end def download(key, &block) if block_given? instrument :streaming_download, key: key do @client.download key, &block end else instrument :download, key: key do @client.download key end end end def download_chunk(key, range) instrument :download_chunk, key: key, range: range do @client.cat key, range.begin, range.size end end def url(key, content_type: nil, filename: nil, expires_in: nil, disposition: nil) instrument :url, key: key do @client.build_file_url key, filename.to_s end end def exists?(key) instrument :exist, key: key do @client.file_exists?(key) end end def url_for_direct_upload(key, expires_in: nil, content_type: nil, content_length: nil, checksum: nil) instrument :url_for_direct_upload, key: key do "#{@client.api_endpoint}/api/v0/add" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activestorage-nft-0.0.2 | lib/active_storage/service/nft_service.rb |