diff options
| author | winter | 2024-12-24 15:32:56 +0000 |
|---|---|---|
| committer | winter | 2024-12-24 15:32:56 +0000 |
| commit | d5a57276eb27e215dd0b1bd5eb67ac26acc9575b (patch) | |
| tree | 0cb3a14fa9a82d2438a7c12838f04ea12e02a9fa /routes/note.php | |
| parent | 01b7c47c68b8b3c5a9fd9137b067b34b566b951d (diff) | |
more stuff and things
Diffstat (limited to 'routes/note.php')
| -rw-r--r-- | routes/note.php | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/routes/note.php b/routes/note.php index 071c86c..8a6c9da 100644 --- a/routes/note.php +++ b/routes/note.php @@ -1,6 +1,7 @@ <?php use Digitigrade\HttpResponseStatus\NotFound; +use Digitigrade\HttpResponseStatus\TemporaryRedirect; use Digitigrade\Model\Note; use Digitigrade\Router; @@ -12,5 +13,20 @@ Router::getInstance()->mount('/note/:id', function (array $args) { if (!$note->author->isLocal) { throw new NotFound("i don't want to tell you about non local notes sorry"); } + if (isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'text/html')) { + throw new TemporaryRedirect('/@/' . $note->author->handle . "/note/$note->id"); + } json_response($note); }); + +Router::getInstance()->mount('/@/:handle/note/:id', function (array $args) { + $note = Note::find($args['id']); + if ($note == null || $note->deleted) { + throw new NotFound("i don't know that note"); + } + // change the handle in the url if it's wrong + if ($args['handle'] != $note->author->getFullHandle()) { + throw new TemporaryRedirect('/@/' . $note->author->getFullHandle() . "/note/$note->id"); + } + render_template('thread_page', ['note' => $note]); +}); |
