Sha256: 30f789e905a3d2179f6def5dd8fc6d2cf39a3243a680b7939ad2cac39894763b

Contents?: true

Size: 782 Bytes

Versions: 4

Compression:

Stored size: 782 Bytes

Contents

require 'sinatra'
module Stan
  class Server < Sinatra::Base
    set :bind, ENV.fetch('STAN_BIND')
    set :port, ENV.fetch('STAN_PORT')

    upload_dir = ENV.fetch('STAN_UPLOAD_DIR')
    public_dir = ENV.fetch('STAN_PUBLIC_DIR')
    post '/upload' do
      name = params['name']
      filename = params['file']['filename']
      tempfile = params['file']['tempfile']
      FileUtils.mkdir_p(upload_dir)
      filepath = "#{upload_dir}/#{filename}"
      while blk = tempfile.read(65536)
        File.open(filepath, 'wb') do |f|
          f.write(blk)
        end
      end
      FileUtils.mkdir_p("#{public_dir}/#{name}")
      Dir.chdir("#{public_dir}/#{name}") do
        `tar -xzf #{filepath} .`
      end
      FileUtils.rm(filepath)
      "Upload complete"
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stan-0.2.3 lib/stan/server.rb
stan-0.2.2 lib/stan/server.rb
stan-0.2.1 lib/stan/server.rb
stan-0.2.0 lib/stan/server.rb