fix: peer progress bar

This commit is contained in:
Roardom
2022-08-27 04:16:46 -05:00
parent 25eb105bb3
commit 7ed269147f
2 changed files with 25 additions and 23 deletions
+15 -1
View File
@@ -24,7 +24,21 @@ class TorrentPeerController extends Controller
public function index(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$torrent = Torrent::withAnyStatus()->findOrFail($id);
$peers = Peer::with(['user'])->where('torrent_id', '=', $id)->latest('seeder')->get();
$peers = Peer::query()
->with(['user'])
->where('torrent_id', '=', $id)
->latest('seeder')
->get()
->map(function ($peer) use ($torrent) {
$progress = 100 * (1 - $peer->left / $torrent->size);
$peer['progress'] = match (true) {
0 < $progress && $progress < 1 => 1,
99 < $progress && $progress < 100 => 99,
default => round($progress),
};
return $peer;
});
return \view('torrent.peers', ['torrent' => $torrent, 'peers' => $peers]);
}
+10 -22
View File
@@ -83,29 +83,17 @@
{{ $p->user->username }}</span></a>
</td>
@endif
@if ($p->seeder == 0)
<td>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="{{ ($p->downloaded / $torrent->size) * 100 }}"
aria-valuemin="0"
aria-valuemax="100"
style="width: {{ ($p->downloaded / $torrent->size) * 100 }}%;">
{{ round(($p->downloaded / $torrent->size) * 100) }}%
</div>
<td>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="{{ $p->progress }}"
aria-valuemin="0"
aria-valuemax="100"
style="width: {{ $p->progress }}%;">
{{ $p->progress }}%
</div>
</td>
@elseif ($p->seeder == 1)
<td>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"
style="width: 100%;">
100%
</div>
</div>
</td>
@endif
</div>
</td>
<td>
<span
class="badge-extra text-green text-bold">{{ \App\Helpers\StringHelper::formatBytes($p->uploaded, 2) }}</span>