refactor(storage): centralize temporary URL generation
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Shared\StorageTest\Services;
|
||||
|
||||
use App\Shared\Storage\Services\TemporaryUrlService;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -10,6 +11,10 @@ use RuntimeException;
|
||||
|
||||
class S3TestService
|
||||
{
|
||||
public function __construct(
|
||||
protected TemporaryUrlService $temporaryUrlService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, int|string|null>
|
||||
*/
|
||||
@@ -44,8 +49,7 @@ class S3TestService
|
||||
'mime_type' => $file->getClientMimeType(),
|
||||
'extension' => $file->extension(),
|
||||
'size' => $file->getSize(),
|
||||
'temporary_url' => $disk->temporaryUrl($path, now()->addMinutes($expiresInMinutes)),
|
||||
'temporary_url_expires_at' => now()->addMinutes($expiresInMinutes)->toIso8601String(),
|
||||
...$this->temporaryUrlService->generate($path, $expiresInMinutes),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -58,16 +62,10 @@ class S3TestService
|
||||
'disk' => 's3',
|
||||
'key' => $path,
|
||||
'path' => $path,
|
||||
'temporary_url' => $this->temporaryUrlForPath($path, $expiresInMinutes),
|
||||
'temporary_url_expires_at' => now()->addMinutes($expiresInMinutes)->toIso8601String(),
|
||||
...$this->temporaryUrlService->generate($path, $expiresInMinutes),
|
||||
];
|
||||
}
|
||||
|
||||
protected function temporaryUrlForPath(string $path, int $expiresInMinutes): string
|
||||
{
|
||||
return Storage::disk('s3')->temporaryUrl($path, now()->addMinutes($expiresInMinutes));
|
||||
}
|
||||
|
||||
protected function normalizeDirectory(?string $directory): string
|
||||
{
|
||||
$directory = trim((string) $directory, '/');
|
||||
|
||||
Reference in New Issue
Block a user