[PLUGIN][ActivityPub][Inbox] Separate handler by method

This commit is contained in:
Diogo Peralta Cordeiro 2022-02-20 05:03:05 +00:00
parent 51cccd0155
commit 6f3e760c63
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 8 additions and 2 deletions

View File

@ -122,7 +122,7 @@ class ActivityPub extends Plugin
$r->connect( $r->connect(
'activitypub_inbox', 'activitypub_inbox',
'/inbox.json', '/inbox.json',
[Inbox::class, 'handle'], Inbox::class,
options: ['format' => self::$accept_headers[0]], options: ['format' => self::$accept_headers[0]],
); );
$r->connect( $r->connect(

View File

@ -36,6 +36,7 @@ use App\Core\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Event; use App\Core\Event;
use App\Util\Common; use App\Util\Common;
use Symfony\Component\HttpFoundation\Request;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Log; use App\Core\Log;
use App\Core\Router\Router; use App\Core\Router\Router;
@ -60,10 +61,15 @@ use Plugin\ActivityPub\Util\TypeResponse;
*/ */
class Inbox extends Controller class Inbox extends Controller
{ {
public function onGet(Request $request, ?int $gsactor_id = null): TypeResponse
{
return new TypeResponse(json_encode(['error' => 'No AP C2S inbox yet.']), 400);
}
/** /**
* Create an Inbox Handler to receive something from someone. * Create an Inbox Handler to receive something from someone.
*/ */
public function handle(?int $gsactor_id = null): TypeResponse public function onPost(Request $request, ?int $gsactor_id = null): TypeResponse
{ {
$error = function (string $m, ?Exception $e = null): TypeResponse { $error = function (string $m, ?Exception $e = null): TypeResponse {
Log::error('ActivityPub Error Answer: ' . ($json = json_encode(['error' => $m, 'exception' => var_export($e, true)]))); Log::error('ActivityPub Error Answer: ' . ($json = json_encode(['error' => $m, 'exception' => var_export($e, true)])));