Skip to content

Commit 76ae3a8

Browse files
committed
fix(file-storage): 本地驱动不支持视频在线播放问题
1 parent 99e4e8a commit 76ae3a8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/FileStorage/Filesystems/LocalFilesystem.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Zhiyi\Plus\FileStorage\FileMetaInterface;
3232
use Zhiyi\Plus\FileStorage\ResourceInterface;
3333
use Symfony\Component\HttpFoundation\Response;
34+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
3435
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
3536

3637
class LocalFilesystem implements FilesystemInterface
@@ -81,6 +82,7 @@ public function meta(ResourceInterface $resource): FileMetaInterface
8182
*/
8283
public function response(ResourceInterface $resource, ?string $rule = null): Response
8384
{
85+
$realPath = $this->filesystem->path($resource->getPath());
8486
if ($this->meta($resource)->hasImage()) {
8587
$rule = new Local\RuleParser($rule);
8688
if (
@@ -93,13 +95,12 @@ public function response(ResourceInterface $resource, ?string $rule = null): Res
9395
return $this->filesystem->response($resource->getPath());
9496
}
9597

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

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

117-
return $this->filesystem->response($resource->getPath());
118+
return new BinaryFileResponse($realPath);
118119
}
119120

120121
/**

0 commit comments

Comments
 (0)