mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-17 10:45:01 +00:00
added basic traffic meter for upload/download
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\FileManagerFolder;
|
||||
use App\Http\Tools\Guardian;
|
||||
use App\Share;
|
||||
use App\User;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -84,6 +85,9 @@ class FileAccessController extends Controller
|
||||
$this->check_file_access($shared, $file);
|
||||
}
|
||||
|
||||
// Store user download size
|
||||
$request->user()->record_download((int) $file->getRawOriginal('filesize'));
|
||||
|
||||
return $this->download_file($file);
|
||||
}
|
||||
|
||||
@@ -113,6 +117,9 @@ class FileAccessController extends Controller
|
||||
// Check file access
|
||||
$this->check_file_access($shared, $file);
|
||||
|
||||
// Store user download size
|
||||
User::find($shared->user_id)->record_download((int) $file->getRawOriginal('filesize'));
|
||||
|
||||
return $this->download_file($file);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ class FileSharingController extends Controller
|
||||
->first();
|
||||
|
||||
if ($image) {
|
||||
|
||||
// Store user download size
|
||||
User::find($shared->user_id)->record_download((int) $image->getRawOriginal('filesize'));
|
||||
|
||||
return $this->show_image($image);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,6 +308,9 @@ class Editor
|
||||
'user_id' => $user_id,
|
||||
];
|
||||
|
||||
// Store user upload size
|
||||
$request->user()->record_upload($file_size);
|
||||
|
||||
// Return new file
|
||||
return FileManagerFile::create($options);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Traffic extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
+37
-2
@@ -5,6 +5,7 @@ namespace App;
|
||||
use App\Notifications\ResetPassword;
|
||||
use App\Notifications\ResetUserPasswordNotification;
|
||||
use ByteUnits\Metric;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -157,10 +158,10 @@ class User extends Authenticatable
|
||||
$is_storage_limit = $storage_limitation ? $storage_limitation : 1;
|
||||
|
||||
// Get user storage usage
|
||||
if (! $is_storage_limit) {
|
||||
if (!$is_storage_limit) {
|
||||
|
||||
return [
|
||||
'used' => $this->used_capacity,
|
||||
'used' => $this->used_capacity,
|
||||
'used_formatted' => Metric::bytes($this->used_capacity)->format(),
|
||||
];
|
||||
}
|
||||
@@ -252,6 +253,40 @@ class User extends Authenticatable
|
||||
$this->notify(new ResetPassword($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Record user upload filesize
|
||||
*
|
||||
* @param $file_size
|
||||
*/
|
||||
public function record_upload($file_size)
|
||||
{
|
||||
$record = Traffic::whereMonth('created_at', '=', Carbon::now()->month)
|
||||
->firstOrCreate([
|
||||
'user_id' => $this->id,
|
||||
]);
|
||||
|
||||
$record->update([
|
||||
'upload' => $record->upload + $file_size
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Record user download filesize
|
||||
*
|
||||
* @param $file_size
|
||||
*/
|
||||
public function record_download($file_size)
|
||||
{
|
||||
$record = Traffic::whereMonth('created_at', '=', Carbon::now()->month)
|
||||
->firstOrCreate([
|
||||
'user_id' => $this->id,
|
||||
]);
|
||||
|
||||
$record->update([
|
||||
'download' => $record->download + $file_size
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user favourites folder
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user