Kaynağa Gözat

DiskSpace info added. Important note in commit !
IMPORTANT :
- require 'sys/filesystem' -> gem install sys-filesystem
- since disk space, you can't use rSeed on a distant host (you need a rtorrent running on the same host where rSeed is launch)

Antoine Leroyer 11 yıl önce
ebeveyn
işleme
1fc3b6c0c2
5 değiştirilmiş dosya ile 26 ekleme ve 2 silme
  1. 2 1
      lib/rSeed.rb
  2. 12 0
      lib/rSeed/rtorrent.rb
  3. 2 0
      lib/rSeed/server.rb
  4. 9 0
      public/js/custom.js
  5. 1 1
      views/index.haml

+ 2 - 1
lib/rSeed.rb

@@ -11,8 +11,9 @@ require "fileutils"
 require "net/http"
 require "sinatra"
 require "xmlrpc/client"
+require "sys/filesystem"
 
 require "rSeed/server"
 require "rSeed/config"
 require "rSeed/session"
-require "rSeed/rtorrent"
+require "rSeed/rtorrent"

+ 12 - 0
lib/rSeed/rtorrent.rb

@@ -59,6 +59,18 @@ module RSeed
       return stats
     end
 
+    def diskInfo
+      begin
+        response = @client.call("get_directory")
+      rescue XMLRPC::FaultException => e
+        puts "Error:"
+        puts e.faultCode
+        puts e.faultString
+      end 
+      stats = Sys::Filesystem.stat(response)
+      return {:total => (stats.blocks * stats.block_size), :free => (stats.block_size * stats.blocks_available)}
+    end
+
     def add(file)
       
     end

+ 2 - 0
lib/rSeed/server.rb

@@ -128,6 +128,8 @@ module RSeed
         @rtorrent.getUpDown.to_json
       when 'get_list'
         @rtorrent.getAll.to_json
+      when 'get_diskinfo'
+        @rtorrent.diskInfo.to_json
       else
         502
       end

+ 9 - 0
public/js/custom.js

@@ -21,6 +21,8 @@ $(document).ready(function() {
   
   refreshList();
   refreshUpDownTotal();
+  diskInfo();
+
 });
 
 function refreshUpDownTotal() {
@@ -53,6 +55,13 @@ function refreshList(){
 
 }
 
+function diskInfo(){
+  $.getJSON( "api/get_diskinfo", function ( data ) {
+    percent = (data['free'] / data['total']) * 100;
+    $(".diskinfo").html(bytesToSize(data['free'], false) + ' Free');
+  });
+}
+
 function bytesToSize(bytes, speed) {
   var sizes = ['o', 'Ko', 'Mo', 'Go', 'To'];
   var speeds = ['o/s', 'Ko/s', 'Mo/s'];

+ 1 - 1
views/index.haml

@@ -15,7 +15,7 @@
             %li
               %a
                 %i.fi-graph-pie
-                493 Go (55%)
+                %span.diskinfo 
             %li.divider
             %li.has-form
               %a.button.radius.success= "&#8593; <strong id='up-info'></strong>"