From 199ac6420275e7a18ca8a25ca83dcb5fdf7c388a Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 24 Nov 2023 13:25:39 +0000 Subject: [PATCH] Issue 12530: Align the instance endpoint to the latest changes --- src/Module/Api/Mastodon/Instance.php | 29 ++++++++++++- src/Module/Api/Mastodon/InstanceV2.php | 12 +++++- src/Object/Api/Mastodon/Instance.php | 6 ++- .../Api/Mastodon/InstanceV2/Accounts.php | 35 ++++++++++++++++ .../Api/Mastodon/InstanceV2/Configuration.php | 10 ++++- .../InstanceV2/MediaAttachmentsConfig.php | 11 ++++- src/Object/Api/Mastodon/InstanceV2/Polls.php | 41 +++++++++++++++++++ .../Api/Mastodon/InstanceV2/Registrations.php | 4 ++ .../Mastodon/InstanceV2/StatusesConfig.php | 12 +++++- 9 files changed, 152 insertions(+), 8 deletions(-) create mode 100644 src/Object/Api/Mastodon/InstanceV2/Accounts.php create mode 100644 src/Object/Api/Mastodon/InstanceV2/Polls.php diff --git a/src/Module/Api/Mastodon/Instance.php b/src/Module/Api/Mastodon/Instance.php index 7096174786..075d4a9dde 100644 --- a/src/Module/Api/Mastodon/Instance.php +++ b/src/Module/Api/Mastodon/Instance.php @@ -29,7 +29,10 @@ use Friendica\Database\Database; use Friendica\Module\Api\ApiResponse; use Friendica\Module\BaseApi; use Friendica\Object\Api\Mastodon\Instance as InstanceEntity; +use Friendica\Object\Api\Mastodon\InstanceV2 as InstanceV2Entity; +use Friendica\Util\Images; use Friendica\Util\Profiler; +use Friendica\Util\Strings; use Psr\Log\LoggerInterface; /** @@ -59,6 +62,30 @@ class Instance extends BaseApi */ protected function rawContent(array $request = []) { - $this->jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, System::getRules())); + $this->jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, System::getRules(), $this->buildConfigurationInfo())); + } + + private function buildConfigurationInfo(): InstanceV2Entity\Configuration + { + $statuses_config = new InstanceV2Entity\StatusesConfig((int)$this->config->get( + 'config', + 'api_import_size', + $this->config->get('config', 'max_import_size') + ), 99, 23); + + $image_size_limit = Strings::getBytesFromShorthand($this->config->get('system', 'maximagesize')); + $max_image_length = $this->config->get('system', 'max_image_length'); + if ($max_image_length > 0) { + $image_matrix_limit = pow($max_image_length, 2); + } else { + $image_matrix_limit = 33177600; // 5760^2 + } + + return new InstanceV2Entity\Configuration( + $statuses_config, + new InstanceV2Entity\MediaAttachmentsConfig(array_keys(Images::supportedTypes()), $image_size_limit, $image_matrix_limit), + new InstanceV2Entity\Polls(), + new InstanceV2Entity\Accounts(), + ); } } diff --git a/src/Module/Api/Mastodon/InstanceV2.php b/src/Module/Api/Mastodon/InstanceV2.php index 7469e1c63f..5136d74067 100644 --- a/src/Module/Api/Mastodon/InstanceV2.php +++ b/src/Module/Api/Mastodon/InstanceV2.php @@ -119,13 +119,21 @@ class InstanceV2 extends BaseApi 'config', 'api_import_size', $this->config->get('config', 'max_import_size') - )); + ), 99, 23); $image_size_limit = Strings::getBytesFromShorthand($this->config->get('system', 'maximagesize')); + $max_image_length = $this->config->get('system', 'max_image_length'); + if ($max_image_length > 0) { + $image_matrix_limit = pow($max_image_length, 2); + } else { + $image_matrix_limit = 33177600; // 5760^2 + } return new InstanceEntity\Configuration( $statuses_config, - new InstanceEntity\MediaAttachmentsConfig(Images::supportedTypes(), $image_size_limit), + new InstanceEntity\MediaAttachmentsConfig(array_keys(Images::supportedTypes()), $image_size_limit, $image_matrix_limit), + new InstanceEntity\Polls(), + new InstanceEntity\Accounts(), ); } diff --git a/src/Object/Api/Mastodon/Instance.php b/src/Object/Api/Mastodon/Instance.php index a7549afd84..18707356ef 100644 --- a/src/Object/Api/Mastodon/Instance.php +++ b/src/Object/Api/Mastodon/Instance.php @@ -31,6 +31,7 @@ use Friendica\DI; use Friendica\Model\User; use Friendica\Module\Register; use Friendica\Network\HTTPException; +use Friendica\Object\Api\Mastodon\InstanceV2\Configuration; /** * Class Instance @@ -68,6 +69,8 @@ class Instance extends BaseDataTransferObject /** @var bool */ protected $invites_enabled; /** @var Account|null */ + /** @var Configuration */ + protected $configuration; protected $contact_account = null; /** @var array */ protected $rules = []; @@ -81,7 +84,7 @@ class Instance extends BaseDataTransferObject * @throws HTTPException\NotFoundException * @throws \ImagickException */ - public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = []) + public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [], Configuration $configuration) { $register_policy = intval($config->get('config', 'register_policy')); @@ -98,6 +101,7 @@ class Instance extends BaseDataTransferObject $this->registrations = ($register_policy != Register::CLOSED); $this->approval_required = ($register_policy == Register::APPROVE); $this->invites_enabled = false; + $this->configuration = $configuration; $this->contact_account = []; $this->rules = $rules; diff --git a/src/Object/Api/Mastodon/InstanceV2/Accounts.php b/src/Object/Api/Mastodon/InstanceV2/Accounts.php new file mode 100644 index 0000000000..6996c08e30 --- /dev/null +++ b/src/Object/Api/Mastodon/InstanceV2/Accounts.php @@ -0,0 +1,35 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon\InstanceV2; + +use Friendica\BaseDataTransferObject; + +/** + * Class Accounts + * + * @see https://docs.joinmastodon.org/entities/Instance/ + */ +class Accounts extends BaseDataTransferObject +{ + /** @var int */ + protected $max_featured_tags = 0; +} diff --git a/src/Object/Api/Mastodon/InstanceV2/Configuration.php b/src/Object/Api/Mastodon/InstanceV2/Configuration.php index 276dece280..cf0320e864 100644 --- a/src/Object/Api/Mastodon/InstanceV2/Configuration.php +++ b/src/Object/Api/Mastodon/InstanceV2/Configuration.php @@ -30,10 +30,14 @@ use Friendica\BaseDataTransferObject; */ class Configuration extends BaseDataTransferObject { + /** @var Accounts */ + protected $accounts; /** @var StatusesConfig */ protected $statuses; /** @var MediaAttachmentsConfig */ protected $media_attachments; + /** @var Polls */ + protected $polls; /** * @param StatusesConfig $statuses @@ -41,9 +45,13 @@ class Configuration extends BaseDataTransferObject */ public function __construct( StatusesConfig $statuses, - MediaAttachmentsConfig $media_attachments + MediaAttachmentsConfig $media_attachments, + Polls $polls, + Accounts $accounts, ) { + $this->accounts = $accounts; $this->statuses = $statuses; $this->media_attachments = $media_attachments; + $this->polls = $polls; } } diff --git a/src/Object/Api/Mastodon/InstanceV2/MediaAttachmentsConfig.php b/src/Object/Api/Mastodon/InstanceV2/MediaAttachmentsConfig.php index 3301ed7be2..d9e9db4c4b 100644 --- a/src/Object/Api/Mastodon/InstanceV2/MediaAttachmentsConfig.php +++ b/src/Object/Api/Mastodon/InstanceV2/MediaAttachmentsConfig.php @@ -34,13 +34,22 @@ class MediaAttachmentsConfig extends BaseDataTransferObject protected $supported_mime_types; /** @var int */ protected $image_size_limit; + /** @var int */ + protected $image_matrix_limit; + /** @var int */ + protected $video_size_limit = 0; + /** @var int */ + protected $video_frame_rate_limit = 0; + /** @var int */ + protected $video_matrix_limit = 0; /** * @param array $supported_mime_types */ - public function __construct(array $supported_mime_types, int $image_size_limit) + public function __construct(array $supported_mime_types, int $image_size_limit, int $image_matrix_limit) { $this->supported_mime_types = $supported_mime_types; $this->image_size_limit = $image_size_limit; + $this->image_matrix_limit = $image_matrix_limit; } } diff --git a/src/Object/Api/Mastodon/InstanceV2/Polls.php b/src/Object/Api/Mastodon/InstanceV2/Polls.php new file mode 100644 index 0000000000..f2d20def48 --- /dev/null +++ b/src/Object/Api/Mastodon/InstanceV2/Polls.php @@ -0,0 +1,41 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon\InstanceV2; + +use Friendica\BaseDataTransferObject; + +/** + * Class Polls + * + * @see https://docs.joinmastodon.org/entities/Instance/ + */ +class Polls extends BaseDataTransferObject +{ + /** @var int */ + protected $max_options = 0; + /** @var int */ + protected $max_characters_per_option = 0; + /** @var int */ + protected $min_expiration = 0; + /** @var int */ + protected $max_expiration = 0; +} diff --git a/src/Object/Api/Mastodon/InstanceV2/Registrations.php b/src/Object/Api/Mastodon/InstanceV2/Registrations.php index b4a9054568..c4c1089ed8 100644 --- a/src/Object/Api/Mastodon/InstanceV2/Registrations.php +++ b/src/Object/Api/Mastodon/InstanceV2/Registrations.php @@ -34,6 +34,10 @@ class Registrations extends BaseDataTransferObject protected $enabled; /** @var bool */ protected $approval_required; + /** @var string|null */ + protected $message; + /** @var string|null */ + protected $url; /** * @param bool $enabled diff --git a/src/Object/Api/Mastodon/InstanceV2/StatusesConfig.php b/src/Object/Api/Mastodon/InstanceV2/StatusesConfig.php index aa2af4f047..c2e2e80aee 100644 --- a/src/Object/Api/Mastodon/InstanceV2/StatusesConfig.php +++ b/src/Object/Api/Mastodon/InstanceV2/StatusesConfig.php @@ -32,12 +32,20 @@ class StatusesConfig extends BaseDataTransferObject { /** @var int */ protected $max_characters = 0; + /** @var int */ + protected $max_media_attachments = 0; + /** @var int */ + protected $characters_reserved_per_url = 0; /** * @param int $max_characters + * @param int $max_media_attachments + * @param int $characters_reserved_per_url */ - public function __construct(int $max_characters) + public function __construct(int $max_characters, int $max_media_attachments, int $characters_reserved_per_url) { - $this->max_characters = $max_characters; + $this->max_characters = $max_characters; + $this->max_media_attachments = $max_media_attachments; + $this->characters_reserved_per_url = $characters_reserved_per_url; } }