mirror of
https://github.com/friendica/friendica
synced 2025-04-22 03:10:10 +00:00
Merge pull request #7926 from annando/api-instance
API: Added endpoints /instance and /instance/peers
This commit is contained in:
commit
1c69dda2e1
6 changed files with 184 additions and 0 deletions
22
src/Module/Api/Mastodon/Instance.php
Normal file
22
src/Module/Api/Mastodon/Instance.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\Api\Mastodon\Instance as InstanceEntity;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Module\Base\Api;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/api/rest/instances/
|
||||
*/
|
||||
class Instance extends Api
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
System::jsonExit(InstanceEntity::get(self::getApp()));
|
||||
}
|
||||
}
|
36
src/Module/Api/Mastodon/Instance/Peers.php
Normal file
36
src/Module/Api/Mastodon/Instance/Peers.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Instance;
|
||||
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Module\Base\Api;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Network;
|
||||
|
||||
/**
|
||||
* Undocumented API endpoint that is implemented by both Mastodon and Pleroma
|
||||
*/
|
||||
class Peers extends Api
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
$return = [];
|
||||
|
||||
// We only select for Friendica and ActivityPub servers, since it is expected to only deliver AP compatible systems here.
|
||||
$instances = DBA::select('gserver', ['url'], ["`network` in (?, ?) AND `last_contact` >= `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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue