diff --git a/LICENCE b/LICENCE index 691d03b..056b687 100644 --- a/LICENCE +++ b/LICENCE @@ -1,6 +1,6 @@ BSD 2-Clause License -Copyright (c) 2021-2022, flashwave +Copyright (c) 2021-2024, flashwave All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/composer.lock b/composer.lock index b3c5b85..236b3ae 100644 --- a/composer.lock +++ b/composer.lock @@ -62,7 +62,7 @@ "source": { "type": "git", "url": "https://patchii.net/flash/index.git", - "reference": "e31781c69f0b13fe251771c8e7e529222630a44f" + "reference": "9d5b050b8928435416a7efbebe2a19ae8e626224" }, "require": { "ext-mbstring": "*", @@ -100,7 +100,7 @@ ], "description": "Composer package for the common library for my projects.", "homepage": "https://railgun.sh/index", - "time": "2023-11-20T19:01:19+00:00" + "time": "2024-03-28T23:27:04+00:00" }, { "name": "flashwave/sasae", @@ -108,7 +108,7 @@ "source": { "type": "git", "url": "https://patchii.net/flash/sasae.git", - "reference": "b56dd222acb8f138729e6258d4a90bbb8401ff52" + "reference": "c8a9f2974e6591215b3f898dd5525de1e8367f66" }, "require": { "flashwave/index": "dev-master", @@ -141,7 +141,7 @@ ], "description": "A wrapper for Twig with added common functionality.", "homepage": "https://railgun.sh/sasae", - "time": "2023-11-20T19:09:35+00:00" + "time": "2024-01-04T02:13:42+00:00" }, { "name": "flashwave/syokuhou", @@ -149,7 +149,7 @@ "source": { "type": "git", "url": "https://patchii.net/flash/syokuhou.git", - "reference": "fdf3c38cc216bf7024af331cbe1758532355c22f" + "reference": "c1fe9371ada20fcea51c225cc53b9ceae4642bc4" }, "require": { "flashwave/index": "dev-master", @@ -180,7 +180,7 @@ ], "description": "Configuration library for PHP.", "homepage": "https://railgun.sh/syokuhou", - "time": "2023-11-20T19:10:04+00:00" + "time": "2024-01-04T02:12:49+00:00" }, { "name": "guzzlehttp/psr7", @@ -300,16 +300,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": { @@ -317,9 +317,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" }, @@ -353,9 +353,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", @@ -616,16 +616,16 @@ }, { "name": "sentry/sentry", - "version": "4.1.0", + "version": "4.6.1", "source": { "type": "git", "url": "https://github.com/getsentry/sentry-php.git", - "reference": "89666f297891ff937fceb2f3d1fb967a6848cf37" + "reference": "5a94184175e5830b589bf923da8c9c3af2c0f409" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/89666f297891ff937fceb2f3d1fb967a6848cf37", - "reference": "89666f297891ff937fceb2f3d1fb967a6848cf37", + "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/5a94184175e5830b589bf923da8c9c3af2c0f409", + "reference": "5a94184175e5830b589bf923da8c9c3af2c0f409", "shasum": "" }, "require": { @@ -649,7 +649,7 @@ "phpbench/phpbench": "^1.0", "phpstan/phpstan": "^1.3", "phpunit/phpunit": "^8.5.14|^9.4", - "symfony/phpunit-bridge": "^5.2|^6.0", + "symfony/phpunit-bridge": "^5.2|^6.0|^7.0", "vimeo/psalm": "^4.17" }, "suggest": { @@ -689,7 +689,7 @@ ], "support": { "issues": "https://github.com/getsentry/sentry-php/issues", - "source": "https://github.com/getsentry/sentry-php/tree/4.1.0" + "source": "https://github.com/getsentry/sentry-php/tree/4.6.1" }, "funding": [ { @@ -701,7 +701,7 @@ "type": "custom" } ], - "time": "2023-12-04T12:41:21+00:00" + "time": "2024-03-08T08:18:09+00:00" }, { "name": "symfony/deprecation-contracts", @@ -772,16 +772,16 @@ }, { "name": "symfony/mime", - "version": "v7.0.0", + "version": "v7.0.3", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535" + "reference": "c1ffe24ba6fdc3e3f0f3fcb93519103b326a3716" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/0a2fff95c1a10df97f571d67e76c7ae0f0d4f535", - "reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535", + "url": "https://api.github.com/repos/symfony/mime/zipball/c1ffe24ba6fdc3e3f0f3fcb93519103b326a3716", + "reference": "c1ffe24ba6fdc3e3f0f3fcb93519103b326a3716", "shasum": "" }, "require": { @@ -835,7 +835,7 @@ "mime-type" ], "support": { - "source": "https://github.com/symfony/mime/tree/v7.0.0" + "source": "https://github.com/symfony/mime/tree/v7.0.3" }, "funding": [ { @@ -851,7 +851,7 @@ "type": "tidelift" } ], - "time": "2023-10-19T14:20:43+00:00" + "time": "2024-01-30T08:34:29+00:00" }, { "name": "symfony/options-resolver", @@ -922,16 +922,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", "shasum": "" }, "require": { @@ -945,9 +945,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -984,7 +981,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" }, "funding": [ { @@ -1000,20 +997,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "ecaafce9f77234a6a449d29e49267ba10499116d" + "reference": "a287ed7475f85bf6f61890146edbc932c0fff919" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/ecaafce9f77234a6a449d29e49267ba10499116d", - "reference": "ecaafce9f77234a6a449d29e49267ba10499116d", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/a287ed7475f85bf6f61890146edbc932c0fff919", + "reference": "a287ed7475f85bf6f61890146edbc932c0fff919", "shasum": "" }, "require": { @@ -1026,9 +1023,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -1071,7 +1065,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.29.0" }, "funding": [ { @@ -1087,20 +1081,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:30:37+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92" + "reference": "bc45c394692b948b4d383a08d7753968bed9a83d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", - "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/bc45c394692b948b4d383a08d7753968bed9a83d", + "reference": "bc45c394692b948b4d383a08d7753968bed9a83d", "shasum": "" }, "require": { @@ -1111,9 +1105,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -1155,7 +1146,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.29.0" }, "funding": [ { @@ -1171,20 +1162,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "42292d99c55abe617799667f454222c54c60e229" + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", - "reference": "42292d99c55abe617799667f454222c54c60e229", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", "shasum": "" }, "require": { @@ -1198,9 +1189,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -1238,7 +1226,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" }, "funding": [ { @@ -1254,20 +1242,20 @@ "type": "tidelift" } ], - "time": "2023-07-28T09:04:16+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-php72", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "70f4aebd92afca2f865444d30a4d2151c13c3179" + "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/70f4aebd92afca2f865444d30a4d2151c13c3179", - "reference": "70f4aebd92afca2f865444d30a4d2151c13c3179", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/861391a8da9a04cbad2d232ddd9e4893220d6e25", + "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25", "shasum": "" }, "require": { @@ -1275,9 +1263,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -1314,7 +1299,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php72/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php72/tree/v1.29.0" }, "funding": [ { @@ -1330,20 +1315,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", "shasum": "" }, "require": { @@ -1351,9 +1336,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -1397,7 +1379,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" }, "funding": [ { @@ -1413,7 +1395,7 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "twig/html-extra", @@ -1555,16 +1537,16 @@ "packages-dev": [ { "name": "phpstan/phpstan", - "version": "1.10.50", + "version": "1.10.66", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4" + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/94779c987e4ebd620025d9e5fdd23323903950bd", + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd", "shasum": "" }, "require": { @@ -1613,7 +1595,7 @@ "type": "tidelift" } ], - "time": "2023-12-13T10:59:42+00:00" + "time": "2024-03-28T16:17:31+00:00" } ], "aliases": [], @@ -1627,5 +1609,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/HomeRoutes.php b/src/HomeRoutes.php index db3f884..47b6ae4 100644 --- a/src/HomeRoutes.php +++ b/src/HomeRoutes.php @@ -1,8 +1,7 @@ templating->render('index'); } - #[Route('GET', '/index.php')] + #[HttpGet('/index.php')] public function getIndexPHP($response): void { $response->redirect('/', true); } diff --git a/src/RoutingContext.php b/src/RoutingContext.php index 20008cf..a6c1c04 100644 --- a/src/RoutingContext.php +++ b/src/RoutingContext.php @@ -1,17 +1,13 @@ router = new HttpFx; + public function __construct(SeriaContext $context) { + $this->router = new HttpRouter(errorHandler: new RoutingErrorHandler($context)); $this->router->use('/', fn($resp) => $resp->setPoweredBy('Seria')); } @@ -19,31 +15,11 @@ class RoutingContext { return $this->router; } - public function registerDefaultErrorPages(): void { - $this->router->setDefaultErrorHandler($this->defaultErrorHandler(...)); - $this->router->addErrorHandler(500, fn($resp) => $resp->setContent(file_get_contents(SERIA_DIR_TEMPLATES . '/500.html'))); - } - - public function defaultErrorHandler( - HttpResponseBuilder $responseBuilder, - HttpRequest $request, - int $code, - string $message - ): void { - // todo: render using templating - $responseBuilder->setTypeHTML(); - $responseBuilder->setContent(sprintf( - '%1$03d %2$s

%1$03d %2$s


Seria
', - $code, - $message - )); - } - public function register(IRouteHandler $handler): void { $this->router->register($handler); } - public function dispatch(?HttpRequest $request = null): void { - $this->router->dispatch($request); + public function dispatch(): void { + $this->router->dispatch(); } } diff --git a/src/RoutingErrorHandler.php b/src/RoutingErrorHandler.php new file mode 100644 index 0000000..346281f --- /dev/null +++ b/src/RoutingErrorHandler.php @@ -0,0 +1,32 @@ +setTypeHTML(); + $response->setContent(file_get_contents(SERIA_DIR_TEMPLATES . '/500.html')); + return; + } + + $templating = $this->context->getTemplating(); + if($templating === null) { + $response->setTypePlain(); + $response->setContent((string)$code); + return; + } + + $response->setTypeHTML(); + $response->setContent($templating->render('http-error', [ + 'http_code' => $code, + 'http_text' => $message, + ])); + } +} diff --git a/src/SeriaContext.php b/src/SeriaContext.php index 501da0f..4d2f829 100644 --- a/src/SeriaContext.php +++ b/src/SeriaContext.php @@ -4,9 +4,7 @@ namespace Seria; use InvalidArgumentException; use Index\Environment; use Index\Data\IDbTransactions; -use Index\Data\Migration\IDbMigrationRepo; -use Index\Data\Migration\DbMigrationManager; -use Index\Data\Migration\FsDbMigrationRepo; +use Index\Data\Migration\{IDbMigrationRepo,DbMigrationManager,FsDbMigrationRepo}; use Index\Security\CSRFP; use Sasae\SasaeEnvironment; use Syokuhou\IConfig; @@ -101,11 +99,7 @@ final class SeriaContext { } public function createRouting(): RoutingContext { - $routing = new RoutingContext; - $routing->registerDefaultErrorPages(); - - $self = $this; - $router = $routing->getRouter(); + $routing = new RoutingContext($this); $routing->register(new HomeRoutes($this->templating)); $routing->register(new Users\ProfileRoutes($this->authInfo, $this->torrentsCtx, $this->usersCtx, $this->templating)); diff --git a/src/Torrents/AnnounceRouting.php b/src/Torrents/AnnounceRouting.php index 9735d7a..0383c43 100644 --- a/src/Torrents/AnnounceRouting.php +++ b/src/Torrents/AnnounceRouting.php @@ -2,8 +2,7 @@ namespace Seria\Torrents; use RuntimeException; -use Index\Routing\Route; -use Index\Routing\RouteHandler; +use Index\Http\Routing\{HttpGet,RouteHandler}; use Index\Serialisation\Bencode; use Seria\Users\UsersContext; @@ -16,10 +15,10 @@ class AnnounceRouting extends RouteHandler { private UsersContext $usersCtx ) {} - #[Route('GET', '/announce')] - #[Route('GET', '/announce.php')] - #[Route('GET', '/announce/:key')] - #[Route('GET', '/announce.php/:key')] + #[HttpGet('/announce')] + #[HttpGet('/announce.php')] + #[HttpGet('/announce/:key')] + #[HttpGet('/announce.php/:key')] public function getAnnounce($response, $request, string $key = '') { if(strlen(inet_pton($_SERVER['REMOTE_ADDR'])) !== 4) return new AnnounceFailure('Tracker is only supported over IPv4, please reset your DNS cache.'); diff --git a/src/Torrents/TorrentCreateRouting.php b/src/Torrents/TorrentCreateRouting.php index b885675..6d2d909 100644 --- a/src/Torrents/TorrentCreateRouting.php +++ b/src/Torrents/TorrentCreateRouting.php @@ -4,8 +4,7 @@ namespace Seria\Torrents; use Exception; use RuntimeException; use Index\Data\IDbTransactions; -use Index\Routing\Route; -use Index\Routing\RouteHandler; +use Index\Http\Routing\{HttpGet,HttpMiddleware,HttpPost,RouteHandler}; use Index\Security\CSRFP; use Sasae\SasaeEnvironment; use Seria\Auth\AuthInfo; @@ -20,7 +19,7 @@ class TorrentCreateRouting extends RouteHandler { private ?SasaeEnvironment $templating ) {} - #[Route('/create')] + #[HttpMiddleware('/create')] public function checkAccess() { if(!$this->authInfo->isLoggedIn()) return 403; @@ -28,7 +27,7 @@ class TorrentCreateRouting extends RouteHandler { return 403; } - #[Route('GET', '/create')] + #[HttpGet('/create')] public function getCreate($response, $request) { $template = $this->templating->load('create'); @@ -44,7 +43,7 @@ class TorrentCreateRouting extends RouteHandler { return $template; } - #[Route('POST', '/create')] + #[HttpPost('/create')] public function postCreate($response, $request) { if(!$request->isFormContent()) return 400; @@ -95,7 +94,7 @@ class TorrentCreateRouting extends RouteHandler { $response->redirect(sprintf('/info/%s', $torrentId)); } - #[Route('GET', '/create.php')] + #[HttpGet('/create.php')] public function getCreatePHP($response, $request) { $response->redirect('/create', true); } diff --git a/src/Torrents/TorrentInfoRouting.php b/src/Torrents/TorrentInfoRouting.php index e232955..28cd89b 100644 --- a/src/Torrents/TorrentInfoRouting.php +++ b/src/Torrents/TorrentInfoRouting.php @@ -2,8 +2,7 @@ namespace Seria\Torrents; use RuntimeException; -use Index\Routing\Route; -use Index\Routing\RouteHandler; +use Index\Http\Routing\{HttpGet,HttpMiddleware,HttpPost,RouteHandler}; use Index\Security\CSRFP; use Sasae\SasaeEnvironment; use Syokuhou\IConfig; @@ -22,7 +21,7 @@ class TorrentInfoRouting extends RouteHandler { private ?SasaeEnvironment $templating ) {} - #[Route('GET', '/download/:id')] + #[HttpGet('/download/([0-9]+)')] public function getDownload($response, $request, string $torrentId) { try { $torrentInfo = $this->torrentsCtx->getTorrents()->getTorrent($torrentId); @@ -77,7 +76,7 @@ class TorrentInfoRouting extends RouteHandler { return 0; } - #[Route('GET', '/info/:id')] + #[HttpGet('/info/([0-9]+)')] public function getInfo($response, $request, string $torrentId) { $error = $this->getTorrentInfo($torrentId); if($error > 0) return $error; @@ -105,9 +104,9 @@ class TorrentInfoRouting extends RouteHandler { ]); } - #[Route('/info/:id/rehash')] - #[Route('/info/:id/approve')] - #[Route('/info/:id/deny')] + #[HttpMiddleware('/info/([0-9]+)/rehash')] + #[HttpMiddleware('/info/([0-9]+)/approve')] + #[HttpMiddleware('/info/([0-9]+)/deny')] public function verifyRequest($response, $request, string $torrentId) { if(!$this->authInfo->isLoggedIn()) return 401; @@ -123,7 +122,7 @@ class TorrentInfoRouting extends RouteHandler { if($error > 0) return $error; } - #[Route('POST', '/info/:id/rehash')] + #[HttpPost('/info/([0-9]+)/rehash')] public function postRehash($response, $request, string $torrentId) { $error = $this->getTorrentInfo($torrentId); if($error > 0) return $error; @@ -144,7 +143,7 @@ class TorrentInfoRouting extends RouteHandler { ]; } - #[Route('POST', '/info/:id/approve')] + #[HttpPost('/info/([0-9]+)/approve')] public function postApprove($response, $request, string $torrentId) { $error = $this->getTorrentInfo($torrentId); if($error > 0) return $error; @@ -157,7 +156,7 @@ class TorrentInfoRouting extends RouteHandler { return 204; } - #[Route('POST', '/info/:id/deny')] + #[HttpPost('/info/([0-9]+)/deny')] public function postDeny($response, $request, string $torrentId) { $error = $this->getTorrentInfo($torrentId); if($error > 0) return $error; @@ -170,7 +169,7 @@ class TorrentInfoRouting extends RouteHandler { return 204; } - #[Route('GET', '/info.php')] + #[HttpGet('/info.php')] public function getInfoPHP($response, $request) { $torrentId = (int)$request->getParam('id', FILTER_SANITIZE_NUMBER_INT); if($torrentId < 1) @@ -179,7 +178,7 @@ class TorrentInfoRouting extends RouteHandler { $response->redirect(sprintf('/info/%d', $torrentId), true); } - #[Route('GET', '/download.php')] + #[HttpGet('/download.php')] public function getDownloadPHP($response, $request) { $torrentId = (int)$request->getParam('id', FILTER_SANITIZE_NUMBER_INT); if($torrentId < 1) diff --git a/src/Torrents/TorrentListRouting.php b/src/Torrents/TorrentListRouting.php index 3bb7909..0f19277 100644 --- a/src/Torrents/TorrentListRouting.php +++ b/src/Torrents/TorrentListRouting.php @@ -2,8 +2,7 @@ namespace Seria\Torrents; use RuntimeException; -use Index\Routing\Route; -use Index\Routing\RouteHandler; +use Index\Http\Routing\{HttpGet,RouteHandler}; use Sasae\SasaeEnvironment; use Seria\Auth\AuthInfo; use Seria\Users\UsersContext; @@ -16,7 +15,7 @@ class TorrentListRouting extends RouteHandler { private ?SasaeEnvironment $templating ) {} - #[Route('GET', '/available')] + #[HttpGet('/available')] public function getAvailable($response, $request) { $users = $this->usersCtx->getUsers(); $peers = $this->torrentsCtx->getPeers(); @@ -64,7 +63,7 @@ class TorrentListRouting extends RouteHandler { ]); } - #[Route('GET', '/pending')] + #[HttpGet('/pending')] public function getPending($response, $request) { if(!$this->authInfo->isLoggedIn()) return 403; @@ -101,7 +100,7 @@ class TorrentListRouting extends RouteHandler { ]); } - #[Route('GET', '/available.php')] + #[HttpGet('/available.php')] public function getAvailablePHP($response, $request): void { $query = []; @@ -119,7 +118,7 @@ class TorrentListRouting extends RouteHandler { $response->redirect($url, true); } - #[Route('GET', '/pending.php')] + #[HttpGet('/pending.php')] public function getPendingPHP($response, $request): void { $query = []; diff --git a/src/Users/ProfileRoutes.php b/src/Users/ProfileRoutes.php index 82e3e16..e6e782d 100644 --- a/src/Users/ProfileRoutes.php +++ b/src/Users/ProfileRoutes.php @@ -2,13 +2,10 @@ namespace Seria\Users; use RuntimeException; -use Index\Routing\Route; -use Index\Routing\RouteHandler; +use Index\Http\Routing\{HttpGet,RouteHandler}; use Sasae\SasaeEnvironment; use Seria\Auth\AuthInfo; -use Seria\Torrents\TorrentsContext; -use Seria\Torrents\TorrentInfo; -use Seria\Torrents\TorrentPeerInfo; +use Seria\Torrents\{TorrentsContext,TorrentInfo,TorrentPeerInfo}; class ProfileRoutes extends RouteHandler { public function __construct( @@ -18,7 +15,7 @@ class ProfileRoutes extends RouteHandler { private ?SasaeEnvironment $templating ) {} - #[Route('GET', '/profile/:name')] + #[HttpGet('/profile/([a-zA-Z0-9\-_]+)')] public function getProfile($response, $request, string $name) { if(!$this->authInfo->isLoggedIn()) return 403; @@ -54,7 +51,7 @@ class ProfileRoutes extends RouteHandler { ]); } - #[Route('GET', '/profile/:name/history')] + #[HttpGet('/profile/([a-zA-Z0-9\-_]+)/history')] public function getHistory($response, $request, string $name) { if(!$this->authInfo->isLoggedIn()) return 403; @@ -72,12 +69,12 @@ class ProfileRoutes extends RouteHandler { ]); } - #[Route('GET', '/profile.php')] + #[HttpGet('/profile.php')] public function getProfilePHP($response, $request): void { $response->redirect(sprintf('/profile/%s', (string)$request->getParam('name')), true); } - #[Route('GET', '/history.php')] + #[HttpGet('/history.php')] public function getHistoryPHP($response, $request) { $userName = (string)$request->getParam('name'); if($userName === '' && $this->authInfo->isLoggedIn()) diff --git a/src/Users/SettingsRoutes.php b/src/Users/SettingsRoutes.php index dc25f25..39a1598 100644 --- a/src/Users/SettingsRoutes.php +++ b/src/Users/SettingsRoutes.php @@ -1,8 +1,7 @@ authInfo->isLoggedIn()) return 403; @@ -31,18 +30,18 @@ class SettingsRoutes extends RouteHandler { } } - #[Route('GET', '/settings')] + #[HttpGet('/settings')] public function getIndex($response) { return $this->templating->render('settings'); } - #[Route('POST', '/settings/passkey')] + #[HttpPost('/settings/passkey')] public function postPasskey($response) { $this->usersCtx->getUsers()->updatePassKey($this->authInfo->getUserInfo()); $response->redirect('/settings'); } - #[Route('GET', '/settings.php')] + #[HttpGet('/settings.php')] public function getSettingsPHP($response): void { $response->redirect('/settings', true); }