Moved /v1/emotes.
This commit is contained in:
parent
b6f5a4e0cc
commit
477210411d
2 changed files with 56 additions and 0 deletions
src
54
src/Emoticons/EmotesApiRoutes.php
Normal file
54
src/Emoticons/EmotesApiRoutes.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
namespace Misuzu\Emoticons;
|
||||||
|
|
||||||
|
use Index\XArray;
|
||||||
|
use Index\Http\{HttpRequest,HttpResponseBuilder};
|
||||||
|
use Index\Http\Routing\{HttpGet,HttpOptions,RouteHandler,RouteHandlerCommon};
|
||||||
|
|
||||||
|
final class EmotesApiRoutes implements RouteHandler {
|
||||||
|
use RouteHandlerCommon;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private EmotesData $emotes
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/** @return int|mixed[] */
|
||||||
|
#[HttpOptions('/api/v1/emotes')]
|
||||||
|
#[HttpGet('/api/v1/emotes')]
|
||||||
|
public function getEmotes(HttpResponseBuilder $response, HttpRequest $request): int|array {
|
||||||
|
$response->setHeader('Access-Control-Allow-Origin', '*');
|
||||||
|
$response->setHeader('Access-Control-Allow-Methods', 'GET');
|
||||||
|
$response->addHeader('Access-Control-Allow-Headers', 'Cache-Control');
|
||||||
|
$response->setHeader('Cache-Control', 'public, max-age=3600');
|
||||||
|
|
||||||
|
if($request->method === 'OPTIONS')
|
||||||
|
return 204;
|
||||||
|
|
||||||
|
$includeId = !empty($request->getParam('include_id'));
|
||||||
|
$includeOrder = !empty($request->getParam('include_order'));
|
||||||
|
|
||||||
|
return XArray::select(
|
||||||
|
$this->emotes->getEmotes(orderBy: 'order'),
|
||||||
|
function($emote) use ($includeId, $includeOrder) {
|
||||||
|
$info = [
|
||||||
|
'url' => $emote->url,
|
||||||
|
'strings' => XArray::select(
|
||||||
|
$this->emotes->getEmoteStrings($emote),
|
||||||
|
fn($string) => $string->string
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
if($includeId)
|
||||||
|
$info['id'] = $emote->id;
|
||||||
|
if($includeOrder)
|
||||||
|
$info['order'] = $emote->order;
|
||||||
|
|
||||||
|
$rank = $emote->minRank;
|
||||||
|
if($rank !== 0)
|
||||||
|
$info['min_rank'] = $rank;
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -176,6 +176,8 @@ class MisuzuContext {
|
||||||
));
|
));
|
||||||
$routingCtx->register($this->deps->constructLazy(WebFinger\WebFingerRoutes::class));
|
$routingCtx->register($this->deps->constructLazy(WebFinger\WebFingerRoutes::class));
|
||||||
|
|
||||||
|
$routingCtx->register($this->deps->constructLazy(Emoticons\EmotesApiRoutes::class));
|
||||||
|
|
||||||
$routingCtx->register($this->deps->constructLazy(Home\HomeRoutes::class));
|
$routingCtx->register($this->deps->constructLazy(Home\HomeRoutes::class));
|
||||||
$routingCtx->register($this->deps->constructLazy(Users\Assets\AssetsRoutes::class));
|
$routingCtx->register($this->deps->constructLazy(Users\Assets\AssetsRoutes::class));
|
||||||
$routingCtx->register($this->deps->constructLazy(Info\InfoRoutes::class));
|
$routingCtx->register($this->deps->constructLazy(Info\InfoRoutes::class));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue