Mercurial > zeropaste
comparison app/controllers/pastes_controller.rb @ 88:0f206bd4924f
Allows posting gzipped text.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Tue, 06 Nov 2012 11:14:32 +0700 |
parents | 2fb80ca710e0 |
children | db5164ff73a9 |
comparison
equal
deleted
inserted
replaced
87:b245005ac9ac | 88:0f206bd4924f |
---|---|
34 # POST / | 34 # POST / |
35 # POST /pastes.json | 35 # POST /pastes.json |
36 # POST /pastes.txt | 36 # POST /pastes.txt |
37 def create | 37 def create |
38 @paste = Paste.new | 38 @paste = Paste.new |
39 if params[:paste] and not params[:paste][:paste].blank? | 39 if params[:paste] |
40 @paste.paste = params[:paste][:paste] | 40 if params[:paste][:paste_gzip_base64] |
41 @paste.ip = request.remote_ip | 41 # 1. decode from base64 |
42 # 2. create StringIO from decoded string | |
43 # 3. unzip and read the stream | |
44 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste][:paste_gzip_base64]))).read | |
45 end | |
46 unless params[:paste][:paste].blank? | |
47 @paste.paste = params[:paste][:paste] | |
48 @paste.ip = request.remote_ip | |
49 end | |
42 end | 50 end |
43 | 51 |
44 begin | 52 begin |
45 respond_to do |format| | 53 respond_to do |format| |
46 if @paste.save | 54 if @paste.save |