-
-
Save sawamur/274953 to your computer and use it in GitHub Desktop.
Eye-fi reciver for sinatra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# Eye-fi receiver | |
# -- An imcomplete implementation of Gallery Remote Protocol Server | |
# by SHIDARA Yoji <dara@shidara.net> | |
# | |
# see http://codex.gallery2.org/Gallery_Remote:Protocol | |
# | |
require 'fileutils' | |
require 'sinatra' | |
GR_STAT_SUCCESS=0 | |
UNKNOWN_CMD=301 | |
def file_recieved(tempfile, filename, uname) | |
dest_path = [Time.now.strftime("%Y%m%d-%H%M%S"), uname.gsub(/[^a-z0-9\.]/i,''), filename.gsub(/[^a-z0-9\.]/i,'')].join('-') # NOTE: change here | |
FileUtils.mv tempfile.path, dest_path | |
end | |
def gr_response(h) | |
"#__GR2PROTO__\n"+h.map{|k,v| "#{k}=#{v}"}.join("\n")+"\n" | |
end | |
use Rack::Session::Cookie, :key => 'GALLERYSID' # NOTE: set secret | |
post '/main.php' do | |
case params['g2_form']['cmd'] | |
when 'login' | |
session[:uname] = params['g2_form']['uname'] | |
gr_response 'status' => GR_STAT_SUCCESS, | |
'server_version' => '2.0' | |
when 'fetch-albums-prune' | |
gr_response 'status' => GR_STAT_SUCCESS, | |
'album_count' => 1, | |
'album.name.1' => 'dummy', | |
'album.title.1' => 'dummy', | |
'album.parent.1' => 0, | |
'album.perms.add.1' => 'true', | |
'album.perms.write.1' => 'true', | |
'album.perms.del_alb.1' => 'true', | |
'album.perms.create_sub.1' => 'true', | |
'can_create_root' => 'yes' | |
when 'new-album' | |
gr_response 'status' => GR_STAT_SUCCESS, | |
'album_name' => params['g2_form']['newAlbumName'] | |
when 'add-item' | |
file_recieved(params['g2_userfile'][:tempfile], params['g2_userfile'][:filename], session[:uname]) | |
gr_response 'status' => GR_STAT_SUCCESS, | |
'item_name' => 'dummy' | |
else | |
gr_response 'status' => UNKNOWN_CMD | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment