Handle image URLs with query parameters returned from an external barcode lookup plugin

This commit is contained in:
Bernd Bestel
2025-03-04 20:40:48 +01:00
parent 46253c455f
commit 2a3e23ded4
2 changed files with 2 additions and 1 deletions

View File

@@ -13,6 +13,7 @@
- Optimizations in the built-in Open Food Facts external barcode lookup plugin:
- A provided but empty localized product name is now ignored
- Non-ASCII characters in product names are now ignored (e.g. line breaks caused problems)
- Optimized that when an external barcode lookup plugin returned an image URL with query parameters, an invalid picture (file name) was added to the created product
### Shopping list

View File

@@ -626,7 +626,7 @@ class StockService extends BaseService
{
$webClient = new Client();
$response = $webClient->request('GET', $pluginOutput['__image_url'], ['headers' => ['User-Agent' => 'Grocy/' . $this->getApplicationService()->GetInstalledVersion()->Version . ' (https://grocy.info)']]);
$fileName = $pluginOutput['__barcode'] . '.' . pathinfo($pluginOutput['__image_url'], PATHINFO_EXTENSION);
$fileName = $pluginOutput['__barcode'] . '.' . pathinfo(parse_url($pluginOutput['__image_url'], PHP_URL_PATH), PATHINFO_EXTENSION);
file_put_contents($this->getFilesService()->GetFilePath('productpictures', $fileName), $response->getBody());
$productData['picture_file_name'] = $fileName;
}