Skip to content

Instantly share code, notes, and snippets.

@darashi
Created June 11, 2009 06:19
Show Gist options
  • Save darashi/127735 to your computer and use it in GitHub Desktop.
Save darashi/127735 to your computer and use it in GitHub Desktop.
Eye-fi receiver
#!/usr/bin/ruby
#
# Eye-fi receiver
# -- An imcomplete implementation of Gallery Remote Protocol Server
# by SHIDARA Yoji <[email protected]>
#
# see http://codex.gallery2.org/Gallery_Remote:Protocol
#
require 'fileutils'
require 'sinatra'
GR_STAT_SUCCESS=0
UNKNOWN_CMD=301
def file_received(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' => 'true'
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