require 'fiona7/builder/lazy_blob_copier' module Fiona7 module Controllers module RestAPI class BlobController def fetch(blob_id, transformation=false) public_get_url = BinaryHandling::UrlGenerator.new(blob_id, 'public_access', 'get', transformation).generate # all URLs are identical! # private_get_url = BinaryHandling::UrlGenerator.new(blob_id, 'private_access', 'get', false).generate # public_head_url = BinaryHandling::UrlGenerator.new(blob_id, 'public_access', 'head', false).generate # private_head_url = BinaryHandling::UrlGenerator.new(blob_id, 'private_access', 'head', false).generate private_head_url = public_head_url = private_get_url = public_get_url return { 'public_access' => { 'get' => { 'url' => public_get_url }, 'head' => { 'url' => public_head_url } }, 'private_access' => { 'get' => { 'url' => private_get_url }, 'head' => { 'url' => private_head_url } } } end def metadata(blob_id) meta_binary = BinaryHandling::MetaBinary.new(blob_id) content_type = meta_binary.mime_type content_length = meta_binary.length if meta_binary.image? width = meta_binary.width height = meta_binary.height else width = 0 height = 0 end { 'meta_data' => { 'content_type' => ['string', content_type], 'content_length' => ['number', content_length], 'width' => ['number', width], 'height' => ['number', height] } } end def copy(blob_id, params) input = params.symbolize_keys blob_id = blob_id destination_obj_id = input[:destination_obj_id] filename = input[:filename] content_type = input[:content_type] destination_obj = Fiona7::WriteObj.find(destination_obj_id) destination_obj.reload_attributes binary_spec = Fiona7::Builder::LazyBlobCopier.new({ destination_obj: destination_obj, source_blob_id: blob_id, filename: filename, content_type: content_type }).call.stringify_keys destination_obj.save! return binary_spec end end end end end