feat: update photo conversion URL handling across services to check for generated conversions before retrieving URLs
This commit is contained in:
parent
0998c81803
commit
3535480266
@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
});
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user