Upload beautify

This commit is contained in:
2026-02-14 15:14:12 +01:00
parent e129618910
commit 79192345e3
249 changed files with 24436 additions and 1021 deletions

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace App\Services\Uploads;
use App\Repositories\Uploads\UploadSessionRepository;
use Illuminate\Support\Facades\File;
final class UploadStatusService
{
public function __construct(
private readonly UploadSessionRepository $sessions,
private readonly UploadStorageService $storage
)
{
}
public function get(string $sessionId): array
{
$session = $this->sessions->getOrFail($sessionId);
$receivedBytes = $this->safeFileSize($session->tempPath);
return [
'session_id' => $session->id,
'status' => $session->status,
'progress' => $session->progress,
'failure_reason' => $session->failureReason,
'user_id' => $session->userId,
'received_bytes' => $receivedBytes,
];
}
private function safeFileSize(string $path): int
{
$tmpRoot = $this->storage->sectionPath('tmp');
$realRoot = realpath($tmpRoot);
$realPath = realpath($path);
if (! $realRoot || ! $realPath || strpos($realPath, $realRoot) !== 0) {
return 0;
}
if (! File::exists($realPath)) {
return 0;
}
return (int) File::size($realPath);
}
}