Cleanup.
This commit is contained in:
parent
e51e5cde45
commit
580c7132c6
6 changed files with 156 additions and 149 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using RdtClient.Data.Enums;
|
||||
using RdtClient.Data.Models.Data;
|
||||
using RdtClient.Data.Models.TorrentClient;
|
||||
|
||||
namespace RdtClient.Data.Models.Internal;
|
||||
|
|
|
|||
|
|
@ -221,23 +221,26 @@ public class QBittorrent(ILogger<QBittorrent> logger, Settings settings, Authent
|
|||
var rdProgress = Math.Clamp(torrent.RdProgress ?? 0.0, 0.0, 100.0) / 100.0;
|
||||
var bytesTotal = torrent.RdSize ?? 0;
|
||||
var speed = torrent.RdSpeed ?? 0;
|
||||
var bytesDone = (Int64) (bytesTotal * rdProgress);
|
||||
var bytesDone = (Int64)(bytesTotal * rdProgress);
|
||||
|
||||
Double downloadProgress = 0;
|
||||
|
||||
if (torrent.Downloads is { Count: > 0 })
|
||||
{
|
||||
var dlBytesDone = torrent.Downloads.Sum(m => m.BytesDone);
|
||||
var dlBytesTotal = torrent.Downloads.Sum(m => m.BytesTotal);
|
||||
speed = (Int32) torrent.Downloads.Average(m => m.Speed);
|
||||
downloadProgress = bytesTotal > 0 ? Math.Clamp((Double) dlBytesDone / dlBytesTotal, 0.0, 1.0) : 0;
|
||||
speed = (Int32)torrent.Downloads.Average(m => m.Speed);
|
||||
downloadProgress = bytesTotal > 0 ? Math.Clamp((Double)dlBytesDone / dlBytesTotal, 0.0, 1.0) : 0;
|
||||
}
|
||||
|
||||
var progress = (rdProgress + downloadProgress) / 2.0;
|
||||
var remaining = TimeSpan.Zero;
|
||||
var bytesRemaining = bytesTotal - bytesDone;
|
||||
|
||||
if (speed > 0 && bytesRemaining > 0)
|
||||
{
|
||||
remaining = TimeSpan.FromSeconds(bytesRemaining / (Double)speed);
|
||||
|
||||
// In case there is clock skew
|
||||
if (remaining < TimeSpan.Zero)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -66,8 +66,10 @@ public class RemoteService(IHubContext<RdtHub> hub, Torrents torrents)
|
|||
BytesTotal = download.BytesTotal,
|
||||
BytesDone = download.BytesDone,
|
||||
Speed = download.Speed
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
})
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await hub.Clients.All.SendCoreAsync("update",
|
||||
[
|
||||
|
|
|
|||
|
|
@ -78,8 +78,10 @@ public class TorrentsController(ILogger<TorrentsController> logger, Torrents tor
|
|||
BytesTotal = download.BytesTotal,
|
||||
BytesDone = download.BytesDone,
|
||||
Speed = download.Speed
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
})
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Ok(torrentDtos);
|
||||
}
|
||||
|
|
@ -138,7 +140,7 @@ public class TorrentsController(ILogger<TorrentsController> logger, Torrents tor
|
|||
RdSpeed = torrent.RdSpeed,
|
||||
RdSeeders = torrent.RdSeeders,
|
||||
Files = torrent.Files,
|
||||
Downloads = (torrent.Downloads).Select(download => new DownloadDto
|
||||
Downloads = torrent.Downloads.Select(download => new DownloadDto
|
||||
{
|
||||
DownloadId = download.DownloadId,
|
||||
TorrentId = download.TorrentId,
|
||||
|
|
@ -157,7 +159,8 @@ public class TorrentsController(ILogger<TorrentsController> logger, Torrents tor
|
|||
BytesTotal = download.BytesTotal,
|
||||
BytesDone = download.BytesDone,
|
||||
Speed = download.Speed
|
||||
}).ToList()
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
|
||||
return Ok(torrentDto);
|
||||
|
|
|
|||
Loading…
Reference in a new issue