Navigation Menu

Skip to content

Commit

Permalink
Remove upload feature
Browse files Browse the repository at this point in the history
It is no longer needed.
  • Loading branch information
kou committed Jun 5, 2014
1 parent 17eaddd commit 349f3fa
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 87 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -2,4 +2,3 @@ source "https://rubygems.org/"

gem "rake"
gem "octokit"
gem "puma"
4 changes: 0 additions & 4 deletions Gemfile.lock
Expand Up @@ -7,9 +7,6 @@ GEM
multipart-post (2.0.0)
octokit (3.1.0)
sawyer (~> 0.5.3)
puma (2.8.2)
rack (>= 1.1, < 2.0)
rack (1.5.2)
rake (10.3.2)
sawyer (0.5.4)
addressable (~> 2.3.5)
Expand All @@ -20,5 +17,4 @@ PLATFORMS

DEPENDENCIES
octokit
puma
rake
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

82 changes: 1 addition & 81 deletions config.ru
@@ -1,86 +1,6 @@
# -*- ruby -*-

require "fileutils"

class Uploader
class ValidationError < StandardError
end

def initialize(request, response)
@request = request
@response = response
@response["Content-Type"] = "text/plain"
end

def run
begin
validate
rescue ValidationError
else
upload
end

@response.finish
end

private
def validate
validate_method
validate_path
validate_content
end

def validation_error(message)
@response.status = 400
@response.write(message)
raise ValidationError
end

def validate_method
return if @request.put?
validation_error("must be PUT\n")
end

def validate_path
return unless @request.path.end_with?("/")
validation_error("must be file name\n")
end

def validate_content
return if @request.body
validation_error("body is required\n")
end

def upload
path = "public#{@request.path}"
FileUtils.mkdir_p(File.dirname(path))
File.open(path, "wb") do |output|
buffer_size = 8912
buffer = ""
while @request.body.read(buffer_size, buffer)
output.write(buffer)
end
end

@response.write("Uploaded\n")
end
end

file_server = Rack::File.new("public")
directory_server = Rack::Directory.new("public")

application = lambda do |env|
request = Rack::Request.new(env)
response = Rack::Response.new
if request.get?
if request.path.end_with?("/")
directory_server.call(env)
else
file_server.call(env)
end
else
uploader = Uploader.new(request, response)
uploader.run
end
[200, {"Content-Type" => "text/plain"}, ["Groonga builder"]]
end
run application

0 comments on commit 349f3fa

Please sign in to comment.