Browse Source

Adding a torrent via link : OK

Antoine Leroyer 11 years ago
parent
commit
d3baf213bb
4 changed files with 27 additions and 12 deletions
  1. 1 2
      lib/rSeed/rtorrent.rb
  2. 6 6
      lib/rSeed/server.rb
  3. 15 0
      public/js/custom.js
  4. 5 4
      views/index.haml

+ 1 - 2
lib/rSeed/rtorrent.rb

@@ -85,13 +85,12 @@ module RSeed
 
     def add(file)
       begin
-        @client.call("load_start",file)
+        @client.call("load_start", file)
       rescue XMLRPC::FaultException => e
         puts "Error:"
         puts e.faultCode
         puts e.faultString
       end
-
     end
 
     def delete(hash)

+ 6 - 6
lib/rSeed/server.rb

@@ -137,10 +137,9 @@ module RSeed
         File.open(@config.get("data_path") + "/" + params['torrentFile'][:filename], "w") do |f|
           f.write(params['torrentFile'][:tempfile].read)
         end
-        @rtorrent.add(params['torrentFile'][:filename])
-        return "Success!"
+        return "OK" if @rtorrent.add(params['torrentFile'][:filename])
       when 'link'
-        # TODO
+        return "Torrent added !" if @rtorrent.add(params[:link])
       when 't411'
         throw(:halt, [404, "Ya pas d'id wesh ...."]) if params['lien'] == nil
         if(URI(params['lien']).host == "www.t411.me")
@@ -151,8 +150,7 @@ module RSeed
           torrentFileContent = RestClient.get "https://api.t411.me/torrents/download/#{id}", {'Authorization' => token}
           torrentFile = @config.get("data_path") + "/" + torrentName + ".torrent"
           File.open(torrentFile, 'wb') {|f| f.write(torrentFileContent) }
-          @rtorrent.add(torrentFile)
-          return "Torrent ajouté !"
+          return @rtorrent.add(torrentFile)
         else
           torrentFile = @config.get("data_path") + "/" + File.basename(params['lien'])
           File.open(torrentFile, 'wb') {|f| f.write(open(params['lien']).read)}
@@ -161,7 +159,9 @@ module RSeed
         404
       end
     end
-
+    
+    # API
+    # ---
     get '/api/:request' do
       content_type :json
       case params[:request]

+ 15 - 0
public/js/custom.js

@@ -42,6 +42,21 @@ $(document).ready(function() {
       });
   });  
 
+  $("#form-add-link").submit(function ( event ){
+     // Stop form from submitting normally
+    event.preventDefault();
+    // Get some values from elements on the page:
+    var $form = $( this ),
+    torrent = $form.find( "input[name='link']" ).val(),
+    url = $form.attr( "action" );
+    // Send the data using post
+    var posting = $.post( url, { link: torrent } );
+    // Put the results in a div
+    posting.done(function( data ) {
+        alertify.success( data );
+    });
+  });
+  
   refreshList();
   refreshUpDownTotal();
   diskInfo();

+ 5 - 4
views/index.haml

@@ -66,24 +66,25 @@
       %a{href: "#panel-search"} Search Engine
   .tabs-content
     #panel-link.content.active{style: "width: 100%;"}
-      %form
+      %form#form-add-link{data: {:abide => ""}, action: "/add/link"}
         .row
           .large-12.columns
-            %input{type: "text", placeholder: "Link to .torrent (http, https, ftp and magnet)"}
+            %input{type: "text", name: "link", required: "", pattern: "url", placeholder: "Link to .torrent (http, https, ftp and magnet)"}
+            %small.error URL not valid !
       .panel.radius
         %p HTTP, HTTPS, FTP and Magnet are natively supported by rTorrent.
         %p For the moment we use the native feature of rTorrent.
         %p rTorrent doesn't support self-signed cert (for HTTPS).
         %p To use Magnet link be sure DHT is activated in your .rtorrent.rc
     #panel-file.content
-      %form
+      %form#form-add-file{action: "/"}
         .row
           .large-12.columns
             %input{type: "file"}
           .large-12.columns
             %input{type: "submit", value: "Send .torrent"}
     #panel-search.content
-      %form
+      %form#search-engine{action: "/"}
         .row
           .large-12.columns
             %input{type: "text", placeholder: "Search for a torrent :)"}