mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 19:10:40 +00:00
record daily traffic instead of monthly
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Users\Models\User;
|
||||
@@ -36,11 +35,10 @@ class SetupDevEnvironment extends Command
|
||||
|
||||
public function __construct(
|
||||
private CreateDiskDirectoriesAction $createDiskDirectories,
|
||||
private SeedDefaultSettingsAction $seedDefaultSettings,
|
||||
private SeedDefaultLanguageAction $seedDefaultLanguage,
|
||||
private SeedDefaultPagesAction $seedDefaultPages,
|
||||
)
|
||||
{
|
||||
private SeedDefaultSettingsAction $seedDefaultSettings,
|
||||
private SeedDefaultLanguageAction $seedDefaultLanguage,
|
||||
private SeedDefaultPagesAction $seedDefaultPages,
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->setUpFaker();
|
||||
}
|
||||
@@ -761,7 +759,7 @@ class SetupDevEnvironment extends Command
|
||||
|
||||
collect([$members[0]->id, $members[1]->id])
|
||||
->each(
|
||||
fn($id) => DB::table('team_folder_members')
|
||||
fn ($id) => DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $companyProjectFolder->id,
|
||||
'user_id' => $id,
|
||||
@@ -771,7 +769,7 @@ class SetupDevEnvironment extends Command
|
||||
|
||||
collect([$members[2]->id, $members[3]->id])
|
||||
->each(
|
||||
fn($id) => DB::table('team_folder_members')
|
||||
fn ($id) => DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $financeDocumentsFolder->id,
|
||||
'user_id' => $id,
|
||||
@@ -782,7 +780,7 @@ class SetupDevEnvironment extends Command
|
||||
// Create invitations
|
||||
collect([$members[4], $members[5]])
|
||||
->each(
|
||||
fn($user) => TeamFolderInvitation::factory()
|
||||
fn ($user) => TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'email' => $user->email,
|
||||
'parent_id' => $companyProjectFolder->id,
|
||||
@@ -1080,7 +1078,6 @@ class SetupDevEnvironment extends Command
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate demo traffic data
|
||||
*/
|
||||
@@ -1089,17 +1086,17 @@ class SetupDevEnvironment extends Command
|
||||
$user = User::all();
|
||||
|
||||
foreach (range(0, 45) as $day) {
|
||||
|
||||
$user
|
||||
->each(fn($user) => DB::table('traffic')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'user_id' => $user->id,
|
||||
'upload' => random_int(1111111, 9999999),
|
||||
'download' => random_int(11111111, 99999999),
|
||||
'created_at' => now()->subDays($day),
|
||||
'updated_at' => now()->subDays($day),
|
||||
])
|
||||
->each(
|
||||
fn ($user) => DB::table('traffic')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'user_id' => $user->id,
|
||||
'upload' => random_int(1111111, 9999999),
|
||||
'download' => random_int(11111111, 99999999),
|
||||
'created_at' => now()->subDays($day),
|
||||
'updated_at' => now()->subDays($day),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1184,7 +1181,7 @@ class SetupDevEnvironment extends Command
|
||||
// Create thumbnail only if image is larger than predefined image sizes
|
||||
if ($intervention->getWidth() > $size['size']) {
|
||||
// Generate thumbnail
|
||||
$intervention->resize($size['size'], null, fn($constraint) => $constraint->aspectRatio())->stream();
|
||||
$intervention->resize($size['size'], null, fn ($constraint) => $constraint->aspectRatio())->stream();
|
||||
|
||||
// Store thumbnail to disk
|
||||
Storage::put("files/$user->id/{$size['name']}-{$file_name}", $intervention);
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ class DeleteUserDataAction
|
||||
{
|
||||
// Delete user avatar if exists
|
||||
if ($user->settings->getRawOriginal('avatar')) {
|
||||
|
||||
// TODO: delete all generated avatars
|
||||
Storage::delete($user->settings->getRawOriginal('avatar'));
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ class GetWidgetsValuesController extends Controller
|
||||
)->format();
|
||||
|
||||
return [
|
||||
'license' => get_settings('license'),
|
||||
'app_version' => config('vuefilemanager.version'),
|
||||
'total_users' => User::count(),
|
||||
'total_used_space' => $storage_usage,
|
||||
'license' => get_settings('license'),
|
||||
'app_version' => config('vuefilemanager.version'),
|
||||
'total_users' => User::count(),
|
||||
'total_used_space' => $storage_usage,
|
||||
'total_premium_users' => Subscription::count(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ use Domain\SetupWizard\Requests\StoreStripePlansRequest;
|
||||
*/
|
||||
class StorePlansController extends Controller
|
||||
{
|
||||
|
||||
public function __invoke(
|
||||
StoreStripePlansRequest $request
|
||||
): Response {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Teams\Actions;
|
||||
|
||||
use App\Users\Models\User;
|
||||
@@ -29,4 +28,4 @@ class CheckMaxTeamMembersLimitAction
|
||||
abort(423, 'You exceed your members limit.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
namespace Domain\Teams\Controllers;
|
||||
|
||||
use Domain\Teams\Actions\CheckMaxTeamMembersLimitAction;
|
||||
use Domain\Teams\Models\TeamFolderMember;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Teams\Models\TeamFolderMember;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Domain\Teams\Requests\ConvertIntoTeamFolderRequest;
|
||||
use Domain\Teams\Actions\CheckMaxTeamMembersLimitAction;
|
||||
use Domain\Teams\Actions\InviteMembersIntoTeamFolderAction;
|
||||
use Domain\Teams\Actions\SetTeamFolderPropertyForAllChildrenAction;
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
namespace Domain\Teams\Controllers;
|
||||
|
||||
use Domain\Teams\Actions\CheckMaxTeamMembersLimitAction;
|
||||
use Domain\Teams\Models\TeamFolderMember;
|
||||
use Illuminate\Support\Str;
|
||||
use Domain\Files\Models\File;
|
||||
use Illuminate\Http\Response;
|
||||
@@ -10,6 +8,7 @@ use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Domain\Teams\Models\TeamFolderMember;
|
||||
use Domain\Teams\DTO\CreateTeamFolderData;
|
||||
use Domain\Files\Resources\FilesCollection;
|
||||
use Domain\Folders\Resources\FolderResource;
|
||||
@@ -18,6 +17,7 @@ use Domain\Folders\Resources\FolderCollection;
|
||||
use Domain\Teams\Actions\UpdateInvitationsAction;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Domain\Teams\Requests\CreateTeamFolderRequest;
|
||||
use Domain\Teams\Actions\CheckMaxTeamMembersLimitAction;
|
||||
use Domain\Teams\Requests\UpdateTeamFolderMembersRequest;
|
||||
use Domain\Teams\Actions\InviteMembersIntoTeamFolderAction;
|
||||
use Domain\Teams\Actions\SetTeamFolderPropertyForAllChildrenAction;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace Domain\Teams\Models;
|
||||
|
||||
use Database\Factories\TeamFolderMemberFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Database\Factories\TeamFolderMemberFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ class RecordDownloadAction
|
||||
int $file_size,
|
||||
string $user_id,
|
||||
): void {
|
||||
$record = Traffic::currentMonth()
|
||||
$record = Traffic::currentDay()
|
||||
->firstOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
|
||||
@@ -12,7 +12,7 @@ class RecordUploadAction
|
||||
int $file_size,
|
||||
string $user_id,
|
||||
): void {
|
||||
$record = Traffic::currentMonth()
|
||||
$record = Traffic::currentDay()
|
||||
->firstOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
|
||||
@@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
/**
|
||||
* @method static whereYear(string $string, string $string1, int $year)
|
||||
* @method static currentMonth()
|
||||
* @property string id
|
||||
* @property string user_id
|
||||
* @property int upload
|
||||
@@ -18,29 +16,21 @@ class Traffic extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'upload',
|
||||
'download',
|
||||
];
|
||||
protected $guarded = [];
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function scopeCurrentMonth($query): Builder
|
||||
public function scopeCurrentDay($query): Builder
|
||||
{
|
||||
return $query
|
||||
->whereYear('created_at', '=', now()->year)
|
||||
->whereMonth('created_at', '=', now()->month);
|
||||
return $query->whereDate('created_at', today());
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->id = (string) Str::uuid();
|
||||
});
|
||||
static::creating(fn ($model) => $model->id = (string) Str::uuid());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ if (! function_exists('user_storage_percentage')) {
|
||||
/**
|
||||
* Get user capacity fill by percentage
|
||||
*/
|
||||
function user_storage_percentage($id, int $additionals = null)
|
||||
function user_storage_percentage($id, ?int $additionals = null)
|
||||
{
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user