From b4288353f0b57bd0822a17c5d9fa9722735e0db7 Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 14 Nov 2024 02:45:53 +0000 Subject: [PATCH] Added emotes endpoint. --- composer.lock | 6 +++--- src/RpcClientWrapper.php | 4 ++-- src/V1/V1EmotesRoutes.php | 25 +++++++++++++++++++++++++ src/V1/V1Routes.php | 4 ++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/V1/V1EmotesRoutes.php diff --git a/composer.lock b/composer.lock index 02d8db2..0fbce1b 100644 --- a/composer.lock +++ b/composer.lock @@ -8,11 +8,11 @@ "packages": [ { "name": "flashii/rpcii", - "version": "v2.0.0", + "version": "v2.0.1", "source": { "type": "git", "url": "https://patchii.net/flashii/rpcii-php.git", - "reference": "93ec139171d023f210f0b7464266b6fc42b4d838" + "reference": "1cbc1edb061612dc1d014a82e24b741d2a0bc11a" }, "require": { "ext-msgpack": ">=2.2", @@ -43,7 +43,7 @@ ], "description": "HTTP RPC client/server library.", "homepage": "https://railgun.sh/rpcii", - "time": "2024-11-13T23:17:29+00:00" + "time": "2024-11-14T02:22:09+00:00" }, { "name": "flashwave/index", diff --git a/src/RpcClientWrapper.php b/src/RpcClientWrapper.php index bb8c00c..0c2dfab 100644 --- a/src/RpcClientWrapper.php +++ b/src/RpcClientWrapper.php @@ -29,7 +29,7 @@ class RpcClientWrapper implements RpcClient { return new ScopedRpcClient($this, $prefix); } - public function query(string $action, array $params): mixed { + public function query(string $action, array $params = []): mixed { foreach($this->clients as $prefix => $client) if(str_starts_with($action, $prefix)) return $client->query($action, $params); @@ -37,7 +37,7 @@ class RpcClientWrapper implements RpcClient { throw new RuntimeException(sprintf('Unable to handle this query: %s', $action)); } - public function action(string $action, array $params): mixed { + public function action(string $action, array $params = []): mixed { foreach($this->clients as $prefix => $client) if(str_starts_with($action, $prefix)) return $client->action($action, $params); diff --git a/src/V1/V1EmotesRoutes.php b/src/V1/V1EmotesRoutes.php new file mode 100644 index 0000000..fdd7729 --- /dev/null +++ b/src/V1/V1EmotesRoutes.php @@ -0,0 +1,25 @@ +setHeader('Access-Control-Allow-Origin', '*'); + $response->setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET'); + $response->setHeader('Cache-Control', 'public, max-age=3600'); + + return $this->rpc->query('all', [ + 'includeId' => !empty($request->getParam('include_id')), + 'includeOrder' => !empty($request->getParam('include_order')), + ]); + } +} diff --git a/src/V1/V1Routes.php b/src/V1/V1Routes.php index 99da4cd..5d5e395 100644 --- a/src/V1/V1Routes.php +++ b/src/V1/V1Routes.php @@ -15,6 +15,10 @@ class V1Routes implements RouteHandler { $router->get('/', fn() => ['status' => 'operational']); + $router->scopeTo('/emotes')->register( + new V1EmotesRoutes($this->ctx->getRpcClient()->scopeTo('misuzu:emotes:')) + ); + $usersRoutes = new V1UsersRoutes($this->ctx, $this->ctx->getRpcClient()->scopeTo('misuzu:users:')); $router->options('/me', $usersRoutes->getMe(...)); $router->get('/me', $usersRoutes->getMe(...));