mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-24 09:50:39 +00:00
record daily traffic instead of monthly
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Models;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
use Domain\Traffic\Models\Traffic;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Domain\Traffic\Models\Traffic;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Database\Factories\UserFactory;
|
||||
use Domain\Settings\Models\Setting;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
@@ -95,7 +94,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
$is_storage_limit = get_settings('storage_limitation') ?? 1;
|
||||
|
||||
if (!$is_storage_limit) {
|
||||
if (! $is_storage_limit) {
|
||||
return [
|
||||
'used' => $this->usedCapacity,
|
||||
'used_formatted' => Metric::bytes($this->usedCapacity)->format(),
|
||||
@@ -103,7 +102,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
}
|
||||
|
||||
return [
|
||||
'used' => (float)get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount),
|
||||
'used' => (float) get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount),
|
||||
'used_formatted' => get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount) . '%',
|
||||
'capacity' => $this->limitations->max_storage_amount,
|
||||
'capacity_formatted' => format_gigabytes($this->limitations->max_storage_amount),
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Models;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
use DB;
|
||||
use ByteUnits\Metric;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Database\Factories\UserLimitationFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
/**
|
||||
* @property int max_storage_amount
|
||||
@@ -23,7 +22,7 @@ class UserLimitation extends Model
|
||||
protected $guarded = [];
|
||||
|
||||
protected $hidden = [
|
||||
'user_id', 'user'
|
||||
'user_id', 'user',
|
||||
];
|
||||
|
||||
public $incrementing = false;
|
||||
@@ -99,7 +98,7 @@ class UserLimitation extends Model
|
||||
'use' => $totalUsedEmails->count(),
|
||||
'total' => (int) $this->max_team_members,
|
||||
'percentage' => ($totalUsedEmails->count() / $this->max_team_members) * 100,
|
||||
'meta' => [
|
||||
'meta' => [
|
||||
'allowed_emails' => $totalUsedEmails,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Resources;
|
||||
|
||||
use Domain\Folders\Resources\FolderCollection;
|
||||
@@ -40,7 +39,7 @@ class UserResource extends JsonResource
|
||||
'attributes' => $this->limitations,
|
||||
],
|
||||
],
|
||||
$this->mergeWhen($this->hasSubscription(), fn() => [
|
||||
$this->mergeWhen($this->hasSubscription(), fn () => [
|
||||
'subscription' => new SubscriptionResource($this->subscription),
|
||||
]),
|
||||
],
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Resources;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
@@ -22,12 +21,12 @@ class UserStorageResource extends JsonResource
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'id' => (string)$this->id,
|
||||
'id' => (string) $this->id,
|
||||
'type' => 'storage',
|
||||
'attributes' => [
|
||||
'used' => Metric::bytes($this->usedCapacity)->format(),
|
||||
'capacity' => format_gigabytes($this->limitations->max_storage_amount),
|
||||
'percentage' => (float)get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount),
|
||||
'percentage' => (float) get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount),
|
||||
],
|
||||
'meta' => [
|
||||
'traffic' => [
|
||||
@@ -40,23 +39,23 @@ class UserStorageResource extends JsonResource
|
||||
],
|
||||
'images' => [
|
||||
'used' => Metric::bytes($images)->format(),
|
||||
'percentage' => (float)get_storage_fill_percentage($images, $this->limitations->max_storage_amount),
|
||||
'percentage' => (float) get_storage_fill_percentage($images, $this->limitations->max_storage_amount),
|
||||
],
|
||||
'audios' => [
|
||||
'used' => Metric::bytes($audios)->format(),
|
||||
'percentage' => (float)get_storage_fill_percentage($audios, $this->limitations->max_storage_amount),
|
||||
'percentage' => (float) get_storage_fill_percentage($audios, $this->limitations->max_storage_amount),
|
||||
],
|
||||
'videos' => [
|
||||
'used' => Metric::bytes($videos)->format(),
|
||||
'percentage' => (float)get_storage_fill_percentage($videos, $this->limitations->max_storage_amount),
|
||||
'percentage' => (float) get_storage_fill_percentage($videos, $this->limitations->max_storage_amount),
|
||||
],
|
||||
'documents' => [
|
||||
'used' => Metric::bytes($documents)->format(),
|
||||
'percentage' => (float)get_storage_fill_percentage($documents, $this->limitations->max_storage_amount),
|
||||
'percentage' => (float) get_storage_fill_percentage($documents, $this->limitations->max_storage_amount),
|
||||
],
|
||||
'others' => [
|
||||
'used' => Metric::bytes($others)->format(),
|
||||
'percentage' => (float)get_storage_fill_percentage($others, $this->limitations->max_storage_amount),
|
||||
'percentage' => (float) get_storage_fill_percentage($others, $this->limitations->max_storage_amount),
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -127,8 +126,8 @@ class UserStorageResource extends JsonResource
|
||||
->where('created_at', '>', $period)
|
||||
->sum('upload');
|
||||
|
||||
$upload = $trafficRecords->map(fn($record) => round(($record->upload / $uploadMax) * 100, 2));
|
||||
$download = $trafficRecords->map(fn($record) => round(($record->download / $downloadMax) * 100, 2));
|
||||
$upload = $trafficRecords->map(fn ($record) => round(($record->upload / $uploadMax) * 100, 2));
|
||||
$download = $trafficRecords->map(fn ($record) => round(($record->download / $downloadMax) * 100, 2));
|
||||
|
||||
return [$downloadTotal, $uploadTotal, $upload, $download];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user