]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Photo.php
Add suggestions
[friendica.git] / src / Module / Photo.php
index e669de8a3dcc04dd5059db288a2460e5d9a4b306..9d2d31b45da02b6958f1956ab5714bda454d583d 100644 (file)
@@ -30,7 +30,11 @@ use Friendica\Model\Photo as MPhoto;
 use Friendica\Model\Post;
 use Friendica\Model\Profile;
 use Friendica\Model\Storage\ExternalResource;
+use Friendica\Model\Storage\ReferenceStorageException;
+use Friendica\Model\Storage\StorageException;
 use Friendica\Model\Storage\SystemResource;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Network\HTTPException\NotFoundException;
 use Friendica\Util\Proxy;
 use Friendica\Object\Image;
 use Friendica\Util\Images;
@@ -105,7 +109,11 @@ class Photo extends BaseModule
                $cacheable = ($photo["allow_cid"] . $photo["allow_gid"] . $photo["deny_cid"] . $photo["deny_gid"] === "") && (isset($photo["cacheable"]) ? $photo["cacheable"] : true);
 
                $stamp = microtime(true);
+
                $imgdata = MPhoto::getImageDataForPhoto($photo);
+               if (empty($imgdata)) {
+                       throw new NotFoundException();
+               }
 
                // The mimetype for an external or system resource can only be known reliably after it had been fetched
                if (in_array($photo['backend-class'], [ExternalResource::NAME, SystemResource::NAME])) {
@@ -118,8 +126,14 @@ class Photo extends BaseModule
                $data = microtime(true) - $stamp;
 
                if (empty($imgdata)) {
-                       Logger::warning("Invalid photo with id {$photo["id"]}.");
-                       throw new \Friendica\Network\HTTPException\InternalServerErrorException(DI::l10n()->t('Invalid photo with id %s.', $photo["id"]));
+                       Logger::warning('Invalid photo', ['id' => $photo['id']]);
+                       if (in_array($photo['backend-class'], [ExternalResource::NAME])) {
+                               $reference = json_decode($photo['backend-ref'], true);
+                               $error = DI::l10n()->t('Invalid external resource with url %s.', $reference['url']);
+                       } else {
+                               $error = DI::l10n()->t('Invalid photo with id %s.', $photo['id']);
+                       }
+                       throw new \Friendica\Network\HTTPException\InternalServerErrorException($error);
                }
 
                // if customsize is set and image is not a gif, resize it