diff --git a/app/Api/ImageResize.php b/app/Api/ImageResize.php index 8941c18..613164f 100755 --- a/app/Api/ImageResize.php +++ b/app/Api/ImageResize.php @@ -2,8 +2,8 @@ namespace App\Api; +use App\Support\Uploads; use Carbon\Carbon; -use Illuminate\Support\Facades\Storage; use Intervention\Image\Facades\Image as Imagee; class ImageResize @@ -54,8 +54,8 @@ class ImageResize // 3. Upload thumb to S3/MinIO $thumbKey = $this->thumbFolder($type) . '/' . $thumbFilename; - if (env('FILESYSTEM_DISK') === 's3') { - Storage::disk('s3')->put($thumbKey, file_get_contents($tmpThumb)); + if (config('filesystems.default') === 's3') { + Uploads::put($thumbKey, file_get_contents($tmpThumb), 's3'); } else { // Local: move to public/uploads/…/thumbs/… $localDir = public_path(dirname($thumbKey)); diff --git a/app/Http/Controllers/Dashboard/Product/Controller.php b/app/Http/Controllers/Dashboard/Product/Controller.php index 9be23af..fcfcd96 100755 --- a/app/Http/Controllers/Dashboard/Product/Controller.php +++ b/app/Http/Controllers/Dashboard/Product/Controller.php @@ -100,12 +100,19 @@ class Controller extends ExController return view('dashboard.products.store', compact('categories', 'brands', 'colors', 'measurement')); } - $product = $this->dispatchSync(StoreJob::fromRequest($request)); + try { + $product = $this->dispatchSync(StoreJob::fromRequest($request)); - $product->categories()->attach([$request->getCategoryID()]); + $product->categories()->attach([$request->getCategoryID()]); - $this->charSync($product, $request->characteristics); - $this->dispatchSync(new ChildJob($request, $product)); + $this->charSync($product, $request->characteristics); + $this->dispatchSync(new ChildJob($request, $product)); + } catch (Exception $e) { + return Response::json([ + 'status' => false, + 'messages' => $e->getMessage() + ], 500); + } $this->success(trans('admin.messages.created')); diff --git a/app/Http/Controllers/Dashboard/Slider/Controller.php b/app/Http/Controllers/Dashboard/Slider/Controller.php index 73b7d88..bb044c7 100755 --- a/app/Http/Controllers/Dashboard/Slider/Controller.php +++ b/app/Http/Controllers/Dashboard/Slider/Controller.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Dashboard\Slider; use App\Models\Slider; +use App\Support\Uploads; use Illuminate\Http\Request; use App\Http\Controllers\Controller as ExController; use Illuminate\Support\Facades\Storage; @@ -53,7 +54,7 @@ class Controller extends ExController } if ($request->hasFile('image')) { - $path = $request->file('image')->store('uploads/sliders'); + $path = Uploads::store($request->file('image'), 'uploads/sliders'); } else { $path = $slider->image; } @@ -77,7 +78,7 @@ class Controller extends ExController if ($request->hasFile('image')) { - $path = $request->file('image')->store('uploads/sliders'); + $path = Uploads::store($request->file('image'), 'uploads/sliders'); } $this->dispatchSync(StoreJob::fromRequest($request, $path)); diff --git a/app/Http/Requests/Dashboard/Category/Request.php b/app/Http/Requests/Dashboard/Category/Request.php index a8dfe66..7a68998 100755 --- a/app/Http/Requests/Dashboard/Category/Request.php +++ b/app/Http/Requests/Dashboard/Category/Request.php @@ -2,8 +2,8 @@ namespace App\Http\Requests\Dashboard\Category; +use App\Support\Uploads; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; class Request extends FormRequest @@ -44,9 +44,9 @@ class Request extends FormRequest if (env('FILESYSTEM_DISK') == 's3') { $folder = "uploads/categories"; - return (string) $this->file('image')->store($folder); + return Uploads::store($this->file('image'), $folder); } else { - return $this->file('image')->store('uploads/categories', 'local'); + return Uploads::store($this->file('image'), 'uploads/categories', 'local'); } } else { return 'null'; diff --git a/app/Http/Requests/Dashboard/Category/Update.php b/app/Http/Requests/Dashboard/Category/Update.php index ce28007..b885ff4 100755 --- a/app/Http/Requests/Dashboard/Category/Update.php +++ b/app/Http/Requests/Dashboard/Category/Update.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\Dashboard\Category; use App\Models\Category; +use App\Support\Uploads; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; @@ -44,7 +45,7 @@ class Update extends FormRequest { if ($this->hasFile('image')) { Storage::delete($category->image); - return (string) $this->file('image')->store('uploads/categories'); + return Uploads::store($this->file('image'), 'uploads/categories'); } return $category->image; diff --git a/app/Http/Requests/Dashboard/Product/Store.php b/app/Http/Requests/Dashboard/Product/Store.php index 24d4bf3..d7a9fbf 100755 --- a/app/Http/Requests/Dashboard/Product/Store.php +++ b/app/Http/Requests/Dashboard/Product/Store.php @@ -2,9 +2,9 @@ namespace App\Http\Requests\Dashboard\Product; +use App\Support\Uploads; use Carbon\Carbon; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Support\Facades\Storage; use App\Api\ImageResize; class Store extends FormRequest @@ -71,7 +71,7 @@ class Store extends FormRequest { $folder = "uploads/posters/" . Carbon::now()->format('Y/m/d'); - return (string) $this->file('poster')->store($folder); + return Uploads::store($this->file('poster'), $folder); } /** @@ -81,7 +81,7 @@ class Store extends FormRequest { if ($this->hasFile('calc')) { $folder = "uploads/calc/" . Carbon::now()->format('Y/m/d'); - return (string) $this->file('calc')->store($folder); + return Uploads::store($this->file('calc'), $folder); } return null; } @@ -90,7 +90,7 @@ class Store extends FormRequest { if ($this->hasFile('data_sheet')) { $folder = "uploads/datasheet/" . Carbon::now()->format('Y/m/d'); - return (string) $this->file('data_sheet')->store($folder); + return Uploads::store($this->file('data_sheet'), $folder); } return null; @@ -102,7 +102,7 @@ class Store extends FormRequest public function getPosterThumb() { $image = $this->file('poster'); - $tempPath = $image->store('temp', 'public'); + $tempPath = Uploads::store($image, 'temp', 'public'); $resizer = new ImageResize(); return $resizer->resize($tempPath, 322, 'posters', true); diff --git a/app/Http/Requests/Dashboard/Product/Update.php b/app/Http/Requests/Dashboard/Product/Update.php index 7de7a19..c30595e 100755 --- a/app/Http/Requests/Dashboard/Product/Update.php +++ b/app/Http/Requests/Dashboard/Product/Update.php @@ -2,6 +2,7 @@ namespace App\Http\Requests\Dashboard\Product; +use App\Support\Uploads; use Carbon\Carbon; use Illuminate\Foundation\Http\FormRequest; @@ -65,7 +66,7 @@ class Update extends FormRequest if ($this->hasFile('poster')) { Storage::delete($product->poster); $folder = "uploads/posters/" . Carbon::now()->format('Y/m/d'); - return (string) $this->file('poster')->store($folder); + return Uploads::store($this->file('poster'), $folder); } return $product->poster; @@ -81,7 +82,7 @@ class Update extends FormRequest Storage::delete($product->calc); } $folder = "uploads/calc/" . Carbon::now()->format('Y/m/d'); - return (string) $this->file('calc')->store($folder); + return Uploads::store($this->file('calc'), $folder); } return $product->calc; } @@ -93,7 +94,7 @@ class Update extends FormRequest Storage::delete($product->data_sheet); } $folder = "uploads/datasheet/" . Carbon::now()->format('Y/m/d'); - return (string) $this->file('data_sheet')->store($folder); + return Uploads::store($this->file('data_sheet'), $folder); } return $product->data_sheet; @@ -106,7 +107,7 @@ class Update extends FormRequest { if ($this->hasFile('poster')) { Storage::delete($product->poster_thumb); - $tempPath = $this->file('poster')->store('temp', 'public'); + $tempPath = Uploads::store($this->file('poster'), 'temp', 'public'); $resizer = new ImageResize(); return $resizer->resize($tempPath, 322, 'posters', true); } diff --git a/app/Jobs/Dashboard/Product/Child.php b/app/Jobs/Dashboard/Product/Child.php index 4543acc..b41984d 100755 --- a/app/Jobs/Dashboard/Product/Child.php +++ b/app/Jobs/Dashboard/Product/Child.php @@ -4,6 +4,7 @@ namespace App\Jobs\Dashboard\Product; use App\Models\Product; use App\Models\Screen; +use App\Support\Uploads; use Carbon\Carbon; use App\Api\ImageResize; use App\Http\Requests\Dashboard\Product\Store as StoreRequest; @@ -54,10 +55,10 @@ class Child $folder = Carbon::now()->format('Y/m/d'); // Store original - $path = $screen['image']->store("uploads/screens/{$folder}"); + $path = Uploads::store($screen['image'], "uploads/screens/{$folder}"); // Store and resize thumb - $tempPath = $screen['image']->store('temp', 'public'); + $tempPath = Uploads::store($screen['image'], 'temp', 'public'); $thumbPath = $this->image->resize($tempPath, 322, 'screens', true); $this->size = Storage::size($path); diff --git a/app/Jobs/Dashboard/Product/ChildUpdate.php b/app/Jobs/Dashboard/Product/ChildUpdate.php index 7317355..c871479 100755 --- a/app/Jobs/Dashboard/Product/ChildUpdate.php +++ b/app/Jobs/Dashboard/Product/ChildUpdate.php @@ -4,6 +4,7 @@ namespace App\Jobs\Dashboard\Product; use App\Models\Product; use App\Models\Screen; +use App\Support\Uploads; use Carbon\Carbon; use App\Api\ImageResize; @@ -83,10 +84,10 @@ class ChildUpdate $folder = Carbon::now()->format('Y/m/d'); if ($screen['image']) { // 1. Store original (S3 if enabled) - $path = $screen['image']->store("uploads/screens/{$folder}"); + $path = Uploads::store($screen['image'], "uploads/screens/{$folder}"); // 2. Local temp for resizing - $tempPath = $screen['image']->store('temp', 'public'); + $tempPath = Uploads::store($screen['image'], 'temp', 'public'); $thumbPath = $this->image->resize($tempPath, 322, 'screens', true); Screen::create([ @@ -94,7 +95,7 @@ class ChildUpdate 'path_thumb' => $thumbPath, 'name' => basename($path), 'product_id' => $child_id, - 'size' => Storage::disk(env('FILESYSTEM_DISK'))->size($path) + 'size' => Storage::size($path) ]); } } diff --git a/app/Jobs/Dashboard/Product/Screen.php b/app/Jobs/Dashboard/Product/Screen.php index 88689f8..eddda24 100755 --- a/app/Jobs/Dashboard/Product/Screen.php +++ b/app/Jobs/Dashboard/Product/Screen.php @@ -2,6 +2,7 @@ namespace App\Jobs\Dashboard\Product; +use App\Support\Uploads; use Carbon\Carbon; use Illuminate\Support\Arr; use App\Models\Screen as Screens; @@ -38,17 +39,17 @@ class Screen $folder = Carbon::now()->format('Y/m/d'); // 1. Store original (S3 if enabled) - $path = $screen->store("uploads/screens/original/{$folder}"); + $path = Uploads::store($screen, "uploads/screens/original/{$folder}"); // 2. Local temp for resizing - $tempPath = $screen->store('temp', 'public'); + $tempPath = Uploads::store($screen, 'temp', 'public'); $thumb = $this->img->resize($tempPath, 350, 'screens', true); $screens = new Screens(); $screens->name = basename($path); $screens->path = $path; $screens->path_thumb = $thumb; - $screens->size = Storage::disk(env('FILESYSTEM_DISK'))->size($path); + $screens->size = Storage::size($path); $screens->product_id = $this->id; $screens->save(); } diff --git a/app/Support/Uploads.php b/app/Support/Uploads.php new file mode 100644 index 0000000..a29ec32 --- /dev/null +++ b/app/Support/Uploads.php @@ -0,0 +1,32 @@ +store($path, $disk) : $file->store($path); + + if (!$storedPath) { + throw new RuntimeException("File upload failed: {$path}"); + } + + return $storedPath; + } + + public static function put(string $path, string $contents, ?string $disk = null): void + { + $stored = $disk + ? Storage::disk($disk)->put($path, $contents) + : Storage::put($path, $contents); + + if (!$stored) { + throw new RuntimeException("File upload failed: {$path}"); + } + } +} diff --git a/config/filesystems.php b/config/filesystems.php index e3c4daf..0c1eae8 100755 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -66,6 +66,7 @@ return [ 'use_path_style_endpoint' => env('MINIO_USE_PATH_STYLE', true), 'visibility' => 'public', 'signature_version' => 'v4', + 'throw' => true, ], diff --git a/public/vendor/dashboard/app-assets/js/core/app-menu.js b/public/vendor/dashboard/app-assets/js/core/app-menu.js index 04eb8e0..0526561 100755 --- a/public/vendor/dashboard/app-assets/js/core/app-menu.js +++ b/public/vendor/dashboard/app-assets/js/core/app-menu.js @@ -49,6 +49,10 @@ } } menu = document.querySelector('.main-menu-content'); + if (!activeEl || !menu) { + this.obj.update(); + return; + } activeEl = activeEl.getBoundingClientRect().top + menu.scrollTop; // If active element's top position is less than 2/3 (66%) of menu height than do not scroll if (activeEl > parseInt((menu.clientHeight * 2) / 3)) {