Merge pull request #12786 from annando/c2s-post

C2S: Posting is now possible
This commit is contained in:
Hypolite Petovan 2023-02-14 15:49:25 -05:00 committed by GitHub
commit f9b3340599
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 518 additions and 153 deletions

View file

@ -61,12 +61,12 @@ class Inbox extends BaseApi
if ($owner['uid'] != $uid) {
throw new \Friendica\Network\HTTPException\ForbiddenException();
}
$outbox = ActivityPub\Transmitter::getInbox($uid, $page, $request['max_id'] ?? null);
$inbox = ActivityPub\ClientToServer::getInbox($uid, $page, $request['max_id'] ?? null);
} else {
$outbox = ActivityPub\Transmitter::getPublicInbox($uid, $page, $request['max_id'] ?? null);
$inbox = ActivityPub\ClientToServer::getPublicInbox($uid, $page, $request['max_id'] ?? null);
}
System::jsonExit($outbox, 'application/activity+json');
System::jsonExit($inbox, 'application/activity+json');
}
protected function post(array $request = [])

View file

@ -26,6 +26,7 @@ use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Network;
/**
* ActivityPub Outbox
@ -50,9 +51,34 @@ class Outbox extends BaseApi
$page = 1;
}
$requester = HTTPSignature::getSigner('', $_SERVER);
$outbox = ActivityPub\Transmitter::getOutbox($owner, $uid, $page, $request['max_id'] ?? null, $requester);
$outbox = ActivityPub\ClientToServer::getOutbox($owner, $uid, $page, $request['max_id'] ?? null, HTTPSignature::getSigner('', $_SERVER));
System::jsonExit($outbox, 'application/activity+json');
}
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$postdata = Network::postdata();
if (empty($postdata) || empty($this->parameters['nickname'])) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
$owner = User::getOwnerDataByNick($this->parameters['nickname']);
if (empty($owner)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
if ($owner['uid'] != $uid) {
throw new \Friendica\Network\HTTPException\ForbiddenException();
}
$activity = json_decode($postdata, true);
if (empty($activity)) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
System::jsonExit(ActivityPub\ClientToServer::processActivity($activity, $uid, self::getCurrentApplication() ?? []));
}
}

View file

@ -96,7 +96,7 @@ class Whoami extends BaseApi
'oauthRegistrationEndpoint' => DI::baseUrl() . '/api/v1/apps',
'oauthTokenEndpoint' => DI::baseUrl() . '/oauth/token',
'sharedInbox' => DI::baseUrl() . '/inbox',
'uploadMedia' => DI::baseUrl() . '/api/upload_media' // @todo Endpoint does not exist at the moment
// 'uploadMedia' => DI::baseUrl() . '/api/upload_media' // @todo Endpoint does not exist at the moment
];
$data['generator'] = ActivityPub\Transmitter::getService();