v1.5-alpha.10

This commit is contained in:
carodej
2020-05-18 12:37:33 +02:00
parent dfe4991177
commit 633bef7660
13 changed files with 475 additions and 26 deletions

View File

@@ -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
*