增加获取预格式化后数据功能

This commit is contained in:
Chenx221 2024-03-22 14:48:17 +08:00
parent 41bfaafc4f
commit 96a5dcb9a5
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
2 changed files with 23 additions and 3 deletions

View File

@ -73,7 +73,20 @@ class FileSizeHelper
$userHomeDir = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $user_id . '.secret'; $userHomeDir = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $user_id . '.secret';
return self::getDirectorySize($userHomeDir); return self::getDirectorySize($userHomeDir);
} }
public static function getUserAllDirSize(int $user_id = null): int
{
if ($user_id === null) {
$user_id = Yii::$app->user->id;
}
return self::getUserHomeDirSize($user_id) + self::getUserVaultDirSize($user_id);
}
public static function getFormatUserAllDirSize(int $user_id = null): string
{
if ($user_id === null) {
$user_id = Yii::$app->user->id;
}
return self::formatBytes(self::getUserAllDirSize($user_id));
}
/** /**
* @param $bytes * @param $bytes
* @param $precision * @param $precision

View File

@ -15,15 +15,16 @@ class IPLocation
public function __construct() public function __construct()
{ {
$status = Yii::$app->params['enableIpInfo']; $status = Yii::$app->params['enableIpInfo'];
if($status){ if ($status) {
$this->is_disabled = false; $this->is_disabled = false;
$this->client = new IPinfo(Yii::$app->params['ipinfoToken']); $this->client = new IPinfo(Yii::$app->params['ipinfoToken']);
} }
} }
public static function getDetails(string $ip): ?Details public static function getDetails(string $ip): ?Details
{ {
$instance = new self(); $instance = new self();
if($instance->is_disabled){ if ($instance->is_disabled) {
return null; return null;
} }
try { try {
@ -41,4 +42,10 @@ class IPLocation
} }
} }
public static function getFormatDetails(string $ip): string
{
$details = self::getDetails($ip);
return $ip.' (' . ($details->bogon ? ('Bogon IP') : ($details->city . ', ' . $details->country)) . ')';
}
} }