Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is no longer needed.
- Loading branch information
Showing
4 changed files
with
1 addition
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,3 @@ source "https://rubygems.org/" | |
|
|
||
| gem "rake" | ||
| gem "octokit" | ||
| gem "puma" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |