diff app/controllers/pastes_controller.rb @ 226:fb9909885d63

Also support plain gzip
author Edho Arief <edho@myconan.net>
date Mon, 13 May 2013 13:19:33 +0900
parents 9998d8b6c524
children 388504e43bcf
line wrap: on
line diff
--- a/app/controllers/pastes_controller.rb	Mon May 13 13:19:13 2013 +0900
+++ b/app/controllers/pastes_controller.rb	Mon May 13 13:19:33 2013 +0900
@@ -31,11 +31,15 @@
   # POST /pastes.json
   # POST /pastes.txt
   def create
-    if params[:paste] && params[:paste][:paste_gzip_base64]
-      # 1. decode from base64
-      # 2. create StringIO from decoded string
-      # 3. unzip and read the stream
-      params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste].delete(:paste_gzip_base64)))).read
+    if params[:paste].is_a? Hash
+      if params[:paste][:paste_gzip_base64]
+        # 1. decode from base64
+        # 2. create StringIO from decoded string
+        # 3. unzip and read the stream
+        params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste].delete(:paste_gzip_base64)))).read
+      elsif params[:paste][:paste_gzip]
+        params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(params[:paste].delete(:paste_gzip))).read
+      end
     end
     @paste = Paste.new(paste_params.merge(ip: request.remote_ip))