PoCo endpoint added

This commit is contained in:
Michael 2019-10-03 15:30:07 +00:00
parent 3eb24d1b5c
commit 59b464ade3

View file

@ -34,7 +34,6 @@ class GServer
public static function detect($url) public static function detect($url)
{ {
/// @Todo: /// @Todo:
// - poco endpoint
// - Pleroma version number // - Pleroma version number
$serverdata = []; $serverdata = [];
@ -97,6 +96,8 @@ class GServer
$serverdata = $nodeinfo; $serverdata = $nodeinfo;
} }
$serverdata = self::checkPoCo($url, $serverdata);
// We can't detect the network type. Possibly it is some system that we don't know yet // We can't detect the network type. Possibly it is some system that we don't know yet
if (empty($serverdata['network'])) { if (empty($serverdata['network'])) {
$serverdata['network'] = Protocol::PHANTOM; $serverdata['network'] = Protocol::PHANTOM;
@ -105,13 +106,18 @@ class GServer
$serverdata['url'] = $url; $serverdata['url'] = $url;
$serverdata['nurl'] = Strings::normaliseLink($url); $serverdata['nurl'] = Strings::normaliseLink($url);
// When we don't have the registered users, we simply count what we know // We take the highest number that we do find
if (empty($serverdata['registered-users'])) { $registeredUsers = $serverdata['registered-users'] ?? 0;
// On an active server there has to be at least a single user
if (($serverdata['network'] != Protocol::PHANTOM) && ($registeredUsers == 0)) {
$registeredUsers = 1;
}
$gcontacts = DBA::count('gcontact', ['server_url' => [$url, $serverdata['nurl']]]); $gcontacts = DBA::count('gcontact', ['server_url' => [$url, $serverdata['nurl']]]);
$apcontacts = DBA::count('apcontact', ['baseurl' => [$url, $serverdata['nurl']]]); $apcontacts = DBA::count('apcontact', ['baseurl' => [$url, $serverdata['nurl']]]);
$contacts = DBA::count('contact', ['uid' => 0, 'baseurl' => [$url, $serverdata['nurl']]]); $contacts = DBA::count('contact', ['uid' => 0, 'baseurl' => [$url, $serverdata['nurl']]]);
$serverdata['registered-users'] = max($gcontacts, $apcontacts, $contacts); $serverdata['registered-users'] = max($gcontacts, $apcontacts, $contacts, $registeredUsers);
}
$serverdata['last_contact'] = DateTimeFormat::utcNow(); $serverdata['last_contact'] = DateTimeFormat::utcNow();
@ -437,6 +443,29 @@ class GServer
return $serverdata; return $serverdata;
} }
private static function checkPoCo($url, $serverdata)
{
$curlResult = Network::curl($url. '/poco');
if (!$curlResult->isSuccess()) {
return $serverdata;
}
$data = json_decode($curlResult->getBody(), true);
if (empty($data)) {
return $serverdata;
}
if (!empty($data['totalResults'])) {
$registeredUsers = $serverdata['registered-users'] ?? 0;
$serverdata['registered-users'] = max($data['totalResults'], $registeredUsers);
$serverdata['poco'] = $url . '/poco';
} else {
$serverdata['poco'] = '';
}
return $serverdata;
}
private static function detectNextcloud($url, $serverdata) private static function detectNextcloud($url, $serverdata)
{ {
$curlResult = Network::curl($url . '/status.php'); $curlResult = Network::curl($url . '/status.php');