lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-1.6.1.1.1 vs lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-1.6.1.1.5

- old
+ new

@@ -269,11 +269,17 @@ binary_id = binary_id_from_params transformation = transformation_from_params meta_binary = MetaBinary.new(binary_id, transformation) if !meta_binary.present? - not_found + 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 @@ -314,9 +320,21 @@ head 404 end def head_ok head 200 + end + + def get_current_binary_url(binary_id) + current_binary_url = nil + blob_obj = Fiona7::WriteObj.find(binary_id.to_i) rescue nil + if blob_obj + binary_obj = blob_obj.parent.parent rescue nil + if binary_obj + current_binary_url = Obj.find(binary_obj.obj_id).blob.url rescue nil + end + end + current_binary_url end end class EmbeddedServer