Skip to content

Commit

Permalink
Merge branch '2.0' into 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Oct 29, 2018
2 parents 8494ed6 + 76ae3a8 commit a327e0b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/FileStorage/Filesystems/LocalFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Zhiyi\Plus\FileStorage\FileMetaInterface;
use Zhiyi\Plus\FileStorage\ResourceInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;

class LocalFilesystem implements FilesystemInterface
Expand Down Expand Up @@ -81,6 +82,7 @@ public function meta(ResourceInterface $resource): FileMetaInterface
*/
public function response(ResourceInterface $resource, ?string $rule = null): Response
{
$realPath = $this->filesystem->path($resource->getPath());
if ($this->meta($resource)->hasImage()) {
$rule = new Local\RuleParser($rule);
if (
Expand All @@ -93,13 +95,12 @@ public function response(ResourceInterface $resource, ?string $rule = null): Res
return $this->filesystem->response($resource->getPath());
}

$pathinfo = \League\Flysystem\Util::pathinfo($resource->getPath());
$pathinfo = \League\Flysystem\Util::pathinfo($realPath);
$cachePath = sprintf('%s/%s/%s.%s', $pathinfo['dirname'], $pathinfo['filename'], $rule->getFilename(), $pathinfo['extension']);
if ($this->filesystem->has($cachePath)) {
return $this->filesystem->response($cachePath);
}

$realPath = $this->filesystem->path($resource->getPath());
$image = Image::make($realPath);
$image->blur($rule->getBlur());
if (($image->width() > $rule->getWidth() || $image->height() > $rule->getHeight()) && ($rule->getWidth() || $rule->getHeight())) {
Expand All @@ -114,7 +115,7 @@ public function response(ResourceInterface $resource, ?string $rule = null): Res
return $image->response();
}

return $this->filesystem->response($resource->getPath());
return new BinaryFileResponse($realPath);
}

/**
Expand Down

0 comments on commit a327e0b

Please sign in to comment.