mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
v1.5-alpha.10
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\FileManagerFile;
|
||||
use App\FileManagerFolder;
|
||||
use App\Http\Resources\StorageDetailResource;
|
||||
use App\Http\Tools\Demo;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
@@ -34,10 +36,10 @@ class AccountController extends Controller
|
||||
->get();
|
||||
|
||||
return [
|
||||
'user' => $user->only(['name', 'email', 'avatar']),
|
||||
'favourites' => $user->favourites->makeHidden(['pivot']),
|
||||
'tree' => $tree,
|
||||
'storage' => [
|
||||
'user' => $user->only(['name', 'email', 'avatar']),
|
||||
'favourites' => $user->favourites->makeHidden(['pivot']),
|
||||
'tree' => $tree,
|
||||
'storage' => [
|
||||
'used' => Metric::bytes($user->used_capacity)->format(),
|
||||
'capacity' => format_gigabytes(config('vuefilemanager.user_storage_capacity')),
|
||||
'percentage' => get_storage_fill_percentage($user->used_capacity, config('vuefilemanager.user_storage_capacity')),
|
||||
@@ -45,6 +47,89 @@ class AccountController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get storage details
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function storage()
|
||||
{
|
||||
$document_mimetypes = [
|
||||
'pdf', 'numbers', 'xlsx', 'xls', 'txt', 'md', 'rtf', 'pptx', 'ppt', 'odt', 'ods', 'odp', 'epub', 'docx', 'doc', 'csv', 'pages'
|
||||
];
|
||||
|
||||
$user = Auth::user();
|
||||
$storage_capacity = config('vuefilemanager.user_storage_capacity');
|
||||
|
||||
$images = FileManagerFile::where('user_id', $user->id)
|
||||
->where('type', 'image')->get()->map(function ($item) {
|
||||
return (int)$item->getOriginal('filesize');
|
||||
})->sum();
|
||||
|
||||
$audios = FileManagerFile::where('user_id', $user->id)
|
||||
->where('type', 'audio')->get()->map(function ($item) {
|
||||
return (int)$item->getOriginal('filesize');
|
||||
})->sum();
|
||||
|
||||
$videos = FileManagerFile::where('user_id', $user->id)
|
||||
->where('type', 'video')->get()->map(function ($item) {
|
||||
return (int)$item->getOriginal('filesize');
|
||||
})->sum();
|
||||
|
||||
$documents = FileManagerFile::where('user_id', $user->id)
|
||||
->whereIn('mimetype', $document_mimetypes)->get()->map(function ($item) {
|
||||
return (int)$item->getOriginal('filesize');
|
||||
})->sum();
|
||||
|
||||
$others = FileManagerFile::where('user_id', $user->id)
|
||||
->whereNotIn('mimetype', $document_mimetypes)
|
||||
->whereNotIn('type', ['audio', 'video', 'image'])
|
||||
->get()->map(function ($item) {
|
||||
return (int)$item->getOriginal('filesize');
|
||||
})->sum();
|
||||
|
||||
$usage = collect([
|
||||
'images' => [
|
||||
'used' => $images,
|
||||
'percentage' => get_storage_fill_percentage($images, $storage_capacity),
|
||||
],
|
||||
'audios' => [
|
||||
'used' => $audios,
|
||||
'percentage' => get_storage_fill_percentage($audios, $storage_capacity),
|
||||
],
|
||||
'videos' => [
|
||||
'used' => $videos,
|
||||
'percentage' => get_storage_fill_percentage($videos, $storage_capacity),
|
||||
],
|
||||
'documents' => [
|
||||
'used' => $documents,
|
||||
'percentage' => get_storage_fill_percentage($documents, $storage_capacity),
|
||||
],
|
||||
'others' => [
|
||||
'used' => $others,
|
||||
'percentage' => get_storage_fill_percentage($others, $storage_capacity),
|
||||
],
|
||||
]);
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'id' => '1',
|
||||
'type' => 'disk',
|
||||
'attributes' => [
|
||||
'used' => Metric::bytes($user->used_capacity)->format(),
|
||||
'capacity' => format_gigabytes($storage_capacity),
|
||||
'percentage' => get_storage_fill_percentage($user->used_capacity, $storage_capacity),
|
||||
],
|
||||
'relationships' => $usage->map(function ($item) {
|
||||
return [
|
||||
'used' => Metric::bytes($item['used'])->format(),
|
||||
'percentage' => $item['percentage']
|
||||
];
|
||||
})
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user profile
|
||||
*
|
||||
|
||||
@@ -230,7 +230,7 @@ class Editor
|
||||
$image = Image::make($file->getRealPath())->orientate();
|
||||
|
||||
// Resize image
|
||||
$image->resize(256, null, function ($constraint) {
|
||||
$image->resize(564, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
})->stream();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user