From b115706359ffe7f68d7e1b8211e45eac02430f28 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 30 Mar 2024 00:52:32 +0000 Subject: [PATCH] Updated to new HTTP router. --- composer.lock | 32 ++++++++++++++++---------------- public/index.html | 2 +- src/Apis/v1_0.php | 19 ++++++++----------- src/IApi.php | 5 ++--- src/UihContext.php | 14 +++++++------- uiharu.php | 2 +- 6 files changed, 35 insertions(+), 39 deletions(-) diff --git a/composer.lock b/composer.lock index 786bc83..d5d78e0 100644 --- a/composer.lock +++ b/composer.lock @@ -12,7 +12,7 @@ "source": { "type": "git", "url": "https://patchii.net/flash/index.git", - "reference": "18397477d6734b4336c8b273f069cd8584173435" + "reference": "9d5b050b8928435416a7efbebe2a19ae8e626224" }, "require": { "ext-mbstring": "*", @@ -50,7 +50,7 @@ ], "description": "Composer package for the common library for my projects.", "homepage": "https://railgun.sh/index", - "time": "2024-01-04T02:07:43+00:00" + "time": "2024-03-28T23:27:04+00:00" }, { "name": "flashwave/syokuhou", @@ -209,16 +209,16 @@ }, { "name": "jean85/pretty-package-versions", - "version": "2.0.5", + "version": "2.0.6", "source": { "type": "git", "url": "https://github.com/Jean85/pretty-package-versions.git", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af" + "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/ae547e455a3d8babd07b96966b17d7fd21d9c6af", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af", + "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/f9fdd29ad8e6d024f52678b570e5593759b550b4", + "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4", "shasum": "" }, "require": { @@ -226,9 +226,9 @@ "php": "^7.1|^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.17", + "friendsofphp/php-cs-fixer": "^3.2", "jean85/composer-provided-replaced-stub-package": "^1.0", - "phpstan/phpstan": "^0.12.66", + "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^7.5|^8.5|^9.4", "vimeo/psalm": "^4.3" }, @@ -262,9 +262,9 @@ ], "support": { "issues": "https://github.com/Jean85/pretty-package-versions/issues", - "source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.5" + "source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.6" }, - "time": "2021-10-08T21:21:46+00:00" + "time": "2024-03-08T09:58:59+00:00" }, { "name": "psr/http-factory", @@ -525,16 +525,16 @@ }, { "name": "sentry/sentry", - "version": "4.3.1", + "version": "4.6.1", "source": { "type": "git", "url": "https://github.com/getsentry/sentry-php.git", - "reference": "cd89f230bda0833cb9992ebe9a1b7d24d6ee245b" + "reference": "5a94184175e5830b589bf923da8c9c3af2c0f409" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/cd89f230bda0833cb9992ebe9a1b7d24d6ee245b", - "reference": "cd89f230bda0833cb9992ebe9a1b7d24d6ee245b", + "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/5a94184175e5830b589bf923da8c9c3af2c0f409", + "reference": "5a94184175e5830b589bf923da8c9c3af2c0f409", "shasum": "" }, "require": { @@ -598,7 +598,7 @@ ], "support": { "issues": "https://github.com/getsentry/sentry-php/issues", - "source": "https://github.com/getsentry/sentry-php/tree/4.3.1" + "source": "https://github.com/getsentry/sentry-php/tree/4.6.1" }, "funding": [ { @@ -610,7 +610,7 @@ "type": "custom" } ], - "time": "2023-12-22T18:46:49+00:00" + "time": "2024-03-08T08:18:09+00:00" }, { "name": "symfony/deprecation-contracts", diff --git a/public/index.html b/public/index.html index 8fbedce..da6dbc5 100644 --- a/public/index.html +++ b/public/index.html @@ -18,7 +18,7 @@ diff --git a/src/Apis/v1_0.php b/src/Apis/v1_0.php index 24e38ec..e43bfa3 100644 --- a/src/Apis/v1_0.php +++ b/src/Apis/v1_0.php @@ -18,10 +18,10 @@ use Index\MediaType; use Index\Colour\Colour; use Index\Colour\ColourRGB; use Index\Data\IDbConnection; -use Index\Http\HttpFx; +use Index\Http\Routing\{HttpGet,HttpPost,RouteHandler}; use Index\Performance\Stopwatch; -final class v1_0 implements \Uiharu\IApi { +final class v1_0 extends RouteHandler implements \Uiharu\IApi { private UihContext $ctx; private IDbConnection $db; @@ -34,15 +34,7 @@ final class v1_0 implements \Uiharu\IApi { return !str_starts_with($url, '/v'); } - public function register(HttpFx $router): void { - $router->get('/metadata', [$this, 'getMetadata']); - $router->post('/metadata', [$this, 'postMetadata']); - $router->get('/metadata/batch', [$this, 'getMetadataBatch']); - $router->post('/metadata/batch', [$this, 'postMetadataBatch']); - $router->get('/metadata/thumb/audio', [$this, 'getThumbAudio']); - $router->get('/metadata/thumb/video', [$this, 'getThumbVideo']); - } - + #[HttpGet('/metadata/thumb/audio')] public function getThumbAudio($response, $request) { $targetUrl = (string)$request->getParam('url'); @@ -63,6 +55,7 @@ final class v1_0 implements \Uiharu\IApi { $response->setContent(FFMPEG::grabFirstAudioCover($parsedUrl)); } + #[HttpGet('/metadata/thumb/video')] public function getThumbVideo($response, $request) { $targetUrl = (string)$request->getParam('url'); @@ -83,6 +76,7 @@ final class v1_0 implements \Uiharu\IApi { $response->setContent(FFMPEG::grabFirstVideoFrame($parsedUrl)); } + #[HttpGet('/metadata')] public function getMetadata($response, $request) { if($request->getMethod() === 'HEAD') { $response->setTypeJson(); @@ -95,6 +89,7 @@ final class v1_0 implements \Uiharu\IApi { ); } + #[HttpPost('/metadata')] public function postMetadata($response, $request) { if(!$request->isStreamContent()) return 400; @@ -105,6 +100,7 @@ final class v1_0 implements \Uiharu\IApi { ); } + #[HttpGet('/metadata/batch')] public function getMetadataBatch($response, $request) { if($request->getMethod() === 'HEAD') { $response->setTypeJson(); @@ -117,6 +113,7 @@ final class v1_0 implements \Uiharu\IApi { ); } + #[HttpPost('/metadata/batch')] public function postMetadataBatch($response, $request) { if(!$request->isFormContent()) return 400; diff --git a/src/IApi.php b/src/IApi.php index 3e39935..d9a7913 100644 --- a/src/IApi.php +++ b/src/IApi.php @@ -1,9 +1,8 @@ database; } - public function getRouter(): HttpFx { + public function getRouter(): HttpRouter { return $this->router; } @@ -39,7 +39,7 @@ final class UihContext { } public function setupHttp(): void { - $this->router = new HttpFx; + $this->router = new HttpRouter; $this->router->use('/', function($response) { $response->setPoweredBy('Uiharu'); }); @@ -69,8 +69,8 @@ final class UihContext { }); } - public function dispatchHttp(...$args): void { - $this->router->dispatch(...$args); + public function dispatchHttp(): void { + $this->router->dispatch(); } public function registerApi(IApi $api): void { @@ -81,7 +81,7 @@ final class UihContext { $reqPath = '/' . trim(parse_url($reqPath, PHP_URL_PATH), '/'); foreach($this->apis as $api) if($api->match($reqPath)) { - $api->register($this->router); + $this->router->register($api); break; } } diff --git a/uiharu.php b/uiharu.php index 6be78e3..e9c1721 100644 --- a/uiharu.php +++ b/uiharu.php @@ -11,7 +11,7 @@ define('UIH_DEBUG', is_file(UIH_ROOT . '/.debug')); define('UIH_PUBLIC', UIH_ROOT . '/public'); define('UIH_SOURCE', UIH_ROOT . '/src'); define('UIH_LIBRARY', UIH_ROOT . '/lib'); -define('UIH_VERSION', '20231215'); +define('UIH_VERSION', '20240330'); require_once UIH_ROOT . '/vendor/autoload.php';