]> git.mxchange.org Git - friendica.git/blobdiff - src/Factory/Api/Friendica/Photo.php
API: Fix interoperability between Friendica and Mastodon part
[friendica.git] / src / Factory / Api / Friendica / Photo.php
index 4053a177764e928048f6316040158831078591df..44a671e16bc2708a9837725440aaf19c779fb493 100644 (file)
@@ -57,14 +57,14 @@ class Photo extends BaseFactory
         * @param string $type
         * @return Array
         */
-       public function createFromId(string $photo_id, int $scale, int $uid, string $type = 'json', bool $with_posts = true): array
+       public function createFromId(string $photo_id, int $scale = null, int $uid, string $type = 'json', bool $with_posts = true): array
        {
                $fields = ['resource-id', 'created', 'edited', 'title', 'desc', 'album', 'filename','type',
                        'height', 'width', 'datasize', 'profile', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid',
                        'backend-class', 'backend-ref', 'id', 'scale'];
 
                $condition = ['uid' => $uid, 'resource-id' => $photo_id];
-               if ($scale >= 0) {
+               if (is_int($scale)) {
                        $fields = array_merge(['data'], $fields);
 
                        $condition['scale'] = $scale;
@@ -74,12 +74,13 @@ class Photo extends BaseFactory
                if (empty($photos)) {
                        throw new HTTPException\NotFoundException();
                }
-               $data       = $photos[0];
-               $data['id'] = $data['resource-id'];
+               $data = $photos[0];
+
+               $data['media-id'] = $data['id'];
+               $data['id']       = $data['resource-id'];
+
                if (is_int($scale)) {
                        $data['data'] = base64_encode(ModelPhoto::getImageDataForPhoto($data));
-               } else {
-                       unset($data['datasize']); //needed only with scale param
                }
 
                if ($type == 'xml') {
@@ -99,12 +100,21 @@ class Photo extends BaseFactory
                        } else {
                                $data['link'][$id] = $link;
                        }
+                       if (is_null($scale)) {
+                               $data['scales'][] = [
+                                       'id'     => $photo['id'],
+                                       'scale'  => $photo['scale'],
+                                       'link'   => $link,
+                                       'width'  => $photo['width'],
+                                       'height' => $photo['height'],
+                                       'size'   => $photo['datasize'],
+                               ];
+                       }
                }
 
                unset($data['backend-class']);
                unset($data['backend-ref']);
                unset($data['resource-id']);
-               unset($data['scale']);
 
                if ($with_posts) {
                        // retrieve item element for getting activities (like, dislike etc.) related to photo