comparison app/controllers/pastes_controller.rb @ 316:61f7f258a6fb

Move from-gzip paste parsing to model.
author edogawaconan <me@myconan.net>
date Sat, 05 Apr 2014 23:23:25 +0900
parents 200488650a86
children 612bc7c32324
comparison
equal deleted inserted replaced
315:325fcf388442 316:61f7f258a6fb
27 27
28 # POST / 28 # POST /
29 # POST /pastes.json 29 # POST /pastes.json
30 # POST /pastes.txt 30 # POST /pastes.txt
31 def create 31 def create
32 if params[:paste].is_a? Hash
33 if params[:paste][:paste_gzip_base64]
34 # 1. decode from base64
35 # 2. create StringIO from decoded string
36 # 3. unzip and read the stream
37 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste].delete(:paste_gzip_base64)))).read
38 elsif params[:paste][:paste_gzip]
39 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(params[:paste].delete(:paste_gzip))).read
40 end
41 end
42 @paste = Paste.new(paste_params.merge(ip: request.remote_ip)) 32 @paste = Paste.new(paste_params.merge(ip: request.remote_ip))
43 33
44 begin 34 begin
45 respond_to do |format| 35 respond_to do |format|
46 if @paste.save 36 if @paste.save
75 end 65 end
76 end 66 end
77 67
78 private 68 private
79 def paste_params 69 def paste_params
80 params.require(:paste).permit(:paste, :is_private, :key) 70 params.require(:paste).permit(:paste, :paste_gzip, :paste_gzip_base64, :is_private, :key)
81 end 71 end
82 end 72 end