diff --git a/doc/API-Mastodon.md b/doc/API-Mastodon.md index d885e6ab3..a711e367f 100644 --- a/doc/API-Mastodon.md +++ b/doc/API-Mastodon.md @@ -16,6 +16,8 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/ap ## Implemented endpoints - [GET /api/v1/follow_requests](https://docs.joinmastodon.org/api/rest/follow-requests/#get-api-v1-follow-requests) +- [GET /api/v1/instance](https://docs.joinmastodon.org/api/rest/instances) +- GET /api/v1/instance/peers - undocumented, but implemented by Mastodon and Pleroma ## Non-implemented endpoints diff --git a/src/Api/Mastodon/Instance.php b/src/Api/Mastodon/Instance.php new file mode 100644 index 000000000..890c83c09 --- /dev/null +++ b/src/Api/Mastodon/Instance.php @@ -0,0 +1,84 @@ +uri = $app->getBaseURL(); + $instance->title = Config::get('config', 'sitename'); + $instance->description = Config::get('config', 'info'); + $instance->email = Config::get('config', 'admin_email'); + $instance->version = FRIENDICA_VERSION; + $instance->urls = []; // Not supported + $instance->stats = Stats::get(); + $instance->thumbnail = $app->getBaseURL() . (Config::get('system', 'shortcut_icon') ?? 'images/friendica-32.png'); + $instance->languages = [Config::get('system', 'language')]; + $instance->max_toot_chars = (int)Config::get('config', 'api_import_size', Config::get('config', 'max_import_size')); + $instance->registrations = ($register_policy != Register::CLOSED); + $instance->approval_required = ($register_policy == Register::APPROVE); + $instance->contact_account = []; + + if (!empty(Config::get('config', 'admin_email'))) { + $adminList = explode(',', str_replace(' ', '', Config::get('config', 'admin_email'))); + $administrator = User::getByEmail($adminList[0], ['nickname']); + if (!empty($administrator)) { + $adminContact = DBA::selectFirst('contact', [], ['nick' => $administrator['nickname'], 'self' => true]); + $instance->contact_account = Account::createFromContact($adminContact); + } + } + + return $instance; + } +} diff --git a/src/Api/Mastodon/Stats.php b/src/Api/Mastodon/Stats.php new file mode 100644 index 000000000..895a58e06 --- /dev/null +++ b/src/Api/Mastodon/Stats.php @@ -0,0 +1,38 @@ +user_count = intval(Config::get('nodeinfo', 'total_users')); + $stats->status_count = Config::get('nodeinfo', 'local_posts') + Config::get('nodeinfo', 'local_comments'); + $stats->domain_count = DBA::count('gserver', ["`network` in (?, ?) AND `last_contact` >= `last_failure`", Protocol::DFRN, Protocol::ACTIVITYPUB]); + } + return $stats; + } +} diff --git a/src/Module/Api/Mastodon/Instance.php b/src/Module/Api/Mastodon/Instance.php new file mode 100644 index 000000000..6a2b3abb6 --- /dev/null +++ b/src/Module/Api/Mastodon/Instance.php @@ -0,0 +1,22 @@ += `last_failure`", Protocol::DFRN, Protocol::ACTIVITYPUB]); + while ($instance = DBA::fetch($instances)) { + $urldata = parse_url($instance['url']); + unset($urldata['scheme']); + $return[] = ltrim(Network::unparseURL($urldata), '/'); + } + DBA::close($instances); + + System::jsonExit($return); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index d8113c5c5..824354690 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -30,6 +30,8 @@ return [ '/api' => [ '/v1' => [ '/follow_requests' => [Module\Api\Mastodon\FollowRequests::class, [R::GET ]], + '/instance' => [Module\Api\Mastodon\Instance::class, [R::GET]], + '/instance/peers' => [Module\Api\Mastodon\Instance\Peers::class, [R::GET]], ], ],