]> git.mxchange.org Git - friendica.git/commitdiff
Issue 12530: Align the instance endpoint to the latest changes
authorMichael <heluecht@pirati.ca>
Fri, 24 Nov 2023 13:25:39 +0000 (13:25 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 24 Nov 2023 13:25:39 +0000 (13:25 +0000)
src/Module/Api/Mastodon/Instance.php
src/Module/Api/Mastodon/InstanceV2.php
src/Object/Api/Mastodon/Instance.php
src/Object/Api/Mastodon/InstanceV2/Accounts.php [new file with mode: 0644]
src/Object/Api/Mastodon/InstanceV2/Configuration.php
src/Object/Api/Mastodon/InstanceV2/MediaAttachmentsConfig.php
src/Object/Api/Mastodon/InstanceV2/Polls.php [new file with mode: 0644]
src/Object/Api/Mastodon/InstanceV2/Registrations.php
src/Object/Api/Mastodon/InstanceV2/StatusesConfig.php

index 709617478605dc520bbb4be47c4c9fc8d48febcf..075d4a9ddef650c1b593ebc98cb8b2f108689322 100644 (file)
@@ -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(),
+               );
        }
 }
index 7469e1c63f6dfb32745224772281dc84ec89303c..5136d740676613dda14f5021d5d06317013a6209 100644 (file)
@@ -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(),
                );
        }
 
index a7549afd8489cd055cf9cbe59fe994403c85cfd1..18707356ef9f0208803d552f4d9ac1304e18996a 100644 (file)
@@ -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 (file)
index 0000000..6996c08
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+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;
+}
index 276dece28074f1e9697984eff30ef506a16fb4f9..cf0320e8646881509c91513cc2f8a73ba2225bb4 100644 (file)
@@ -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;
        }
 }
index 3301ed7be2159cf780c9834f06d2069c3757615f..d9e9db4c4b56c01d2cf3c7ad3729ed6c22a31d1d 100644 (file)
@@ -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 (file)
index 0000000..f2d20de
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+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;
+}
index b4a90545685432e406097ea8d3fbcd8659820be2..c4c1089ed889a2cd626ceb5c0f89a0fb8e1f3646 100644 (file)
@@ -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
index aa2af4f04736346aa813d659745300d79b07bafa..c2e2e80aeef4e6ffae71c5906b68e03b02b3aebe 100644 (file)
@@ -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;
        }
 }