diff options
| author | winter | 2024-12-06 20:43:26 +0000 |
|---|---|---|
| committer | winter | 2024-12-06 20:43:26 +0000 |
| commit | e1ad307b531c27ec6bfaf8b4d018991b0d4a78f3 (patch) | |
| tree | 4ef08af2b4051d433bb929d5162474ac6777cab1 /routes | |
initial commit
hardcoded functionality mostly!
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/actor.php | 39 | ||||
| -rw-r--r-- | routes/homepage.php | 12 | ||||
| -rw-r--r-- | routes/nodeinfo.php | 42 | ||||
| -rw-r--r-- | routes/note.php | 20 | ||||
| -rw-r--r-- | routes/webfinger.php | 34 |
5 files changed, 147 insertions, 0 deletions
diff --git a/routes/actor.php b/routes/actor.php new file mode 100644 index 0000000..230f342 --- /dev/null +++ b/routes/actor.php @@ -0,0 +1,39 @@ +<?php + +use WpfTest\HttpReturnStatus\NotFound; +use WpfTest\Router; + +Router::getInstance()->mount('/user/:username', function (array $args) { + if ($args['username'] != 'winter') { + throw new NotFound('i only know about winter'); + } + json_response([ // hardcoded much for testing + 'type' => 'actor', + 'self' => path_to_uri('/user/winter'), + 'created' => '2024-12-06T19:40:00+00:00', + 'homepage' => path_to_uri('/winter'), + 'handle' => 'winter', + 'displayName' => 'winter!', + 'bio' => 'winter on php', + 'pronouns' => 'it/she', + 'automated' => false, + 'endpoints' => [ + 'basicFeed' => path_to_uri('/user/winter/basicFeed') + ] + ]); +}); + +Router::getInstance()->mount('/user/:username/basicFeed', function (array $args) { + if ($args['username'] != 'winter') { + throw new NotFound('i only know about winter'); + } + json_response([ + 'page' => 1, + 'totalPages' => 1, + 'nextPage' => null, + 'previousPage' => null, + 'items' => [ + path_to_uri('/post/1') + ] + ]); +});
\ No newline at end of file diff --git a/routes/homepage.php b/routes/homepage.php new file mode 100644 index 0000000..ea5d31b --- /dev/null +++ b/routes/homepage.php @@ -0,0 +1,12 @@ +<?php + +use WpfTest\Router; + +Router::getInstance()->mount('/', function (array $args) { + echo '<h1>home</h1>'; +}); + +Router::getInstance()->mount('/:username', function (array $args) { ?> + <h1><?= $args['username'] ?></h1> + <p>todo!</p> +<?php });
\ No newline at end of file diff --git a/routes/nodeinfo.php b/routes/nodeinfo.php new file mode 100644 index 0000000..b507849 --- /dev/null +++ b/routes/nodeinfo.php @@ -0,0 +1,42 @@ +<?php + +use WpfTest\Router; + +Router::getInstance()->mount('/.well-known/nodeinfo', function (array $args) { + json_response([ + 'links' => [ + [ + 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1', + 'href' => path_to_uri('/nodeinfo/2.1') + ] + ] + ], 'application/jrd+json'); +}); + +Router::getInstance()->mount('/nodeinfo/2.1', function (array $args) { + json_response([ + 'version' => '2.1', + 'software' => [ + 'name' => 'WPF test server', + 'version' => '0.1.0' + ], + 'protocols' => ['wpf'], + 'services' => [ + 'inbound' => [], + 'outbound' => [] + ], + 'openRegistrations' => false, + 'usage' => [ + 'users' => [ + 'total' => 1 + ] + ], + 'metadata' => [ + 'nodeName' => "winter's pawsome test server", + 'nodeDescription' => 'written in php i dunno', + 'wpfExtensions' => [ + // + ] + ] + ], 'application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.1#"'); +});
\ No newline at end of file diff --git a/routes/note.php b/routes/note.php new file mode 100644 index 0000000..9c5e507 --- /dev/null +++ b/routes/note.php @@ -0,0 +1,20 @@ +<?php + +use WpfTest\Router; + +Router::getInstance()->mount('/post/:id', function (array $args) { + json_response([ + 'type' => 'note', + 'self' => path_to_uri('/post/' . $args['id']), + 'created' => '2024-12-06T20:14:00+00:00', + 'author' => path_to_uri('/user/winter'), + 'plainContent' => 'meow :3', + 'language' => 'eng', + 'inReplyTo' => null, + 'threadApex' => path_to_uri('/post/' . $args['id']), + 'privacy' => [ + 'scope' => 'public', + 'indexable' => true + ] + ]); +}); diff --git a/routes/webfinger.php b/routes/webfinger.php new file mode 100644 index 0000000..5994529 --- /dev/null +++ b/routes/webfinger.php @@ -0,0 +1,34 @@ +<?php + +use WpfTest\GlobalConfig; +use WpfTest\HttpReturnStatus\BadRequest; +use WpfTest\HttpReturnStatus\NotFound; +use WpfTest\Router; + +Router::getInstance()->mount('/.well-known/webfinger', function (array $args) { + if (!isset($_GET['resource'])) { + throw new BadRequest('parameter `resource` is required'); + } + $resource = $_GET['resource']; + if (!str_starts_with($resource, 'acct:')) { + throw new BadRequest('only acct: URIs are supported'); + } + $handle = substr($resource, 5); + [$localPart, $remotePart] = explode('@', $handle, 2); + if ($remotePart != GlobalConfig::getInstance()->getCanonicalHost()) { + throw new NotFound('i only know about local accounts'); + } + if ($localPart != 'winter') { + throw new NotFound('i only know about winter!!!'); + } + json_response([ + 'subject' => "acct:$localPart@$remotePart", + 'links' => [ + [ + 'rel' => 'urn:example:wpf:actor', + 'href' => path_to_uri('/user/winter'), + 'type' => 'application/json' + ] + ] + ]); +});
\ No newline at end of file |
