From 503a49b7d7b4275fd09b4a7c06cbdbdf257fef79 Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 24 Dec 2024 14:15:02 +0000 Subject: breaking change: use id in actor uri instead of handle --- routes/actor.php | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'routes') diff --git a/routes/actor.php b/routes/actor.php index d453a11..57bfbc5 100644 --- a/routes/actor.php +++ b/routes/actor.php @@ -7,10 +7,13 @@ use Digitigrade\Model\Actor; use Digitigrade\Model\Note; use Digitigrade\Router; -Router::getInstance()->mount('/actor/:handle', function (array $args) { - $actor = Actor::findLocalByHandle($args['handle']); +Router::getInstance()->mount('/actor/:id', function (array $args) { + $actor = Actor::find($args['id']); if ($actor == null || $actor->deleted) { - throw new NotFound("i don't know any local actor called " . $args['handle']); + throw new NotFound("i don't know that actor"); + } + if (!$actor->isLocal) { + throw new NotFound("that actor is not local!"); } if (isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'text/html')) { throw new TemporaryRedirect("/@/$actor->handle"); @@ -18,8 +21,8 @@ Router::getInstance()->mount('/actor/:handle', function (array $args) { json_response($actor); }); -Router::getInstance()->mount('/actor/:handle/basicFeed', function (array $args) { - $actor = Actor::findLocalByHandle($args['handle']); +Router::getInstance()->mount('/actor/:id/basicFeed', function (array $args) { + $actor = Actor::find($args['id']); $notes = Note::findAllWithAuthor($actor); // TODO: implement pagination json_response([ @@ -33,8 +36,8 @@ Router::getInstance()->mount('/actor/:handle/basicFeed', function (array $args) ]); }); -Router::getInstance()->mount('/actor/:handle/fullFeed', function (array $args) { - $actor = Actor::findLocalByHandle($args['handle']); +Router::getInstance()->mount('/actor/:id/fullFeed', function (array $args) { + $actor = Actor::find($args['id']); $notes = Note::findAllWithAuthor($actor); // TODO: implement pagination here as well json_response([ @@ -46,9 +49,9 @@ Router::getInstance()->mount('/actor/:handle/fullFeed', function (array $args) { ]); }); -Router::getInstance()->mount('/actor/:handle/follow', function (array $args) { - $target = Actor::findLocalByHandle($args['handle']); - if ($target == null) { +Router::getInstance()->mount('/actor/:id/follow', function (array $args) { + $target = Actor::find($args['id']); + if ($target == null || !$target->isLocal || $target->deleted) { throw new NotFound(); } $initiator = Actor::findByRequestHeaders(); @@ -58,9 +61,9 @@ Router::getInstance()->mount('/actor/:handle/follow', function (array $args) { $initiator->follow($target); }); -Router::getInstance()->mount('/actor/:handle/unfollow', function (array $args) { - $target = Actor::findLocalByHandle($args['handle']); - if ($target == null) { +Router::getInstance()->mount('/actor/:id/unfollow', function (array $args) { + $target = Actor::find($args['id']); + if ($target == null || !$target->isLocal || $target->deleted) { throw new NotFound(); } $initiator = Actor::findByRequestHeaders(); @@ -70,9 +73,9 @@ Router::getInstance()->mount('/actor/:handle/unfollow', function (array $args) { $initiator->unfollow($target); }); -Router::getInstance()->mount('/actor/:handle/acceptedFollow', function (array $args) { - $initiator = Actor::findLocalByHandle($args['handle']); - if ($initiator == null) { +Router::getInstance()->mount('/actor/:id/acceptedFollow', function (array $args) { + $initiator = Actor::find($args['id']); + if ($initiator == null || !$initiator->isLocal || $initiator->deleted) { throw new NotFound(); } $target = Actor::findByRequestHeaders(); @@ -82,9 +85,9 @@ Router::getInstance()->mount('/actor/:handle/acceptedFollow', function (array $a $target->acceptPendingFollowFrom($initiator); }); -Router::getInstance()->mount('/actor/:handle/rejectedFollow', function (array $args) { - $initiator = Actor::findLocalByHandle($args['handle']); - if ($initiator == null) { +Router::getInstance()->mount('/actor/:id/rejectedFollow', function (array $args) { + $initiator = Actor::find($args['id']); + if ($initiator == null || !$initiator->isLocal || $initiator->deleted) { throw new NotFound(); } $target = Actor::findByRequestHeaders(); -- cgit v1.3