Аватар: в шапку рядом с именем, кэш на год, чинит битую ссылку и вечный application/octet-stream у загрузок

This commit is contained in:
rsgrinko committed 2026-09-17 02:29:56 +03:00
1 parent 4a57409eec
commit 9caacebb49
5 files changed
+47 -8

No files matched your search

+8 -2
View File
@@ -173,11 +173,17 @@ final class ProfileController extends Controller
/** @var User|null $user */
$user = User::find($id);
if ($user === null || !$user->hasAvatar() || !Storage::exists((string) $user->avatar_path)) {
if ($user === null || !$user->hasAvatar()) {
return new Response('', 404);
}
return Response::file(Storage::path((string) $user->avatar_path), (string) $user->avatar_mime ?: 'application/octet-stream');
// Ссылка несёт хеш пути файла (View::avatar()): пока фото не заменили,
// адрес не меняется, и браузеру незачем перекачивать его на каждой
// странице — без этих заголовков сессия шлёт no-store на любой ответ
return Response::file(Storage::path((string) $user->avatar_path), (string) $user->avatar_mime ?: 'application/octet-stream')
->withHeader('Cache-Control', 'private, max-age=31536000, immutable')
->withHeader('Pragma', 'cache')
->withHeader('Expires', gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
}
private static function metaKey(UserField $field): string