Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created January 9, 2012 08:00
Show Gist options
  • Save rummelonp/1581794 to your computer and use it in GitHub Desktop.
Save rummelonp/1581794 to your computer and use it in GitHub Desktop.
自鯖ぎゃぞーちゃん!
# -*- coding: utf-8 -*-
require 'sinatra'
require 'erb'
require 'digest/sha1'
set :image_dir, 'public'
get '/' do
@images = Dir[options.image_dir + '/**'].map {|i| File.basename(i)}
erb :index
end
post '/upload.cgi' do
data = params['imagedata'][:tempfile].read
name = Digest::SHA1.hexdigest(data.to_s)
File.open("#{settings.image_dir}/#{name}.png", 'w').print(data)
"http://#{request.host_with_port}/#{name}.png"
end
__END__
@@layout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>pic.mitukiii.jp</title>
</head>
<body>
<%= yield %>
</body>
</html>
@@index
<% @images.each do |i| %>
<img src="<%= i %>" />
<% end %>
diff --git a/Contents/Resources/script b/Contents/Resources/script
index 49694ee..0f67d00 100644
--- a/Contents/Resources/script
+++ b/Contents/Resources/script
@@ -38,7 +38,8 @@ File.delete(tmpfile)
# upload
boundary = '----BOUNDARYBOUNDARY----'
-HOST = 'gyazo.com'
+HOST = 'localhost'
+PORT = '4567'
CGI = '/upload.cgi'
UA = 'Gyazo/1.0'
@@ -60,7 +61,7 @@ header ={
'User-Agent' => UA
}
-Net::HTTP.start(HOST,80){|http|
+Net::HTTP.start(HOST, PORT){|http|
res = http.post(CGI,data,header)
url = res.response.to_ary[1]
system "echo -n #{url} | pbcopy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment