Permalink
Browse files

create gyazo id in the server script

  • Loading branch information...
1 parent 30d2f58 commit 4ed6b99896c7a4ea3dfbf9cbe479ee16d34897fd Isshu Rakusai committed Sep 24, 2010
Showing with 12 additions and 1 deletion.
  1. +12 −1 Server/upload.cgi
View
13 Server/upload.cgi
@@ -14,10 +14,21 @@ id = cgi.params['id'][0].read
imagedata = cgi.params['imagedata'][0].read
hash = Digest::MD5.hexdigest(imagedata)
+create_newid = false
+if not id or id == "" then
+ id = Digest::MD5.hexdigest(cgi.remote_addr + Time.now.to_s)
+ create_newid = true
+end
+
dbm = SDBM.open('db/id',0644)
dbm[hash] = id
dbm.close
File.open("data/#{hash}.png","w").print(imagedata)
-cgi.out { "http://gyazo.com/#{hash}.png" }
+headers = {}
+if create_newid then
+ headers = {"X-Gyazo-Id"=>id}
+end
+
+cgi.out(headers){"http://gyazo.com/#{hash}.png"}

0 comments on commit 4ed6b99

Please sign in to comment.