mirror of
https://github.com/grocy/grocy.git
synced 2025-10-09 23:56:03 +00:00
Compare commits
2 Commits
8129b6b60b
...
68b4abfac4
Author | SHA1 | Date | |
---|---|---|---|
|
68b4abfac4 | ||
|
1934256f29 |
@@ -11,7 +11,9 @@
|
||||
### Stock
|
||||
|
||||
- Optimized the line plot markers color of the price history chart (product card) (thanks @DeepCoreSystem)
|
||||
- Optimized that when an external barcode lookup plugin returned an image URL without a file extension, the file extension is now determined by the Content-Type header (if any) (thanks @jordy-u for the idea)
|
||||
- External barcode lookup plugin optimizations:
|
||||
- When an image URL without a file extension ist returned, the file extension is now determined by the Content-Type header (if any) (thanks @jordy-u for the idea)
|
||||
- Data URLs for images are now supported (`data:image/png;base64,xxxx`) (thanks @GammaC0de)
|
||||
- Fixed that German Umlauts were removed from product names when looking up a barcode via the built-in Open Food Facts external barcode lookup plugin
|
||||
- Fixed that when using/scanning a barcode on the purchase page with a note attached (which prefills the note field) and when manually selecting another product afterwards, the note of the previously used barcode was incorrectly prefilled again
|
||||
- Fixed that the "next input focus handling" (jumping to the next input after entering a value) didn't work at some places (e.g. after entering a purchased date on the purchase page)
|
||||
|
@@ -628,20 +628,35 @@ class StockService extends BaseService
|
||||
{
|
||||
try
|
||||
{
|
||||
$webClient = new Client();
|
||||
$response = $webClient->request('GET', $pluginOutput['__image_url'], ['headers' => ['User-Agent' => 'Grocy/' . $this->getApplicationService()->GetInstalledVersion()->Version . ' (https://grocy.info)']]);
|
||||
$fileName = $pluginOutput['__barcode'];
|
||||
$fileExtension = pathinfo(parse_url($pluginOutput['__image_url'], PHP_URL_PATH), PATHINFO_EXTENSION);
|
||||
|
||||
// Fallback to Content-Type header if file extension is missing
|
||||
if (strlen($fileExtension) == 0 && $response->hasHeader('Content-Type'))
|
||||
if (preg_match('/^https?:\/\//', $pluginOutput['__image_url']))
|
||||
{
|
||||
$fileExtension = explode('+', explode('/', $response->getHeader('Content-Type')[0])[1])[0];
|
||||
$webClient = new Client();
|
||||
$response = $webClient->request('GET', $pluginOutput['__image_url'], ['headers' => ['User-Agent' => 'Grocy/' . $this->getApplicationService()->GetInstalledVersion()->Version . ' (https://grocy.info)']]);
|
||||
$fileExtension = pathinfo(parse_url($pluginOutput['__image_url'], PHP_URL_PATH), PATHINFO_EXTENSION);
|
||||
|
||||
// Fallback to Content-Type header if file extension is missing
|
||||
if (strlen($fileExtension) == 0 && $response->hasHeader('Content-Type'))
|
||||
{
|
||||
$fileExtension = explode('+', explode('/', $response->getHeader('Content-Type')[0])[1])[0];
|
||||
}
|
||||
|
||||
$imageData = $response->getBody();
|
||||
}
|
||||
elseif (preg_match('/data:image\/(\w+?);base64,([A-Za-z0-9+\/]*={0,2})$/', $pluginOutput['__image_url'], $matches))
|
||||
{
|
||||
$fileExtension = $matches[1];
|
||||
if (!($imageData = base64_decode($matches[2])))
|
||||
{
|
||||
unset($imageData);
|
||||
}
|
||||
}
|
||||
|
||||
$filePath = $fileName . '.' . $fileExtension;
|
||||
file_put_contents($this->getFilesService()->GetFilePath('productpictures', $filePath), $response->getBody());
|
||||
$productData['picture_file_name'] = $filePath;
|
||||
if (!empty($fileExtension) && !empty($imageData))
|
||||
{
|
||||
$fileName = $pluginOutput['__barcode'] . '.' . $fileExtension;
|
||||
file_put_contents($this->getFilesService()->GetFilePath('productpictures', $fileName), $imageData);
|
||||
$productData['picture_file_name'] = $fileName;
|
||||
}
|
||||
}
|
||||
catch (\Exception)
|
||||
{
|
||||
|
Reference in New Issue
Block a user