Skip to content

Commit

Permalink
before de reigai shori
Browse files Browse the repository at this point in the history
  • Loading branch information
cherenkov committed Jul 17, 2010
1 parent 6811b4b commit 20e4b4d
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions croppi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,33 @@
require 'uri'

# reloader
require 'sinatra/base'
require 'sinatra/reloader' if development?
#require 'sinatra/base'
#require 'sinatra/reloader' if development?


before do
p "@@@@@@@@@@@"
if params[:url] then
uri = URI.parse(URI.encode(params[:url]))
Net::HTTP.start(uri.host) {|http|
res = http.request_get(uri.path)
@api_dataURL = "data:" + res['content-type'] + ";base64," + Base64.encode64(res.body)
}
@api_fileName = File.basename(uri.path).tosjis
begin
Net::HTTP.start(uri.host) {|http|
res = http.request_get(uri.path)
redirect "/" unless res['content-type'].include?("image/")

@api_dataURL = "data:" + res['content-type'] + ";base64," + Base64.encode64(res.body)
}
@api_fileName = File.basename(uri.path).tosjis
rescue
redirect '/'
end
end
end



get '/' do
erb :index
end







post '/' do
#適当なチェック
unless params[:imagedata] && params[:filename]
Expand All @@ -47,7 +46,6 @@
#拡張子を除いたファイル名取得し、_c.pngを付け足す。日本語ファイル名文字化け対策にtosjis。
filename = (File.basename(params[:filename], ".*") + "_c.png").tosjis


#tmp/imagesフォルダに保存
open("tmp/#{filename}","wb") do |fh|
fh.write imagedata
Expand All @@ -64,7 +62,7 @@
end




#@@@@ マッチしないリクエストは'/'にリダイレクト。
not_found do
redirect '/'
end

0 comments on commit 20e4b4d

Please sign in to comment.