diff --git a/app/Services/Admin/Finance/Cash/CashTransactionService.php b/app/Services/Admin/Finance/Cash/CashTransactionService.php index 7123552..0bac667 100644 --- a/app/Services/Admin/Finance/Cash/CashTransactionService.php +++ b/app/Services/Admin/Finance/Cash/CashTransactionService.php @@ -201,7 +201,9 @@ private function formatTransaction(CashTransaction $transaction): array return $transaction->toArray() + [ 'receipt_key' => $s3Key, 'receipt_url' => $this->s3Service->getTemporaryUrl($s3Key), - 'receipt_conversion_url' => $this->s3Service->getTemporaryUrl($media->getPath('thumb')), + 'receipt_conversion_url' => $media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($s3Key), ]; } } diff --git a/app/Services/Admin/Finance/ExpenseService.php b/app/Services/Admin/Finance/ExpenseService.php index 2abc05f..f7409e5 100644 --- a/app/Services/Admin/Finance/ExpenseService.php +++ b/app/Services/Admin/Finance/ExpenseService.php @@ -165,10 +165,9 @@ private function formatExpense(Expense $expense): array return $this->s3Service->getTemporaryUrl($s3Key); }); - $conversionCacheKey = "expense_receipt_conversion_{$media->id}"; - $receiptConversionUrl = Cache::remember($conversionCacheKey, now()->addMinutes(55), function () use ($media) { - return $this->s3Service->getTemporaryUrl($media->getPath('thumb')); - }); + $receiptConversionUrl = $media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $receiptUrl; return $expense->toArray() + [ 'receipt_key' => $s3Key, diff --git a/app/Services/Admin/Manage/CuttingService.php b/app/Services/Admin/Manage/CuttingService.php index 0df9cdf..bfbb98b 100644 --- a/app/Services/Admin/Manage/CuttingService.php +++ b/app/Services/Admin/Manage/CuttingService.php @@ -58,7 +58,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); $cutting->photo_conversion_urls = $cuttingMedia->map( - fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + fn ($media) => $media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); }); @@ -84,7 +86,9 @@ public function getMaterials(Cutting $cutting): Collection ? $this->s3Service->getTemporaryUrl($media->getPath()) : null; $material->rawMaterialPrice->photo_conversion_url = $media - ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + ? ($media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath())) : null; }); } @@ -124,7 +128,9 @@ public function getForShow(Cutting $cutting): array fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); $cutting->photo_conversion_urls = $cuttingMedia->map( - fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + fn ($media) => $media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); $cutting->cuttingMaterials->each(function (CuttingMaterial $material) { @@ -134,7 +140,9 @@ public function getForShow(Cutting $cutting): array ? $this->s3Service->getTemporaryUrl($media->getPath()) : null; $material->rawMaterialPrice->photo_conversion_url = $media - ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + ? ($media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath())) : null; } }); diff --git a/app/Services/Admin/Manage/PurchaseService.php b/app/Services/Admin/Manage/PurchaseService.php index 4823de0..a85b8ab 100644 --- a/app/Services/Admin/Manage/PurchaseService.php +++ b/app/Services/Admin/Manage/PurchaseService.php @@ -56,7 +56,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); $purchase->photo_conversion_urls = $purchaseMedia->map( - fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + fn ($media) => $media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); }); @@ -80,7 +82,9 @@ public function getItems(Purchase $purchase): Collection ? $this->s3Service->getTemporaryUrl($media->getPath()) : null; $item->rawMaterialPrice->photo_conversion_url = $media - ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + ? ($media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath())) : null; }); } diff --git a/app/Services/Admin/Manage/RestockService.php b/app/Services/Admin/Manage/RestockService.php index 4c5bfc6..665b775 100644 --- a/app/Services/Admin/Manage/RestockService.php +++ b/app/Services/Admin/Manage/RestockService.php @@ -52,7 +52,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); $restock->photo_conversion_urls = $restockMedia->map( - fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + fn ($media) => $media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath()) )->toArray(); }); @@ -76,7 +78,9 @@ public function getItems(Restock $restock): \Illuminate\Support\Collection ? $this->s3Service->getTemporaryUrl($media->getPath()) : null; $item->productVariant->photo_conversion_url = $media - ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + ? ($media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath())) : null; }); } diff --git a/app/Services/Admin/Manage/TransactionService.php b/app/Services/Admin/Manage/TransactionService.php index 49466ab..117c8a1 100644 --- a/app/Services/Admin/Manage/TransactionService.php +++ b/app/Services/Admin/Manage/TransactionService.php @@ -87,7 +87,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = ? $this->s3Service->getTemporaryUrl($orderMedia->getPath()) : null; $order->photo_conversion_url = $orderMedia - ? $this->s3Service->getTemporaryUrl($orderMedia->getPath('thumb')) + ? ($orderMedia->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($orderMedia->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($orderMedia->getPath())) : null; $order->profit = $order->total_amount - $order->cogs; @@ -150,7 +152,9 @@ public function getItems(Order $order): \Illuminate\Support\Collection ? $this->s3Service->getTemporaryUrl($media->getPath()) : null; $item->productVariant->photo_conversion_url = $media - ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + ? ($media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath())) : null; }); } diff --git a/app/Services/Admin/Master/Product/ProductService.php b/app/Services/Admin/Master/Product/ProductService.php index ed16ded..357a508 100644 --- a/app/Services/Admin/Master/Product/ProductService.php +++ b/app/Services/Admin/Master/Product/ProductService.php @@ -74,7 +74,11 @@ public function getVariants(Product $product): Collection ->each(function (ProductVariant $variant) { $media = $variant->getMedia('images'); $variant->photo_urls = $media->map(fn ($m) => $this->s3Service->getTemporaryUrl($m->getPath()))->toArray(); - $variant->photo_conversion_urls = $media->map(fn ($m) => $this->s3Service->getTemporaryUrl($m->getPath('thumb')))->toArray(); + $variant->photo_conversion_urls = $media->map( + fn ($m) => $m->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($m->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($m->getPath()) + )->toArray(); }); } diff --git a/app/Services/Admin/Master/RawMaterial/RawMaterialService.php b/app/Services/Admin/Master/RawMaterial/RawMaterialService.php index a436b63..a2dda13 100644 --- a/app/Services/Admin/Master/RawMaterial/RawMaterialService.php +++ b/app/Services/Admin/Master/RawMaterial/RawMaterialService.php @@ -65,7 +65,9 @@ public function getVariants(RawMaterial $rawMaterial): Collection $media = $price->getFirstMedia('images'); if ($media) { $price->photo_url = $this->s3Service->getTemporaryUrl($media->getPath()); - $price->photo_conversion_url = $this->s3Service->getTemporaryUrl($media->getPath('thumb')); + $price->photo_conversion_url = $media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath()); } else { $price->photo_url = null; $price->photo_conversion_url = null; diff --git a/app/Services/Admin/Master/RawMaterial/RawMaterialVariantService.php b/app/Services/Admin/Master/RawMaterial/RawMaterialVariantService.php index 015aa1a..0edb7ec 100644 --- a/app/Services/Admin/Master/RawMaterial/RawMaterialVariantService.php +++ b/app/Services/Admin/Master/RawMaterial/RawMaterialVariantService.php @@ -37,7 +37,9 @@ public function getForCutting(): array ? $this->s3Service->getTemporaryUrl($media->getPath()) : null; $price->photo_conversion_url = $media - ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + ? ($media->getGeneratedConversions()->contains('thumb') + ? $this->s3Service->getTemporaryUrl($media->getPath('thumb')) + : $this->s3Service->getTemporaryUrl($media->getPath())) : null; }); })