소스 검색

fix: some traits errors and small improvements

Denis 4 달 전
부모
커밋
9c0ea8059b
6개의 변경된 파일149개의 추가작업 그리고 29개의 파일을 삭제
  1. 109 0
      _ide_helper.php
  2. 2 2
      app/Commands/TestWebsocketEvent.php
  3. 9 1
      app/Http/Controllers/AuthController.php
  4. 18 15
      app/Traits/RemoveArchiveS3.php
  5. 11 10
      app/Traits/UploadsBase64Image.php
  6. 0 1
      routes/console.php

+ 109 - 0
_ide_helper.php

@@ -22910,6 +22910,115 @@ public static function dropNestedSet()
             return \Illuminate\Database\Schema\Blueprint::dropNestedSet();
         }
 
+        /**
+         * @see \Pgvector\Laravel\Schema::register()
+         * @param string $column
+         * @param mixed|null $dimensions
+         * @return \Illuminate\Database\Schema\ColumnDefinition
+         * @static
+         */
+        public static function halfvec($column, $dimensions = null)
+        {
+            return \Illuminate\Database\Schema\Blueprint::halfvec($column, $dimensions);
+        }
+
+        /**
+         * @see \Pgvector\Laravel\Schema::register()
+         * @param string $column
+         * @param mixed|null $length
+         * @return \Illuminate\Database\Schema\ColumnDefinition
+         * @static
+         */
+        public static function bit($column, $length = null)
+        {
+            return \Illuminate\Database\Schema\Blueprint::bit($column, $length);
+        }
+
+        /**
+         * @see \Pgvector\Laravel\Schema::register()
+         * @param string $column
+         * @param mixed|null $dimensions
+         * @return \Illuminate\Database\Schema\ColumnDefinition
+         * @static
+         */
+        public static function sparsevec($column, $dimensions = null)
+        {
+            return \Illuminate\Database\Schema\Blueprint::sparsevec($column, $dimensions);
+        }
+
+            }
+    }
+
+namespace Illuminate\Database\Schema\Grammars {
+    /**
+     */
+    class PostgresGrammar extends \Illuminate\Database\Schema\Grammars\Grammar {
+            }
+    /**
+     */
+    class Grammar extends \Illuminate\Database\Grammar {
+            }
+    }
+
+namespace Illuminate\Database {
+    /**
+     */
+    class Grammar {
+        /**
+         * @see \Pgvector\Laravel\Schema::register()
+         * @param \Illuminate\Database\Schema\ColumnDefinition $column
+         * @return string
+         * @static
+         */
+        public static function typeVector($column)
+        {
+            return \Illuminate\Database\Grammar::typeVector($column);
+        }
+
+        /**
+         * @see \Pgvector\Laravel\Schema::register()
+         * @param \Illuminate\Database\Schema\ColumnDefinition $column
+         * @return string
+         * @static
+         */
+        public static function typeHalfvec($column)
+        {
+            return \Illuminate\Database\Grammar::typeHalfvec($column);
+        }
+
+        /**
+         * @see \Pgvector\Laravel\Schema::register()
+         * @param \Illuminate\Database\Schema\ColumnDefinition $column
+         * @return string
+         * @static
+         */
+        public static function typeBit($column)
+        {
+            return \Illuminate\Database\Grammar::typeBit($column);
+        }
+
+        /**
+         * @see \Pgvector\Laravel\Schema::register()
+         * @param \Illuminate\Database\Schema\ColumnDefinition $column
+         * @return string
+         * @static
+         */
+        public static function typeSparsevec($column)
+        {
+            return \Illuminate\Database\Grammar::typeSparsevec($column);
+        }
+
+            }
+    }
+
+namespace Illuminate\Database\Query\Grammars {
+    /**
+     */
+    class PostgresGrammar extends \Illuminate\Database\Query\Grammars\Grammar {
+            }
+    /**
+     */
+    class Grammar extends \Illuminate\Database\Grammar {
             }
     }
 

+ 2 - 2
app/Commands/TestWebsocketEvent.php

@@ -2,7 +2,7 @@
 
 namespace App\Commands;
 
-use App\Broadcasting\DTO\WebsocketEventDataDTO;
+use App\Broadcasting\Entity\WebsocketEventData;
 use App\Broadcasting\Events\WebsocketEvent;
 use Illuminate\Console\Command;
 
@@ -24,7 +24,7 @@ public function handle(): int
                 ? json_decode($this->option('data'), true, 512, JSON_THROW_ON_ERROR)
                 : ['message' => 'Test message'];
 
-            $eventData = WebsocketEventDataDTO::from(
+            $eventData = WebsocketEventData::from(
                 room: $room,
                 data: $data,
                 event: $event

+ 9 - 1
app/Http/Controllers/AuthController.php

@@ -54,8 +54,16 @@ public function logout(): JsonResponse
 
     public function refresh(RefreshTokenRequest $request): JsonResponse
     {
+        $refresh_token = $request->cookie("refresh_token");
+
+        if (is_null($refresh_token)) {
+            return $this->errorResponse(
+                code: 403,
+            )->withoutCookie("refresh_token");
+        }
+
         $result = $this->authService->refresh(
-            $request->cookie("refresh_token"),
+            $refresh_token
         );
 
         if (is_null($result)) {

+ 18 - 15
app/Traits/RemoveArchiveS3.php

@@ -2,31 +2,34 @@
 
 namespace App\Traits;
 
+use Exception;
 use Illuminate\Support\Facades\Storage;
-use Illuminate\Support\Str;
 
 trait RemoveArchiveS3
 {
     /**
-     * Upload a base64 encoded image to S3 and return the URL.
+     * Delete a file and return a boolean if succeded.
      *
-     * @param string $base64Image
-     * @param string $s3Folder
-     * @return string
-     * @throws \Exception
+     * @param string $url
+     * @return bool
+     * @throws \Exception If the file as not found or if the deletion failed.
      */
     public function removeArchiveByUrl(string $url): bool
     {
-        // Extrair o caminho relativo do S3 da URL completa
-        $oldImagePath = parse_url($url, PHP_URL_PATH);
-        $oldImagePath = ltrim($oldImagePath, '/'); // remover a barra inicial
+        // Extrair o caminho relativo da URL completa
+        $imagePath = parse_url($url, PHP_URL_PATH);
+        $imagePath = ltrim($imagePath, '/'); // remover a barra inicial
 
-        // Excluir a imagem antiga do S3
-        if (Storage::disk('s3')->exists($oldImagePath)) {
-            Storage::disk('s3')->delete($oldImagePath);
+        // Excluir a imagem antiga
+        if (Storage::exists($imagePath)) {
+            $success = Storage::delete($imagePath);
+            if ($success) {
+                return true;
+            } else {
+                throw new Exception("Deletion was not possible");
+            }
+        } else {
+            throw new Exception("File not found");
         }
-
-        // Return the URL of the uploaded image
-        return true;
     }
 }

+ 11 - 10
app/Traits/UploadsBase64Image.php

@@ -2,20 +2,21 @@
 
 namespace App\Traits;
 
+use Exception;
 use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Str;
 
 trait UploadsBase64Image
 {
     /**
-     * Upload a base64 encoded image to S3 and return the URL.
+     * Upload a base64 encoded image and return the URL.
      *
      * @param string $base64Image
-     * @param string $s3Folder
+     * @param string $folder
      * @return string
      * @throws \Exception
      */
-    public function uploadBase64Image(string $base64Image, string $s3Folder): string
+    public function uploadBase64Image(string $base64Image, string $folder): string
     {
         // Extract the file extension and base64 data
         if (preg_match('/^data:image\/(\w+);base64,/', $base64Image, $type)) {
@@ -23,28 +24,28 @@ public function uploadBase64Image(string $base64Image, string $s3Folder): string
             $type = strtolower($type[1]); // jpg, png, gif
 
             if (!in_array($type, ['jpg', 'jpeg', 'png', 'gif'])) {
-                throw new \Exception(__('validation.extensions', ['attribute' => __('general.image'), 'values' => 'jpg, jpeg, png, gif']));
+                throw new Exception(__('validation.extensions', ['attribute' => __('general.image'), 'values' => 'jpg, jpeg, png, gif']));
             }
 
             $image = base64_decode($base64Image);
 
             if ($image === false) {
-                throw new \Exception('Base64 decode failed');
+                throw new Exception('Base64 decode failed');
             }
         } else {
-            throw new \Exception('Invalid base64 image format');
+            throw new Exception('Invalid base64 image format');
         }
 
         // Generate a unique filename
         $filename = Str::random(20) . '.' . $type;
 
         // Define the full path where the file will be stored
-        $filePath = $s3Folder . '/' . $filename;
+        $filePath = $folder . '/' . $filename;
 
-        // Save the file to S3
-        Storage::disk('s3')->put($filePath, $image);
+        // Save the file
+        Storage::put($filePath, $image);
 
         // Return the URL of the uploaded image
-        return Storage::disk('s3')->url($filePath);
+        return Storage::url($filePath);
     }
 }

+ 0 - 1
routes/console.php

@@ -29,7 +29,6 @@
 })->purpose('Refresh all permissions and user type permissions');
 
 Artisan::command('websocket:test {room} {--event=test-event} {--data=}', function () {
-    // Pass through all arguments and options to the command class
     $this->call(TestWebsocketEvent::class, [
         'room' => $this->argument('room'),
         '--event' => $this->option('event'),