From 46607598f3bb81174d2e2b54a82ffe95bbcc779d Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Mon, 12 Dec 2022 11:27:59 -0500 Subject: [PATCH 1/3] Fix Friendica Photo GET API endpoint to work without explicit scale term --- src/Factory/Api/Friendica/Photo.php | 4 ++-- src/Module/Api/Friendica/Photo.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Factory/Api/Friendica/Photo.php b/src/Factory/Api/Friendica/Photo.php index 2621a7830..4053a1777 100644 --- a/src/Factory/Api/Friendica/Photo.php +++ b/src/Factory/Api/Friendica/Photo.php @@ -57,14 +57,14 @@ class Photo extends BaseFactory * @param string $type * @return Array */ - public function createFromId(string $photo_id, int $scale = null, int $uid, string $type = 'json', bool $with_posts = true): array + public function createFromId(string $photo_id, int $scale, 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 (is_int($scale)) { + if ($scale >= 0) { $fields = array_merge(['data'], $fields); $condition['scale'] = $scale; diff --git a/src/Module/Api/Friendica/Photo.php b/src/Module/Api/Friendica/Photo.php index b4b6a3997..5b21d8e92 100644 --- a/src/Module/Api/Friendica/Photo.php +++ b/src/Module/Api/Friendica/Photo.php @@ -54,7 +54,7 @@ class Photo extends BaseApi throw new HTTPException\BadRequestException('No photo id.'); } - $scale = (!empty($request['scale']) ? intval($request['scale']) : false); + $scale = (!empty($request['scale']) ? intval($request['scale']) : -1); $photo_id = $request['photo_id']; // prepare json/xml output with data from database for the requested photo From 4e5794c99d53ff233244e85e6f8ef84b8a7d3f81 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Mon, 12 Dec 2022 12:37:01 -0500 Subject: [PATCH 2/3] Update Friendica Photo API endpoint fix to pass null for scale when not applied --- src/Factory/Api/Friendica/Photo.php | 4 ++-- src/Module/Api/Friendica/Photo.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Factory/Api/Friendica/Photo.php b/src/Factory/Api/Friendica/Photo.php index 4053a1777..36df12d67 100644 --- a/src/Factory/Api/Friendica/Photo.php +++ b/src/Factory/Api/Friendica/Photo.php @@ -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 (intval($scale)) { $fields = array_merge(['data'], $fields); $condition['scale'] = $scale; diff --git a/src/Module/Api/Friendica/Photo.php b/src/Module/Api/Friendica/Photo.php index 5b21d8e92..67f242127 100644 --- a/src/Module/Api/Friendica/Photo.php +++ b/src/Module/Api/Friendica/Photo.php @@ -54,7 +54,7 @@ class Photo extends BaseApi throw new HTTPException\BadRequestException('No photo id.'); } - $scale = (!empty($request['scale']) ? intval($request['scale']) : -1); + $scale = (!empty($request['scale']) ? intval($request['scale']) : null); $photo_id = $request['photo_id']; // prepare json/xml output with data from database for the requested photo From a8428264f032b8a5cf9d98ebdbf4ce8b29814b65 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Mon, 12 Dec 2022 12:38:45 -0500 Subject: [PATCH 3/3] Use is_int not intval to return Photo->createFromId back to original version --- src/Factory/Api/Friendica/Photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factory/Api/Friendica/Photo.php b/src/Factory/Api/Friendica/Photo.php index 36df12d67..2621a7830 100644 --- a/src/Factory/Api/Friendica/Photo.php +++ b/src/Factory/Api/Friendica/Photo.php @@ -64,7 +64,7 @@ class Photo extends BaseFactory 'backend-class', 'backend-ref', 'id', 'scale']; $condition = ['uid' => $uid, 'resource-id' => $photo_id]; - if (intval($scale)) { + if (is_int($scale)) { $fields = array_merge(['data'], $fields); $condition['scale'] = $scale;