ActivityPub: Add a NodeInfo

This commit is contained in:
veselcraft 2021-12-27 18:36:05 +03:00
parent 0becdfdb28
commit a0ccbc9af2
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
5 changed files with 45 additions and 3 deletions

View file

@ -59,4 +59,9 @@ class Comments
"deleted" => false,
]));
}
function getCountOfAllComments(): int
{
return sizeof($this->comments->where(["deleted" => false]));
}
}

View file

@ -105,4 +105,9 @@ class Posts
{
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0]));
}
function getCountOfAllPosts(): int
{
return sizeof($this->posts->where(["deleted" => 0]));
}
}

View file

@ -1,6 +1,8 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Repositories;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Repositories\Posts;
use openvk\Web\Models\Repositories\Comments;
use Nette\Database\Table\ActiveRow;
use Chandler\Database\DatabaseConnection;
use Chandler\Security\User as ChandlerUser;
@ -47,9 +49,11 @@ class Users
function getStatistics(): object
{
return (object) [
"all" => sizeof(clone $this->users),
"active" => sizeof((clone $this->users)->where("online > 0")),
"online" => sizeof((clone $this->users)->where("online >= ?", time() - 900)),
"all" => sizeof(clone $this->users),
"active" => sizeof((clone $this->users)->where("online > 0")),
"online" => sizeof((clone $this->users)->where("online >= ?", time() - 900)),
"posts" => (new Posts)->getCountOfAllPosts(),
"comments" => (new Comments)->getCountOfAllComments()
];
}

View file

@ -14,6 +14,13 @@ final class ActivityPubPresenter extends OpenVKPresenter
header("Content-Type: application/xrd+xml; charset=utf-8");
exit($data);
} else if ($_SERVER['REQUEST_URI'] == "/.well-known/nodeinfo") {
$response->links = array(array(
"href" => ovk_scheme(true) . $_SERVER["SERVER_NAME"] . '/nodeinfo/2.0',
'rel' => "http://nodeinfo.diaspora.software/ns/schema/2.0"
));
$this->returnJson((array) $response);
} else if ($this->startsWith($_SERVER["REQUEST_URI"], '/.well-known/webfinger') && $this->startsWith($this->requestParam("resource"), 'acct:')) {
$username = array();
$subject = substr($this->requestParam("resource"), 5, strlen($this->requestParam("resource")));
@ -43,6 +50,25 @@ final class ActivityPubPresenter extends OpenVKPresenter
}
}
function renderNodeinfo()
{
$stats = (new Users)->getStatistics();
$response->version = '2.0';
$response->protocols = array('activitypub');
$response->openRegistrations = OPENVK_ROOT_CONF['openvk']['preferences']['registration']['enable'];
$response->software = array('name' => 'openvk',
'version' => OPENVK_VERSION);
$response->usage = array('localPosts' => $stats->posts,
'localComments' => $stats->comments,
'users' => array(
'total' => $stats->all
));
$response->metadata = (object)array();
$this->returnJson((array) $response);
}
private function startsWith($string, $startString)
{
$len = strlen($startString);

View file

@ -269,6 +269,8 @@ routes:
handler: "ActivityPub->WellKnown"
placeholders:
uri: ".+"
- url: "/nodeinfo/2.0"
handler: "ActivityPub->nodeinfo"
- url: "/{?shortCode}"
handler: "UnknownTextRouteStrategy->delegate"
placeholders: