1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 17:12:30 +01:00

Remove any confusing legacy sizing files; everything in the panel is true MB (1000) not MiB

This commit is contained in:
Dane Everitt 2020-05-08 21:13:39 -07:00
parent 2d95204e9a
commit 6967b76ae6
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 0 additions and 107 deletions

View File

@ -1,28 +0,0 @@
<?php
namespace Pterodactyl\Providers;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
class MacroServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*/
public function boot()
{
File::macro('humanReadableSize', function ($path, $precision = 2) {
$size = File::size($path);
static $units = ['B', 'kB', 'MB', 'GB', 'TB'];
$i = 0;
while (($size / 1024) > 0.9) {
$size = $size / 1024;
$i++;
}
return round($size, ($i < 2) ? 0 : $precision) . ' ' . $units[$i];
});
}
}

View File

@ -1,34 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
if (! function_exists('human_readable')) {
/**
* Generate a human-readable filesize for a given file path.
*
* @param string $path
* @param int $precision
* @return string
*/
function human_readable($path, $precision = 2)
{
if (is_numeric($path)) {
$i = 0;
while (($path / 1024) > 0.9) {
$path = $path / 1024;
$i++;
}
return round($path, $precision) . ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'][$i];
}
return app('file')->humanReadableSize($path, $precision);
}
}
if (! function_exists('is_digit')) {
/**

View File

@ -180,7 +180,6 @@ return [
Pterodactyl\Providers\EventServiceProvider::class,
Pterodactyl\Providers\HashidsServiceProvider::class,
Pterodactyl\Providers\RouteServiceProvider::class,
Pterodactyl\Providers\MacroServiceProvider::class,
Pterodactyl\Providers\RepositoryServiceProvider::class,
Pterodactyl\Providers\ViewComposerServiceProvider::class,

View File

@ -1,48 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Tests\Unit\Helpers;
use Tests\TestCase;
class HumanReadableTest extends TestCase
{
/**
* Test the human_readable helper.
*
* @dataProvider helperDataProvider
*/
public function testHelper($value, $response, $precision = 2)
{
$this->assertSame($response, human_readable($value, $precision));
}
/**
* Provide data to test against the helper function.
*
* @return array
*/
public function helperDataProvider()
{
return [
[0, '0B'],
[1, '1B'],
[1024, '1kB'],
[10392, '10.15kB'],
[10392, '10kB', 0],
[10392, '10.148438kB', 6],
[1024000, '0.98MB'],
[1024000, '1MB', 0],
[102400000, '97.66MB'],
[102400000, '98MB', 0],
[102400000, '97.6563MB', 4],
[102400000, '97.65625MB', 10],
];
}
}