fix: Fix incorrect byte values

Aside from fixing the units, which mixed binary and metric
inadvertently, this commit adds an interface to a third-party library
that handles the conversion much more elegantly and provides flexibility
 for future needs of a similar nature.
This commit is contained in:
Ben Johnson
2020-03-06 10:38:34 -05:00
parent 8920866194
commit a986681184
9 changed files with 158 additions and 27 deletions
+20 -7
View File
@@ -13,6 +13,7 @@
namespace App\Http\Controllers;
use App\Helpers\ByteUnits;
use App\Models\BonExchange;
use App\Models\BonTransactions;
use App\Models\PersonalFreeleech;
@@ -35,13 +36,25 @@ class BonusController extends Controller
*/
private $chat;
/**
* The library used for parsing byte units.
*
* @var ByteUnits
*/
protected $byteUnits;
/**
* BonusController Constructor.
*
* @param ByteUnits $byteUnits
* @param ChatRepository $chat
*/
public function __construct(ChatRepository $chat)
{
public function __construct(
ByteUnits $byteUnits,
ChatRepository $chat
) {
$this->byteUnits = $byteUnits;
$this->chat = $chat;
}
@@ -593,7 +606,7 @@ class BonusController extends Controller
->select('peers.hash')->distinct()
->join('torrents', 'torrents.id', '=', 'peers.torrent_id')
->where('peers.seeder', 1)
->where('torrents.size', '>=', 1073741824 * 100)
->where('torrents.size', '>=', $this->byteUnits->bytesFromUnit('100GiB'))
->where('peers.user_id', $user->id)
->count();
}
@@ -613,8 +626,8 @@ class BonusController extends Controller
->select('peers.hash')->distinct()
->join('torrents', 'torrents.id', '=', 'peers.torrent_id')
->where('peers.seeder', 1)
->where('torrents.size', '>=', 1073741824 * 25)
->where('torrents.size', '<', 1073741824 * 100)
->where('torrents.size', '>=', $this->byteUnits->bytesFromUnit('25GiB'))
->where('torrents.size', '<', $this->byteUnits->bytesFromUnit('100GiB'))
->where('peers.user_id', $user->id)
->count();
}
@@ -634,8 +647,8 @@ class BonusController extends Controller
->select('peers.hash')->distinct()
->join('torrents', 'torrents.id', '=', 'peers.torrent_id')
->where('peers.seeder', 1)
->where('torrents.size', '>=', 1073741824)
->where('torrents.size', '<', 1073741824 * 25)
->where('torrents.size', '>=', $this->byteUnits->bytesFromUnit('1GiB'))
->where('torrents.size', '<', $this->byteUnits->bytesFromUnit('25GiB'))
->where('peers.user_id', $user->id)
->count();
}