diff --git a/app/AlbumSources/AmazonS3Source.php b/app/AlbumSources/AmazonS3Source.php index 9ac3164..948c534 100644 --- a/app/AlbumSources/AmazonS3Source.php +++ b/app/AlbumSources/AmazonS3Source.php @@ -4,9 +4,10 @@ namespace App\AlbumSources; use App\Helpers\MiscHelper; use App\Photo; -use Guzzle\Http\EntityBody; -use Guzzle\Http\Exception\ClientErrorResponseException; +use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Psr7\Stream; use Illuminate\Support\Facades\Log; +use function GuzzleHttp\Psr7\stream_for; class AmazonS3Source extends AlbumSourceBase implements IAlbumSource, IAnalysisQueueSource { @@ -37,7 +38,7 @@ class AmazonS3Source extends AlbumSourceBase implements IAlbumSource, IAnalysisQ 'Key' => $fileToDelete ]); } - catch (ClientErrorResponseException $ex) + catch (GuzzleException $ex) { // Don't worry if the file no longer exists Log::warning('Failed deleting image from S3.', ['error' => $ex->getMessage(), 'path' => $fileToDelete]); @@ -61,7 +62,7 @@ class AmazonS3Source extends AlbumSourceBase implements IAlbumSource, IAnalysisQ 'Key' => $this->getPathToPhoto($photo, $thumbnail) ]); } - catch (ClientErrorResponseException $ex) + catch (GuzzleException $ex) { // Don't worry if the file no longer exists Log::warning('Failed deleting image from S3.', ['error' => $ex->getMessage(), 'path' => $photoPath]); @@ -91,7 +92,7 @@ class AmazonS3Source extends AlbumSourceBase implements IAlbumSource, IAnalysisQ * Fetches the contents of a thumbnail for a photo. * @param Photo $photo Photo to fetch the thumbnail for. * @param string $thumbnail Thumbnail to fetch (or null to fetch the original.) - * @return EntityBody + * @return Stream */ public function fetchPhotoContent(Photo $photo, $thumbnail = null) { @@ -105,7 +106,7 @@ class AmazonS3Source extends AlbumSourceBase implements IAlbumSource, IAnalysisQ 'SaveAs' => $tempFile ]); - return EntityBody::factory(fopen($tempFile, 'r+')); + return stream_for(fopen($tempFile, 'r+')); } finally { diff --git a/app/AlbumSources/BackblazeB2Source.php b/app/AlbumSources/BackblazeB2Source.php index b206c1a..2058bfc 100644 --- a/app/AlbumSources/BackblazeB2Source.php +++ b/app/AlbumSources/BackblazeB2Source.php @@ -6,8 +6,9 @@ use App\BackblazeB2FileIdCache; use App\Photo; use App\Services\BackblazeB2Service; use App\Storage; -use Guzzle\Http\EntityBody; +use GuzzleHttp\Psr7\Stream; use Illuminate\Support\Facades\Log; +use function GuzzleHttp\Psr7\stream_for; class BackblazeB2Source extends AlbumSourceBase implements IAlbumSource { @@ -67,7 +68,7 @@ class BackblazeB2Source extends AlbumSourceBase implements IAlbumSource * Fetches the contents of a thumbnail for a photo. * @param Photo $photo Photo to fetch the thumbnail for. * @param string $thumbnail Thumbnail to fetch (or null to fetch the original.) - * @return EntityBody + * @return Stream */ public function fetchPhotoContent(Photo $photo, $thumbnail = null) { @@ -78,12 +79,10 @@ class BackblazeB2Source extends AlbumSourceBase implements IAlbumSource $b2Cache = $this->getB2FileFromCache($pathOnStorage); if (is_null($b2Cache)) { - return EntityBody::fromString(''); + return stream_for(''); } - return EntityBody::fromString( - $this->getClient()->downloadFile($b2Cache->b2_file_id) - ); + return stream_for($this->getClient()->downloadFile($b2Cache->b2_file_id)); } /** diff --git a/app/AlbumSources/DropboxSource.php b/app/AlbumSources/DropboxSource.php index 2b67ea9..6098826 100644 --- a/app/AlbumSources/DropboxSource.php +++ b/app/AlbumSources/DropboxSource.php @@ -4,7 +4,8 @@ namespace App\AlbumSources; use App\Photo; use App\Services\DropboxService; -use Guzzle\Http\EntityBody; +use GuzzleHttp\Psr7\Stream; +use function GuzzleHttp\Psr7\stream_for; class DropboxSource extends AlbumSourceBase implements IAlbumSource { @@ -37,13 +38,13 @@ class DropboxSource extends AlbumSourceBase implements IAlbumSource * Fetches the contents of a thumbnail for a photo. * @param Photo $photo Photo to fetch the thumbnail for. * @param string $thumbnail Thumbnail to fetch (or null to fetch the original.) - * @return EntityBody + * @return Stream */ public function fetchPhotoContent(Photo $photo, $thumbnail = null) { $pathOnStorage = $this->getPathToPhoto($photo, $thumbnail); - return EntityBody::fromString($this->getClient()->downloadFile($pathOnStorage)); + return stream_for($this->getClient()->downloadFile($pathOnStorage)); } /** diff --git a/app/AlbumSources/IAlbumSource.php b/app/AlbumSources/IAlbumSource.php index aecce32..f96e8a7 100644 --- a/app/AlbumSources/IAlbumSource.php +++ b/app/AlbumSources/IAlbumSource.php @@ -5,7 +5,7 @@ namespace App\AlbumSources; use App\Album; use App\Photo; use App\Storage; -use Guzzle\Http\EntityBody; +use GuzzleHttp\Psr7\Stream; interface IAlbumSource { @@ -27,7 +27,7 @@ interface IAlbumSource * Fetches the contents of a thumbnail for a photo. * @param Photo $photo Photo to fetch the thumbnail for. * @param string $thumbnail Thumbnail to fetch (or null to fetch the original.) - * @return EntityBody + * @return Stream */ function fetchPhotoContent(Photo $photo, $thumbnail = null); diff --git a/app/AlbumSources/LocalFilesystemSource.php b/app/AlbumSources/LocalFilesystemSource.php index fae811b..7fd012d 100644 --- a/app/AlbumSources/LocalFilesystemSource.php +++ b/app/AlbumSources/LocalFilesystemSource.php @@ -5,8 +5,9 @@ namespace App\AlbumSources; use App\Helpers\FileHelper; use App\Helpers\MiscHelper; use App\Photo; -use Guzzle\Http\EntityBody; +use GuzzleHttp\Psr7\Stream; use Symfony\Component\HttpFoundation\File\File; +use function GuzzleHttp\Psr7\stream_for; /** * Driver for managing files on the local filesystem. @@ -37,7 +38,7 @@ class LocalFilesystemSource extends AlbumSourceBase implements IAlbumSource, IAn * Fetches the contents of a thumbnail for a photo. * @param Photo $photo Photo to fetch the thumbnail for. * @param string $thumbnail Thumbnail to fetch (or null to fetch the original.) - * @return EntityBody + * @return Stream */ public function fetchPhotoContent(Photo $photo, $thumbnail = null) { @@ -50,7 +51,7 @@ class LocalFilesystemSource extends AlbumSourceBase implements IAlbumSource, IAn 'r+' ); - return EntityBody::factory($fh); + return stream_for($fh); } public function getName() diff --git a/app/AlbumSources/OpenStackSource.php b/app/AlbumSources/OpenStackSource.php index d3b99ee..9b09b7c 100644 --- a/app/AlbumSources/OpenStackSource.php +++ b/app/AlbumSources/OpenStackSource.php @@ -3,12 +3,11 @@ namespace App\AlbumSources; use App\Photo; -use Guzzle\Http\EntityBody; -use Guzzle\Http\Exception\ClientErrorResponseException; +use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Psr7\Stream; use Illuminate\Support\Facades\Log; -use OpenCloud\ObjectStore\Exception\ObjectNotFoundException; -use OpenCloud\OpenStack; -use Symfony\Component\HttpFoundation\File\File; +use OpenStack\OpenStack; +use function GuzzleHttp\Psr7\stream_for; /** * Driver for managing files on an OpenStack Keystone+Swift compatible platform. @@ -40,7 +39,7 @@ class OpenStackSource extends AlbumSourceBase implements IAlbumSource { $this->getContainer()->deleteObject($photoPath); } - catch (ClientErrorResponseException $ex) + catch (GuzzleException $ex) { // Don't worry if the file no longer exists Log::warning('Failed deleting image from OpenStack.', ['error' => $ex->getMessage(), 'path' => $photoPath]); @@ -51,13 +50,13 @@ class OpenStackSource extends AlbumSourceBase implements IAlbumSource * Fetches the contents of a thumbnail for a photo. * @param Photo $photo Photo to fetch the thumbnail for. * @param string $thumbnail Thumbnail to fetch (or null to fetch the original.) - * @return EntityBody + * @return Stream */ public function fetchPhotoContent(Photo $photo, $thumbnail = null) { $object = $this->getContainer()->getObject($this->getPathToPhoto($photo, $thumbnail)); - return $object->getContent(); + return stream_for($object->getContent()); } /** diff --git a/app/AlbumSources/RackspaceSource.php b/app/AlbumSources/RackspaceSource.php index bcb42ee..62e7277 100644 --- a/app/AlbumSources/RackspaceSource.php +++ b/app/AlbumSources/RackspaceSource.php @@ -3,8 +3,6 @@ namespace App\AlbumSources; use App\Photo; -use App\Storage; -use OpenCloud\Rackspace; class RackspaceSource extends OpenStackSource { diff --git a/app/Http/Controllers/Gallery/PhotoController.php b/app/Http/Controllers/Gallery/PhotoController.php index 98a3eb8..334f348 100644 --- a/app/Http/Controllers/Gallery/PhotoController.php +++ b/app/Http/Controllers/Gallery/PhotoController.php @@ -6,17 +6,15 @@ use App\Album; use App\Facade\Theme; use App\Facade\UserConfig; use App\Helpers\DbHelper; -use App\Helpers\MiscHelper; -use app\Http\Controllers\Admin\AlbumController; use App\Http\Controllers\Controller; -use App\Http\Middleware\VerifyCsrfToken; use App\Photo; use App\VisitorHit; -use Guzzle\Http\Mimetypes; +use GuzzleHttp\Psr7\Stream; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Gate; use Symfony\Component\HttpFoundation\Request; +use function GuzzleHttp\Psr7\mimetype_from_extension; class PhotoController extends Controller { @@ -71,8 +69,9 @@ class PhotoController extends Controller }); } + /** @var Stream $photoStream */ $photoStream = $album->getAlbumSource()->fetchPhotoContent($photo, $thumbnail); - $mimeType = Mimetypes::getInstance()->fromFilename($photo->storage_file_name); + $mimeType = mimetype_from_extension(pathinfo($photo->storage_file_name, PATHINFO_EXTENSION)); return response()->stream( function() use ($photoStream) @@ -81,7 +80,7 @@ class PhotoController extends Controller }, 200, [ - 'Content-Length' => $photoStream->getContentLength(), + 'Content-Length' => strlen($photoStream->getContents()), 'Content-Type' => $mimeType ] ); diff --git a/app/Services/PhotoService.php b/app/Services/PhotoService.php index 59055fd..6dbcb11 100644 --- a/app/Services/PhotoService.php +++ b/app/Services/PhotoService.php @@ -6,12 +6,10 @@ use App\Album; use App\AlbumSources\IAlbumSource; use App\AlbumSources\IAnalysisQueueSource; use App\Helpers\AnalysisQueueHelper; -use App\Helpers\FileHelper; use App\Helpers\ImageHelper; use App\Helpers\MiscHelper; use App\Helpers\ThemeHelper; use App\Photo; -use Symfony\Component\HttpFoundation\File\File; class PhotoService { @@ -207,7 +205,7 @@ class PhotoService $stream = $this->albumSource->fetchPhotoContent($this->photo); $stream->rewind(); - while (!$stream->feof()) + while (!$stream->eof()) { fwrite($photoHandle, $stream->read(4096)); } @@ -326,7 +324,7 @@ class PhotoService $stream = $this->albumSource->fetchPhotoContent($this->photo); $stream->rewind(); - while (!$stream->feof()) + while (!$stream->eof()) { fwrite($photoHandle, $stream->read(4096)); } diff --git a/composer.json b/composer.json index 5f90ee5..13e17ba 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "ext-json": "*", "aws/aws-sdk-php": "^3.134", "doctrine/dbal": "^2.5", + "guzzlehttp/guzzle": "^6.5", "laravel/framework": "^6.0", "laravel/socialite": "^4.3", "php-amqplib/php-amqplib": "^2.9", diff --git a/composer.lock b/composer.lock index f1379b0..41a6105 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "62c34970835f89cbd6bb144d978a42c0", + "content-hash": "9a11d044f41aef4c08fcddf00fd6f7ed", "packages": [ { "name": "aws/aws-sdk-php",