]> git.mxchange.org Git - friendica.git/commitdiff
Ensure $attachment has a width and a height when it's an image in Mastodon\Attachment
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 23 Nov 2022 16:00:15 +0000 (11:00 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 23 Nov 2022 16:00:15 +0000 (11:00 -0500)
- Address https://github.com/friendica/friendica/issues/11993#issuecomment-1323274513

src/Factory/Api/Mastodon/Attachment.php
src/Object/Api/Mastodon/Attachment.php

index 5a87aeed954074d89d11b4006467716be560fb73..accebe3433f8079f771cff3c536240bb39bba299 100644 (file)
@@ -94,12 +94,17 @@ class Attachment extends BaseFactory
         */
        public function createFromPhoto(int $id): array
        {
-               $photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type'], ['id' => $id]);
+               $photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type', 'width', 'height'], ['id' => $id]);
                if (empty($photo)) {
                        return [];
                }
 
-               $attachment = ['id' => $photo['id'], 'description' => $photo['title']];
+               $attachment = [
+                       'id'          => $photo['id'],
+                       'description' => $photo['title'],
+                       'width'       => $photo['width'],
+                       'height'      => $photo['height'],
+               ];
 
                $photoTypes = Images::supportedTypes();
                $ext        = $photoTypes[$photo['type']];
@@ -113,7 +118,6 @@ class Attachment extends BaseFactory
                        $preview_url = '';
                }
 
-
                $object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, 'image', $url, $preview_url, '');
                return $object->toArray();
        }
index 90b1bffb9fd4e644595fd516a479cfae71b2c48d..3f890bf744a9c38c0edb0d02397a962ad460f67b 100644 (file)
@@ -22,6 +22,8 @@
 namespace Friendica\Object\Api\Mastodon;
 
 use Friendica\BaseDataTransferObject;
+use Friendica\Core\Logger;
+use Friendica\Core\System;
 
 /**
  * Class Attachment
@@ -50,8 +52,12 @@ class Attachment extends BaseDataTransferObject
        /**
         * Creates an attachment
         *
-        * @param array $attachment
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @param array $attachment Expected keys: id, description
+        *                          If $type == 'image': width, height[, preview-width, preview-height]
+        * @param string $type      One of: audio, video, gifv, image, unknown
+        * @param string $url
+        * @param string $preview
+        * @param string $remote
         */
        public function __construct(array $attachment, string $type, string $url, string $preview, string $remote)
        {
@@ -70,7 +76,7 @@ class Attachment extends BaseDataTransferObject
                                $this->meta['original']['aspect'] = (float) ((int)  $attachment['width'] / (int) $attachment['height']);
                        }
 
-                       if ((int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) {
+                       if (isset($attachment['preview-width']) && (int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) {
                                $this->meta['small']['width'] = (int) $attachment['preview-width'];
                                $this->meta['small']['height'] = (int) $attachment['preview-height'];
                                $this->meta['small']['size'] = (int) $attachment['preview-width'] . 'x' . (int) $attachment['preview-height'];