# encoding: utf-8
require "json"
require "pebblebed/sinatra"

Dir.glob("#{File.dirname(__FILE__)}/v1/**/*.rb").each { |file| require file }

class TiramisuV1 < Sinatra::Base
  set :root, "#{File.dirname(__FILE__)}/v1"

  register Sinatra::Pebblebed

  set :config, Tiramisu.config

  helpers do

    def asset_store
      Thread.current[:asset_store] ||= AssetStore.new(settings.config['S3'])
    end

    def stream_file(&block)
      stream do |out|
        out << " " * 256 if request.user_agent =~ /MSIE/ # ie need ~ 250 k of prelude before it starts flushing the response buffer
        progress = Progress.new(out)
        yield(progress)
        #IE strips off whitespace at the end of an iframe
        #so we need to send a terminator
        out << ";" if request.user_agent =~ /MSIE/ # Damn you, IE...
      end
    end

  end

  def ensure_file
    # Firefox sends empty string ""
    # Safari and Opera sends "undefined"
    raise MissingUploadedFileError if params[:file].nil? || params[:file] == '' || params[:file] == 'undefined'
  end
end

# encoding: utf-8
require "json"
require "pebblebed/sinatra"

Dir.glob("#{File.dirname(__FILE__)}/v1/**/*.rb").each { |file| require file }

class TiramisuV1 < Sinatra::Base
  set :root, "#{File.dirname(__FILE__)}/v1"

  register Sinatra::Pebblebed

  set :config, Tiramisu.config

  before do
    cache_control :private, :no_cache, :no_store, :must_revalidate
  end

  helpers do

    def asset_store
      Thread.current[:asset_store] ||= AssetStore.new(settings.config['S3'])
    end

    def stream_file(&block)
      stream do |out|
        out << " " * 256 if request.user_agent =~ /MSIE/ # ie need ~ 250 k of prelude before it starts flushing the response buffer
        progress = Progress.new(out)
        yield(progress)
        #IE strips off whitespace at the end of an iframe
        #so we need to send a terminator
        out << ";" if request.user_agent =~ /MSIE/ # Damn you, IE...
      end
    end

  end

  def ensure_file
    # Firefox sends empty string ""
    # Safari and Opera sends "undefined"
    raise MissingUploadedFileError if params[:file].nil? || params[:file] == '' || params[:file] == 'undefined'
  end
end

Add no-cache header to prevent Safari on IOS6 from caching POST requests (sic!)
Add no-cache header to prevent Safari on IOS6 from caching POST requests (sic!)
