From d5a57276eb27e215dd0b1bd5eb67ac26acc9575b Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 24 Dec 2024 15:32:56 +0000 Subject: more stuff and things --- routes/note.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'routes/note.php') 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 @@ 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]); +}); -- cgit v1.3