[Groonga-commit] groonga/heroku-groonga-builder at 1b7fce4 [build_kytea] Add uploader

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Sep 14 17:37:44 JST 2014


Kouhei Sutou	2014-05-19 22:49:22 +0900 (Mon, 19 May 2014)

  New Revision: 1b7fce4a0802e71cc1f40bc1605fb3ca91303a64
  https://github.com/groonga/heroku-groonga-builder/commit/1b7fce4a0802e71cc1f40bc1605fb3ca91303a64

  Message:
    Add uploader

  Added files:
    .gitignore
    config.ru
  Modified files:
    Gemfile
    Gemfile.lock
    Procfile

  Added: .gitignore (+1 -0) 100644
===================================================================
--- /dev/null
+++ .gitignore    2014-05-19 22:49:22 +0900 (87174b6)
@@ -0,0 +1 @@
+/public/

  Modified: Gemfile (+1 -0)
===================================================================
--- Gemfile    2014-05-19 22:08:26 +0900 (400f309)
+++ Gemfile    2014-05-19 22:49:22 +0900 (c58b030)
@@ -1,3 +1,4 @@
 source "https://rubygems.org/"
 
 gem "rake"
+gem "puma"

  Modified: Gemfile.lock (+5 -1)
===================================================================
--- Gemfile.lock    2014-05-19 22:08:26 +0900 (360a764)
+++ Gemfile.lock    2014-05-19 22:49:22 +0900 (f99cee0)
@@ -1,10 +1,14 @@
 GEM
   remote: https://rubygems.org/
   specs:
-    rake (10.3.1)
+    puma (2.8.2)
+      rack (>= 1.1, < 2.0)
+    rack (1.5.2)
+    rake (10.3.2)
 
 PLATFORMS
   ruby
 
 DEPENDENCIES
+  puma
   rake

  Modified: Procfile (+1 -1)
===================================================================
--- Procfile    2014-05-19 22:08:26 +0900 (57e928a)
+++ Procfile    2014-05-19 22:49:22 +0900 (449ff97)
@@ -1 +1 @@
-web: bundle exec ruby -run -e httpd -- --port=$PORT --do-not-reverse-lookup .
+web: bundle exec puma --port $PORT config.ru

  Added: config.ru (+81 -0) 100644
===================================================================
--- /dev/null
+++ config.ru    2014-05-19 22:49:22 +0900 (7390c28)
@@ -0,0 +1,81 @@
+# -*- 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****@reque*****?
+    validation_error("must be PUT\n")
+  end
+
+  def validate_path
+    return unles****@reque*****_with?("/")
+    validation_error("must be file name\n")
+  end
+
+  def validate_content
+    return if****@reque*****
+    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****@reque*****(buffer_size, buffer)
+        output.write(buffer)
+      end
+    end
+
+    @response.write("Uploaded\n")
+  end
+end
+
+file_server = Rack::File.new("public")
+
+application = lambda do |env|
+  request = Rack::Request.new(env)
+  response = Rack::Response.new
+  if request.get?
+    file_server.call(env)
+  else
+    uploader = Uploader.new(request, response)
+    uploader.run
+  end
+end
+run application
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index