This commit is contained in:
2026-03-20 21:17:26 +01:00
parent 1a62fcb81d
commit 29c3ff8572
229 changed files with 13147 additions and 2577 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Support;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class AvatarUrl
{
@@ -22,16 +21,14 @@ class AvatarUrl
}
$base = rtrim((string) config('cdn.avatar_url', 'https://files.skinbase.org'), '/');
$resolvedSize = self::resolveSize($size);
// Use hash-based path: avatars/ab/cd/{hash}/{size}.webp?v={hash}
$p1 = substr($avatarHash, 0, 2);
$p2 = substr($avatarHash, 2, 2);
$diskPath = sprintf('avatars/%s/%s/%s/%d.webp', $p1, $p2, $avatarHash, $size);
// Always use CDN-hosted avatar files.
//return sprintf('%s/avatars/%s/%s/%s/%d.webp?v=%s', $base, $p1, $p2, $avatarHash, $size, $avatarHash);
return sprintf('%s/avatars/%s/%s/%s/%d.webp', $base, $p1, $p2, $avatarHash, $size);
return sprintf('%s/avatars/%s/%s/%s/%d.webp', $base, $p1, $p2, $avatarHash, $resolvedSize);
}
public static function default(): string
@@ -59,4 +56,26 @@ class AvatarUrl
return self::$hashCache[$userId];
}
private static function resolveSize(int $requestedSize): int
{
$sizes = array_values(array_filter(
(array) config('avatars.sizes', [32, 64, 128, 256, 512]),
static fn ($size): bool => (int) $size > 0
));
if ($sizes === []) {
return max(1, $requestedSize);
}
sort($sizes);
foreach ($sizes as $size) {
if ($requestedSize <= (int) $size) {
return (int) $size;
}
}
return (int) end($sizes);
}
}