Module: Fiona7::BinaryHandling::DeliveryMixin

Included in:
EmbeddedServer::BinaryServerlet::RequestHandler, Fiona7::BlobsController
Defined in:
lib/fiona7/scrivito_patches/binary.rb

Instance Method Summary collapse

Instance Method Details

#queryObject

HEAD



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/fiona7/scrivito_patches/binary.rb', line 297

def query
  binary_id      = binary_id_from_params
  transformation = transformation_from_params
  meta_binary    = BinaryHandling::MetaBinary.new(binary_id, transformation)

  if !meta_binary.valid?
    bad_request
  elsif !meta_binary.present?
    not_found
  else
    simple_set_header('Content-Type', meta_binary.mime_type)
    simple_set_header('Content-Length', meta_binary.length)
    simple_set_header('Cache-Control', 'no-transform,public,max-age=300,s-maxage=900')
    head_ok
  end
end

#showObject

GET



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/fiona7/scrivito_patches/binary.rb', line 268

def show
  binary_id      = binary_id_from_params
  transformation = transformation_from_params
  meta_binary    = MetaBinary.new(binary_id, transformation)

  if !meta_binary.present?
    if Fiona7.mode == :standalone &&
       (current_binary = get_current_binary_url(binary_id))
      Rails.logger.info("Redirect to #{current_binary}")
      redirect_to current_binary, status: 301
    else
      not_found
    end
  elsif !meta_binary.valid?
    bad_request
  elsif stale?(:last_modified => meta_binary.last_changed) && true
    filename = meta_binary.filename
    filepath = meta_binary.filepath
    mime_type = meta_binary.mime_type

    send_file(File.expand_path(filepath), {
      :type => mime_type,
      :filename => filename,
      :disposition => 'inline'
    })
  end
end