# load bundled gems and std lib stuff
require 'rubygems'
require 'csv'
require 'bundler/setup'
Bundler.require

# load our models and schemas
require './logbook'
Dir[File.join(File.dirname(__FILE__), 'schema', '*.rb')].each { |file| require file }

get '/?:logbook_file?' do |logbook_file|
  logbook_file ||= 'data/logbook.csv'
  logbook = Logbook.new(logbook_file)

  data = {
    flights: logbook.flight_data,
    metadata: {
      application: "logflow",
      version: "0.1"
    }.merge(logbook.metadata)
  }

  <<-HTML
    <a href="logten://addFlights/#{URI.escape(JSON.generate(data))}">Import flight data:</a>
    <pre>#{JSON.pretty_generate(data)}</pre>
  HTML
end

# load bundled gems and std lib stuff
require 'rubygems'
require 'csv'
require 'bundler/setup'
Bundler.require

# load our models and schemas
require './logbook'
Dir[File.join(File.dirname(__FILE__), 'schema', '*.rb')].each { |file| require file }

get '/' do
  logbook_file = ENV['LOGBOOK_CSV'] || 'data/logbook.csv'
  logbook = Logbook.new(logbook_file)

  data = {
    flights: logbook.flight_data,
    metadata: {
      application: "logflow",
      version: "0.1"
    }.merge(logbook.metadata)
  }

  <<-HTML
    <a href="logten://addFlights/#{URI.escape(JSON.generate(data))}">Import flight data:</a>
    <pre>#{JSON.pretty_generate(data)}</pre>
  HTML
end

Revert "Allow passing the logbook file path/name as an URL param."
Revert "Allow passing the logbook file path/name as an URL param."

Decided to undo this. It's a security risk if future people come across this and unknowingly run this as publicly accessible (would allow reading of arbitrary files on the file system via URL param). I don't think it provides enough additional convenience to be worth the risk.

This reverts commit bcb6d786544b44ab34c0392453dd0c9c9fd53f05.
