Mercurial > zeropaste
changeset 226:fb9909885d63
Also support plain gzip
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 13 May 2013 13:19:33 +0900 |
parents | 9998d8b6c524 |
children | c2a76a901e61 |
files | app/controllers/pastes_controller.rb |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
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))