Added emotes endpoint.

This commit is contained in:
Pachira 2024-11-14 02:45:53 +00:00
parent 2896148124
commit b4288353f0
4 changed files with 34 additions and 5 deletions

6
composer.lock generated
View file

@ -8,11 +8,11 @@
"packages": [ "packages": [
{ {
"name": "flashii/rpcii", "name": "flashii/rpcii",
"version": "v2.0.0", "version": "v2.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://patchii.net/flashii/rpcii-php.git", "url": "https://patchii.net/flashii/rpcii-php.git",
"reference": "93ec139171d023f210f0b7464266b6fc42b4d838" "reference": "1cbc1edb061612dc1d014a82e24b741d2a0bc11a"
}, },
"require": { "require": {
"ext-msgpack": ">=2.2", "ext-msgpack": ">=2.2",
@ -43,7 +43,7 @@
], ],
"description": "HTTP RPC client/server library.", "description": "HTTP RPC client/server library.",
"homepage": "https://railgun.sh/rpcii", "homepage": "https://railgun.sh/rpcii",
"time": "2024-11-13T23:17:29+00:00" "time": "2024-11-14T02:22:09+00:00"
}, },
{ {
"name": "flashwave/index", "name": "flashwave/index",

View file

@ -29,7 +29,7 @@ class RpcClientWrapper implements RpcClient {
return new ScopedRpcClient($this, $prefix); 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) foreach($this->clients as $prefix => $client)
if(str_starts_with($action, $prefix)) if(str_starts_with($action, $prefix))
return $client->query($action, $params); return $client->query($action, $params);
@ -37,7 +37,7 @@ class RpcClientWrapper implements RpcClient {
throw new RuntimeException(sprintf('Unable to handle this query: %s', $action)); 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) foreach($this->clients as $prefix => $client)
if(str_starts_with($action, $prefix)) if(str_starts_with($action, $prefix))
return $client->action($action, $params); return $client->action($action, $params);

25
src/V1/V1EmotesRoutes.php Normal file
View file

@ -0,0 +1,25 @@
<?php
namespace Syokuhou\V1;
use Index\Http\Routing\{HttpGet,RouteHandler,RouteHandlerTrait};
use RPCii\Client\RpcClient;
class V1EmotesRoutes implements RouteHandler {
use RouteHandlerTrait;
public function __construct(
private RpcClient $rpc
) {}
#[HttpGet('/')]
public function getEmotes($response, $request) {
$response->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')),
]);
}
}

View file

@ -15,6 +15,10 @@ class V1Routes implements RouteHandler {
$router->get('/', fn() => ['status' => 'operational']); $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:')); $usersRoutes = new V1UsersRoutes($this->ctx, $this->ctx->getRpcClient()->scopeTo('misuzu:users:'));
$router->options('/me', $usersRoutes->getMe(...)); $router->options('/me', $usersRoutes->getMe(...));
$router->get('/me', $usersRoutes->getMe(...)); $router->get('/me', $usersRoutes->getMe(...));