api resource refactoring part 3

This commit is contained in:
Peter Papp
2021-08-27 11:01:44 +02:00
parent 174f2a2c1f
commit d299183ecd
16 changed files with 101 additions and 91 deletions

View File

@@ -1,4 +1,5 @@
<?php
namespace App\Users\Models;
use ByteUnits\Metric;
@@ -95,7 +96,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 +104,7 @@ class User extends Authenticatable implements MustVerifyEmail
}
return [
'used' => (float) get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity),
'used' => (float)get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity),
'used_formatted' => get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity) . '%',
'capacity' => $this->settings->storage_capacity,
'capacity_formatted' => format_gigabytes($this->settings->storage_capacity),
@@ -116,7 +117,7 @@ class User extends Authenticatable implements MustVerifyEmail
public function getUsedCapacityAttribute(): int
{
return $this->filesWithTrashed
->map(fn ($item) => $item->getRawOriginal())->sum('filesize');
->map(fn($item) => $item->getRawOriginal())->sum('filesize');
}
/**
@@ -165,7 +166,10 @@ class User extends Authenticatable implements MustVerifyEmail
public function latestUploads(): HasMany
{
return $this->hasMany(File::class)
->with(['parent:id,name'])
->with([
'parent:id,name',
'shared:token,id,item_id,permission,is_protected,expire_in',
])
->take(40);
}