48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
use MintyPHP\Service\User\UserServicesFactory;
|
|
use MintyPHP\Service\Access\AccessServicesFactory;
|
|
use MintyPHP\Service\Access\UserAuthorizationPolicy;
|
|
use MintyPHP\Support\Guard;
|
|
|
|
define('MINTY_ALLOW_OUTPUT', true);
|
|
|
|
Guard::requireLogin();
|
|
$authorizationService = (new AccessServicesFactory())->createAuthorizationService();
|
|
$userServicesFactory = new UserServicesFactory();
|
|
$userAccountService = $userServicesFactory->createUserAccountService();
|
|
$userAvatarService = $userServicesFactory->createUserAvatarService();
|
|
|
|
$uuid = trim((string) ($_GET['uuid'] ?? ''));
|
|
$size = isset($_GET['size']) ? (int) $_GET['size'] : null;
|
|
if (!$userAvatarService->isValidUuid($uuid)) {
|
|
http_response_code(404);
|
|
return;
|
|
}
|
|
|
|
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
|
|
$user = $uuid !== '' ? $userAccountService->findByUuid($uuid) : null;
|
|
$userId = (int) ($user['id'] ?? 0);
|
|
$decision = $authorizationService->authorize(UserAuthorizationPolicy::ABILITY_ADMIN_USERS_AVATAR_VIEW, [
|
|
'actor_user_id' => $currentUserId,
|
|
'target_user_id' => $userId,
|
|
]);
|
|
if (!$decision->isAllowed()) {
|
|
http_response_code(403);
|
|
return;
|
|
}
|
|
|
|
$path = $userAvatarService->findAvatarPath($uuid, $size);
|
|
if (!$path || !is_file($path)) {
|
|
http_response_code(404);
|
|
return;
|
|
}
|
|
|
|
$mime = $userAvatarService->detectMime($path);
|
|
header('Content-Type: ' . $mime);
|
|
header('X-Content-Type-Options: nosniff');
|
|
header('Content-Security-Policy: sandbox');
|
|
header('Cache-Control: private, max-age=300');
|
|
header('Content-Length: ' . filesize($path));
|
|
readfile($path);
|