# HG changeset patch # User edogawaconan # Date 1396707805 -32400 # Node ID 61f7f258a6fb0af30509c03fd922addcd0afb927 # Parent 325fcf388442a3dadc4fa48c0df83f46a381b6a0 Move from-gzip paste parsing to model. diff -r 325fcf388442 -r 61f7f258a6fb app/controllers/pastes_controller.rb --- a/app/controllers/pastes_controller.rb Sat Apr 05 23:20:32 2014 +0900 +++ b/app/controllers/pastes_controller.rb Sat Apr 05 23:23:25 2014 +0900 @@ -29,16 +29,6 @@ # POST /pastes.json # POST /pastes.txt def create - 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)) begin @@ -77,6 +67,6 @@ private def paste_params - params.require(:paste).permit(:paste, :is_private, :key) + params.require(:paste).permit(:paste, :paste_gzip, :paste_gzip_base64, :is_private, :key) end end diff -r 325fcf388442 -r 61f7f258a6fb app/models/paste.rb --- a/app/models/paste.rb Sat Apr 05 23:20:32 2014 +0900 +++ b/app/models/paste.rb Sat Apr 05 23:23:25 2014 +0900 @@ -22,6 +22,14 @@ end end + def paste_gzip=(paste) + self.paste = ActiveSupport::Gzip.decompress paste + end + + def paste_gzip_base64=(paste) + self.paste_gzip = Base64.decode64(paste) + end + def safe_destroy(param_key) if key == param_key destroy