From 768508954008536ee19b6272e8d13bec733ec14c Mon Sep 17 00:00:00 2001 From: ncoronel Date: Thu, 27 Aug 2026 12:10:41 -0300 Subject: [PATCH] refactor(storage-test): remove unused S3 test endpoints --- .../Controllers/S3TestController.php | 58 ----------- .../GenerateS3TemporaryUrlRequest.php | 24 ----- .../Requests/StoreS3TestFileRequest.php | 26 ----- .../StorageTest/Services/S3TestService.php | 81 ---------------- .../StorageTest/documentacion/README.md | 23 ----- app/Domains/StorageTest/routes/api.php | 9 -- ...achable-s3-testing.postman_collection.json | 95 ------------------- 7 files changed, 316 deletions(-) delete mode 100644 app/Domains/StorageTest/Controllers/S3TestController.php delete mode 100644 app/Domains/StorageTest/Requests/GenerateS3TemporaryUrlRequest.php delete mode 100644 app/Domains/StorageTest/Requests/StoreS3TestFileRequest.php delete mode 100644 app/Domains/StorageTest/Services/S3TestService.php delete mode 100644 app/Domains/StorageTest/documentacion/README.md delete mode 100644 app/Domains/StorageTest/routes/api.php delete mode 100644 postman/attachable-s3-testing.postman_collection.json diff --git a/app/Domains/StorageTest/Controllers/S3TestController.php b/app/Domains/StorageTest/Controllers/S3TestController.php deleted file mode 100644 index c645947..0000000 --- a/app/Domains/StorageTest/Controllers/S3TestController.php +++ /dev/null @@ -1,58 +0,0 @@ -attachmentService->store( - $request->file('file') ?? (string) $request->validated('file_base64'), - $request->validated('path'), - ); - - $temporaryUrl = $this->s3TestService->generateTemporaryUrl( - $attachment->path, - (int) $request->validated('expires_in_minutes', 10), - ); - - return response()->json( - [ - 'id' => $attachment->id, - 'key' => $attachment->key, - 'path' => $attachment->path, - 'filename' => $attachment->filename, - 'type' => $attachment->type->value, - 'mime_type' => $attachment->mime_type, - 'extension' => $attachment->extension, - 'size' => $attachment->size, - 'temporary_url' => $temporaryUrl['temporary_url'], - 'temporary_url_expires_at' => $temporaryUrl['temporary_url_expires_at'], - ], - 201, - ); - } - - public function temporaryUrl(GenerateS3TemporaryUrlRequest $request): JsonResponse - { - return response()->json( - $this->s3TestService->generateTemporaryUrl( - $request->validated('path'), - (int) $request->validated('expires_in_minutes', 10), - ) - ); - } -} diff --git a/app/Domains/StorageTest/Requests/GenerateS3TemporaryUrlRequest.php b/app/Domains/StorageTest/Requests/GenerateS3TemporaryUrlRequest.php deleted file mode 100644 index b906053..0000000 --- a/app/Domains/StorageTest/Requests/GenerateS3TemporaryUrlRequest.php +++ /dev/null @@ -1,24 +0,0 @@ -> - */ - public function rules(): array - { - return [ - 'path' => ['required', 'string', 'max:2048'], - 'expires_in_minutes' => ['nullable', 'integer', 'min:1', 'max:1440'], - ]; - } -} diff --git a/app/Domains/StorageTest/Requests/StoreS3TestFileRequest.php b/app/Domains/StorageTest/Requests/StoreS3TestFileRequest.php deleted file mode 100644 index d46ea27..0000000 --- a/app/Domains/StorageTest/Requests/StoreS3TestFileRequest.php +++ /dev/null @@ -1,26 +0,0 @@ -> - */ - public function rules(): array - { - return [ - 'file' => ['nullable', 'file', 'max:10240', 'required_without:file_base64'], - 'file_base64' => ['nullable', 'string', 'required_without:file'], - 'path' => ['required', 'string', 'max:2048'], - 'expires_in_minutes' => ['nullable', 'integer', 'min:1', 'max:1440'], - ]; - } -} diff --git a/app/Domains/StorageTest/Services/S3TestService.php b/app/Domains/StorageTest/Services/S3TestService.php deleted file mode 100644 index 5243a85..0000000 --- a/app/Domains/StorageTest/Services/S3TestService.php +++ /dev/null @@ -1,81 +0,0 @@ - - */ - public function storeTestFile( - UploadedFile $file, - ?string $directory = null, - int $expiresInMinutes = 10, - ): array { - $directory = $this->normalizeDirectory($directory); - $disk = Storage::disk('s3'); - $path = $disk->putFile($directory, $file); - - if (! is_string($path) || $path === '') { - Log::error('S3 upload returned an empty path.', [ - 'disk' => 's3', - 'directory' => $directory, - 'original_name' => $file->getClientOriginalName(), - 'mime_type' => $file->getClientMimeType(), - 'size' => $file->getSize(), - ]); - - throw new RuntimeException('No se pudo subir el archivo al disco s3.'); - } - - return [ - 'disk' => 's3', - 'directory' => $directory, - 'key' => $path, - 'path' => $path, - 'filename' => basename($path), - 'original_name' => $file->getClientOriginalName(), - '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(), - ]; - } - - /** - * @return array - */ - public function generateTemporaryUrl(string $path, int $expiresInMinutes = 10): array - { - return [ - 'disk' => 's3', - 'key' => $path, - 'path' => $path, - 'temporary_url' => $this->temporaryUrlForPath($path, $expiresInMinutes), - 'temporary_url_expires_at' => now()->addMinutes($expiresInMinutes)->toIso8601String(), - ]; - } - - 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, '/'); - - if ($directory !== '') { - return $directory; - } - - return 'testing/attachments/'.now()->format('Y/m/d').'/'.Str::uuid(); - } -} diff --git a/app/Domains/StorageTest/documentacion/README.md b/app/Domains/StorageTest/documentacion/README.md deleted file mode 100644 index 09d7138..0000000 --- a/app/Domains/StorageTest/documentacion/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Dominio StorageTest - -## Propósito - -Expone operaciones técnicas para comprobar la escritura en S3 y la generación de URL temporales. - -## Componentes - -- `S3TestController`: recibe solicitudes de carga y URL temporal. -- `S3TestService`: almacena un archivo de prueba y genera el enlace firmado. -- `StoreS3TestFileRequest`: valida la carga. -- `GenerateS3TemporaryUrlRequest`: valida ruta y tiempo de expiración. - -## Endpoints - -Bajo `/storage-test/s3`: - -- `POST /upload`. -- `GET /temporary-url`. - -## Consideraciones - -Es infraestructura de diagnóstico, no una API funcional de archivos. Debe restringirse por entorno o autorización. Para adjuntos de negocio se debe usar el dominio `Attachable`. diff --git a/app/Domains/StorageTest/routes/api.php b/app/Domains/StorageTest/routes/api.php deleted file mode 100644 index ef5ff59..0000000 --- a/app/Domains/StorageTest/routes/api.php +++ /dev/null @@ -1,9 +0,0 @@ -group(function (): void { - Route::post('upload', [S3TestController::class, 'store']); - Route::get('temporary-url', [S3TestController::class, 'temporaryUrl']); -}); diff --git a/postman/attachable-s3-testing.postman_collection.json b/postman/attachable-s3-testing.postman_collection.json deleted file mode 100644 index f7eca10..0000000 --- a/postman/attachable-s3-testing.postman_collection.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "info": { - "_postman_id": "8faefdb8-734a-4262-a3b6-4d49e56ea901", - "name": "Storage Test S3", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "variable": [ - { - "key": "base_url", - "value": "http://127.0.0.1:8000" - }, - { - "key": "expires_in_minutes", - "value": "10" - }, - { - "key": "path", - "value": "" - } - ], - "item": [ - { - "name": "Upload Test File", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "formdata", - "formdata": [ - { - "key": "file", - "type": "file", - "src": [] - }, - { - "key": "directory", - "value": "testing/manual", - "type": "text" - }, - { - "key": "expires_in_minutes", - "value": "{{expires_in_minutes}}", - "type": "text" - } - ] - }, - "url": { - "raw": "{{base_url}}/api/storage-test/s3/upload", - "host": [ - "{{base_url}}" - ], - "path": [ - "api", - "storage-test", - "s3", - "upload" - ] - }, - "description": "Sube un archivo al disco s3 y devuelve el path junto con una temporary_url." - }, - "response": [] - }, - { - "name": "Generate Temporary URL", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{base_url}}/api/storage-test/s3/temporary-url?path={{path}}&expires_in_minutes={{expires_in_minutes}}", - "host": [ - "{{base_url}}" - ], - "path": [ - "api", - "storage-test", - "s3", - "temporary-url" - ], - "query": [ - { - "key": "path", - "value": "{{path}}" - }, - { - "key": "expires_in_minutes", - "value": "{{expires_in_minutes}}" - } - ] - }, - "description": "Genera una URL temporal para un path ya existente en S3." - }, - "response": [] - } - ] -}