Browse Source

Fix for public links file

Create config path to public_links file
Create this file if it doesn't exist
Add data/ to .gitignore
Boulet 11 years ago
parent
commit
b4313b42e0
3 changed files with 15 additions and 11 deletions
  1. 1 0
      .gitignore
  2. 9 6
      config.yml-dist
  3. 5 5
      lib/rSeed/server.rb

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 tmp/
 config.yml
 *.swp
+data/

+ 9 - 6
config.yml-dist

@@ -3,11 +3,14 @@
 #
 
 rtorrent:
-  rpc_host: "localhost"                   # Hostname, should be localhost
-  rpc_port: 80                            # Default port for your HTTP server
-  rpc_path: "/RPC2"                       # Location directive in your HTTP instance to connect to rTorrent
-  download_dir: "/path/to/download/dir"   # Location of rTorrent's finished downloads directory
+  rpc_host: "localhost"                           # Hostname, should be localhost
+  rpc_port: 80                                    # Default port for your HTTP server
+  rpc_path: "/RPC2"                               # Location directive in your HTTP instance to connect to rTorrent
+  download_dir: "/path/to/download/dir"           # Location of rTorrent's finished downloads directory
+
+rseed:
+  public_link_file_path: "data/public_links.db"   # File with shared torrent's hashes
 
 t411:
-#  t411_username: "login"                 # T411.me username
-#  t411_password: "password"              # T411.me password
+#  t411_username: "login"                         # T411.me username
+#  t411_password: "password"                      # T411.me password

+ 5 - 5
lib/rSeed/server.rb

@@ -27,6 +27,7 @@ module RSeed
         end
       end
       @rtorrent = Rtorrent.new(@config.get("rpc_host"), @config.get("rpc_path"), @config.get("rpc_port"))
+      File.open(@config.get('public_link_file_path'), 'a+'){} if not File.exist?(@config.get('public_link_file_path'))
     end
 
     # Helperz
@@ -54,13 +55,12 @@ module RSeed
       end
 
       def publicLink hash
-        hasLink = false
-        File.open('data/public_links') do |fd|
+        File.open(@config.get('public_link_file_path')) do |fd|
           fd.any? do |line|
-            hasLink = true if line.include?(hash)
+            return true if line.include?(hash)
           end
         end
-        return hasLink 
+        return false 
       end
     end
 
@@ -118,7 +118,7 @@ module RSeed
     post '/share' do
       fullhash = @rtorrent.getHash(params[:hash]).downcase
       if not publicLink(fullhash)
-        File.open('data/public_links', 'a+') do |fd|
+        File.open(@config.get('public_link_file_path'), 'a+') do |fd|
           fd.puts fullhash
         end
       end