Module: S3::TrackerHelper
- Defined in:
- lib/sinatra-s3/helpers/tracker.rb
Instance Method Summary collapse
- #torrent(bit) ⇒ Object
- #torrent_list(info_hash) ⇒ Object
- #tracker_error(msg) ⇒ Object
- #tracker_reply(params) ⇒ Object
Instance Method Details
#torrent(bit) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sinatra-s3/helpers/tracker.rb', line 6 def torrent(bit) mi = bit. mi.announce = URI("http://#{env['HTTP_HOST']}/tracker/announce") mi.url_list = URI("http://#{env['HTTP_HOST']}/#{bit.parent.name}/#{bit.name}") mi.created_by = "Served by Sinatra-S3/0.1a" mi.creation_date = Time.now t = Torrent.find_by_bit_id bit.id info_hash = Digest::SHA1.digest(mi.info.to_bencoding).to_hex_s unless t and t.info_hash == info_hash t ||= Torrent.new t.update_attributes(:info_hash => info_hash, :bit_id => bit.id, :metainfo => mi.to_bencoding) end status 200 headers 'Content-Disposition' => "attachment; filename=#{bit.name}.torrent;", 'Content-Type' => 'application/x-bittorrent' body mi.to_bencoding end |
#torrent_list(info_hash) ⇒ Object
23 24 25 26 27 |
# File 'lib/sinatra-s3/helpers/tracker.rb', line 23 def torrent_list(info_hash) params = {:order => 'seeders DESC, leechers DESC', :include => :bit} params[:conditions] = ['info_hash = ?', info_hash.to_hex_s] if info_hash Torrent.find :all, params end |
#tracker_error(msg) ⇒ Object
35 36 37 38 39 |
# File 'lib/sinatra-s3/helpers/tracker.rb', line 35 def tracker_error(msg) status 200 headers 'Content-Type' => 'text/plain' body ({'failure reason' => msg}.to_bencoding) end |
#tracker_reply(params) ⇒ Object
29 30 31 32 33 |
# File 'lib/sinatra-s3/helpers/tracker.rb', line 29 def tracker_reply(params) status 200 headers 'Content-Type' => 'text/plain' body params.merge('interval' => TRACKER_INTERVAL).to_bencoding end |