Upload beautify

This commit is contained in:
2026-02-17 17:14:43 +01:00
parent b053c0cc48
commit 41287914aa
106 changed files with 4948 additions and 906 deletions

50
app/Support/AvatarUrl.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
namespace App\Support;
use Illuminate\Support\Facades\DB;
class AvatarUrl
{
private static array $hashCache = [];
public static function forUser(int $userId, ?string $hash = null, int $size = 128): string
{
if ($userId <= 0) {
return self::default();
}
$avatarHash = $hash ?: self::resolveHash($userId);
if (!$avatarHash) {
return self::default();
}
$base = rtrim((string) config('cdn.avatar_url', 'https://file.skinbase.org'), '/');
return sprintf('%s/avatars/%d/%d.webp?v=%s', $base, $userId, $size, $avatarHash);
}
public static function default(): string
{
return asset('img/default-avatar.webp');
}
private static function resolveHash(int $userId): ?string
{
if (array_key_exists($userId, self::$hashCache)) {
return self::$hashCache[$userId];
}
try {
$value = DB::table('user_profiles')
->where('user_id', $userId)
->value('avatar_hash');
} catch (\Throwable $e) {
$value = null;
}
self::$hashCache[$userId] = $value ? (string) $value : null;
return self::$hashCache[$userId];
}
}