feat: ship creator journey v2 and profile updates
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Services\Uploads;
|
||||
use App\DTOs\Uploads\UploadStoredFile;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use RuntimeException;
|
||||
@@ -34,9 +35,10 @@ final class UploadStorageService
|
||||
{
|
||||
$path = $this->sectionPath($section);
|
||||
|
||||
if (! File::exists($path)) {
|
||||
File::makeDirectory($path, 0755, true);
|
||||
}
|
||||
$this->ensureDirectoryExists($path, [
|
||||
'section' => $section,
|
||||
'storage_root' => rtrim((string) config('uploads.storage_root'), DIRECTORY_SEPARATOR),
|
||||
]);
|
||||
|
||||
return $path;
|
||||
}
|
||||
@@ -75,9 +77,11 @@ final class UploadStorageService
|
||||
$segments = $this->hashSegments($hash);
|
||||
$dir = $this->sectionPath($section) . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $segments);
|
||||
|
||||
if (! File::exists($dir)) {
|
||||
File::makeDirectory($dir, 0755, true);
|
||||
}
|
||||
$this->ensureDirectoryExists($dir, [
|
||||
'section' => $section,
|
||||
'hash' => $hash,
|
||||
'segments' => $segments,
|
||||
]);
|
||||
|
||||
return $dir;
|
||||
}
|
||||
@@ -87,9 +91,12 @@ final class UploadStorageService
|
||||
$segments = $this->hashSegments($hash);
|
||||
$dir = $this->localOriginalsRoot() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $segments);
|
||||
|
||||
if (! File::exists($dir)) {
|
||||
File::makeDirectory($dir, 0755, true);
|
||||
}
|
||||
$this->ensureDirectoryExists($dir, [
|
||||
'section' => 'local_originals',
|
||||
'hash' => $hash,
|
||||
'segments' => $segments,
|
||||
'local_originals_root' => $this->localOriginalsRoot(),
|
||||
]);
|
||||
|
||||
return $dir;
|
||||
}
|
||||
@@ -219,6 +226,37 @@ final class UploadStorageService
|
||||
return is_array($matches) && count($matches) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $context
|
||||
*/
|
||||
private function ensureDirectoryExists(string $path, array $context = []): void
|
||||
{
|
||||
if (File::exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parent = dirname($path);
|
||||
|
||||
try {
|
||||
File::makeDirectory($path, 0755, true);
|
||||
} catch (\Throwable $exception) {
|
||||
Log::error('Upload storage directory creation failed.', array_merge($context, [
|
||||
'path' => $path,
|
||||
'parent' => $parent,
|
||||
'path_exists' => File::exists($path),
|
||||
'parent_exists' => File::exists($parent),
|
||||
'parent_is_directory' => File::isDirectory($parent),
|
||||
'parent_is_writable' => is_writable($parent),
|
||||
'storage_root_config' => (string) config('uploads.storage_root'),
|
||||
'local_originals_root_config' => (string) config('uploads.local_originals_root'),
|
||||
'exception_class' => $exception::class,
|
||||
'exception_message' => $exception->getMessage(),
|
||||
]));
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
private function safeExtension(UploadedFile $file): string
|
||||
{
|
||||
$extension = (string) $file->guessExtension();
|
||||
|
||||
Reference in New Issue
Block a user