Skip to content

Commit

Permalink
fix: logs, images with extensions (#192)
Browse files Browse the repository at this point in the history
* fix: error logs

* fix: images have an extension
  • Loading branch information
dkarlovi authored Dec 12, 2023
1 parent b74d447 commit e452343
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
framework:
php_errors:
log: true
session:
storage_factory_id: session.storage.factory.mock_file
csrf_protection: ~
3 changes: 3 additions & 0 deletions resources/init/basic/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ services:
image: darthsim/imgproxy:v3
environment:
- IMGPROXY_LOCAL_FILESYSTEM_ROOT=/app
- IMGPROXY_MAX_ANIMATION_FRAMES=60
- IMGPROXY_ENABLE_AVIF_DETECTION=1
- IMGPROXY_ENABLE_WEBP_DETECTION=1
working_dir: /app
ports:
- 8090:8080
Expand Down
6 changes: 5 additions & 1 deletion src/AssetQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ public function flush(?callable $callable = null): array

// TODO: ImgProxy
if ($specification instanceof AssetFetch) {
$response = $this->httpClient->request('GET', $specification->url);
$response = $this->httpClient->request('GET', $specification->url, [
'headers' => [
'Accept' => 'image/webp,image/apng,image/*,*/*;q=0.8',
],
]);
$this->filesystem->mkdir(\dirname($destination));
$handle = fopen($destination, 'w');
if ($handle === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Twig/Extension/ThumbnailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getFunctions(): array
return $url;
}

$path = \dirname($relative).'/'.md5(md5_file($path).$filter);
$path = sprintf('%1$s/%2$s.%3$s.webp', \dirname($relative), pathinfo($relative, \PATHINFO_FILENAME), mb_substr(md5(md5_file($path).$filter), 0, 8));
$this->thumbnailQueue->add(new AssetFetch($url, $path));

return $this->packages->getUrl(ltrim($path, '/'));
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/site/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ services:
image: darthsim/imgproxy:v3
environment:
- IMGPROXY_LOCAL_FILESYSTEM_ROOT=/app
- IMGPROXY_MAX_ANIMATION_FRAMES=60
- IMGPROXY_ENABLE_AVIF_DETECTION=1
- IMGPROXY_ENABLE_WEBP_DETECTION=1
working_dir: /app
ports:
- 8090:8080
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/functional/site/fixtures/en/article/images/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ <h1>Images!</h1>
</tbody>
</table>
<p>This is a database lookup example: Hello World!</p>
<p>This is an asset lookup: /sub/dir/another/content/articles/images/509b6b4c27eb27d81e17c4038e7ad88b</p>
<p><img src="/sub/dir/another/content/articles/images/8514a44ac6072de0665dcd273f694d28" alt="Logo" /></p>
<p>This is an asset lookup: /sub/dir/another/content/articles/images/image.509b6b4c.webp</p>
<p><img src="/sub/dir/another/content/articles/images/image.8514a44a.webp" alt="Logo" /></p>

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/site/fixtures/en/articles/1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose">
<h1>Articles</h1>
<h2><a href="https://example.com/sub/dir/another/en/article/images/">Images!</a></h2>
<p><img src="/sub/dir/another/content/articles/images/200ad8764a311b8ca90c5271eaf73efb"></p>
<p><img src="/sub/dir/another/content/articles/images/image.200ad876.webp"></p>
<p>20.07.2022. 12:35</p>
<h2><a href="https://example.com/sub/dir/another/en/article/lists/">Lists!</a></h2>
<p>19.07.2022. 12:13</p>
Expand Down

0 comments on commit e452343

Please sign in to comment.