Merge pull request #13664 from annando/issue-12530

Issue 12530: Align the instance endpoint to the latest changes
This commit is contained in:
Hypolite Petovan 2023-11-24 09:56:52 -05:00 committed by GitHub
commit ce5aa016e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 152 additions and 8 deletions

View 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(),
);
}
}

View 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(),
);
}

View 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;

View file

@ -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;
}

View 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;
}
}

View 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;
}
}

View file

@ -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;
}

View 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

View 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;
}
}