Updated EEPROM to new HTTP router.

This commit is contained in:
flash 2024-03-29 23:21:40 +00:00
parent 53bace90e8
commit d5b3f3c66f
8 changed files with 46 additions and 55 deletions

View file

@ -1,4 +1,4 @@
Copyright (c) 2020-2023, flashwave <me@flash.moe> Copyright (c) 2020-2024, flashwave <me@flash.moe>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

50
composer.lock generated
View file

@ -12,7 +12,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://patchii.net/flash/index.git", "url": "https://patchii.net/flash/index.git",
"reference": "e31781c69f0b13fe251771c8e7e529222630a44f" "reference": "9d5b050b8928435416a7efbebe2a19ae8e626224"
}, },
"require": { "require": {
"ext-mbstring": "*", "ext-mbstring": "*",
@ -50,7 +50,7 @@
], ],
"description": "Composer package for the common library for my projects.", "description": "Composer package for the common library for my projects.",
"homepage": "https://railgun.sh/index", "homepage": "https://railgun.sh/index",
"time": "2023-11-20T19:01:19+00:00" "time": "2024-03-28T23:27:04+00:00"
}, },
{ {
"name": "flashwave/syokuhou", "name": "flashwave/syokuhou",
@ -58,7 +58,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://patchii.net/flash/syokuhou.git", "url": "https://patchii.net/flash/syokuhou.git",
"reference": "fdf3c38cc216bf7024af331cbe1758532355c22f" "reference": "c1fe9371ada20fcea51c225cc53b9ceae4642bc4"
}, },
"require": { "require": {
"flashwave/index": "dev-master", "flashwave/index": "dev-master",
@ -89,7 +89,7 @@
], ],
"description": "Configuration library for PHP.", "description": "Configuration library for PHP.",
"homepage": "https://railgun.sh/syokuhou", "homepage": "https://railgun.sh/syokuhou",
"time": "2023-11-20T19:10:04+00:00" "time": "2024-01-04T02:12:49+00:00"
}, },
{ {
"name": "guzzlehttp/psr7", "name": "guzzlehttp/psr7",
@ -209,16 +209,16 @@
}, },
{ {
"name": "jean85/pretty-package-versions", "name": "jean85/pretty-package-versions",
"version": "2.0.5", "version": "2.0.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Jean85/pretty-package-versions.git", "url": "https://github.com/Jean85/pretty-package-versions.git",
"reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af" "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/ae547e455a3d8babd07b96966b17d7fd21d9c6af", "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/f9fdd29ad8e6d024f52678b570e5593759b550b4",
"reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af", "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -226,9 +226,9 @@
"php": "^7.1|^8.0" "php": "^7.1|^8.0"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.17", "friendsofphp/php-cs-fixer": "^3.2",
"jean85/composer-provided-replaced-stub-package": "^1.0", "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", "phpunit/phpunit": "^7.5|^8.5|^9.4",
"vimeo/psalm": "^4.3" "vimeo/psalm": "^4.3"
}, },
@ -262,9 +262,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/Jean85/pretty-package-versions/issues", "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", "name": "psr/http-factory",
@ -525,16 +525,16 @@
}, },
{ {
"name": "sentry/sentry", "name": "sentry/sentry",
"version": "4.1.0", "version": "4.6.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/getsentry/sentry-php.git", "url": "https://github.com/getsentry/sentry-php.git",
"reference": "89666f297891ff937fceb2f3d1fb967a6848cf37" "reference": "5a94184175e5830b589bf923da8c9c3af2c0f409"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/89666f297891ff937fceb2f3d1fb967a6848cf37", "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/5a94184175e5830b589bf923da8c9c3af2c0f409",
"reference": "89666f297891ff937fceb2f3d1fb967a6848cf37", "reference": "5a94184175e5830b589bf923da8c9c3af2c0f409",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -558,7 +558,7 @@
"phpbench/phpbench": "^1.0", "phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.3", "phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.5.14|^9.4", "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" "vimeo/psalm": "^4.17"
}, },
"suggest": { "suggest": {
@ -598,7 +598,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/getsentry/sentry-php/issues", "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": [ "funding": [
{ {
@ -610,7 +610,7 @@
"type": "custom" "type": "custom"
} }
], ],
"time": "2023-12-04T12:41:21+00:00" "time": "2024-03-08T08:18:09+00:00"
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
@ -750,16 +750,16 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.10.50", "version": "1.10.66",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "06a98513ac72c03e8366b5a0cb00750b487032e4" "reference": "94779c987e4ebd620025d9e5fdd23323903950bd"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/94779c987e4ebd620025d9e5fdd23323903950bd",
"reference": "06a98513ac72c03e8366b5a0cb00750b487032e4", "reference": "94779c987e4ebd620025d9e5fdd23323903950bd",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -808,7 +808,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-12-13T10:59:42+00:00" "time": "2024-03-28T16:17:31+00:00"
} }
], ],
"aliases": [], "aliases": [],
@ -821,5 +821,5 @@
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": [],
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.3.0" "plugin-api-version": "2.6.0"
} }

View file

@ -56,7 +56,7 @@
</div> </div>
</div> </div>
<div class="eeprom-footer"> <div class="eeprom-footer">
<a href="https://flash.moe" target="_blank" rel="noopener">flashwave</a> 2020-2023 <a href="https://flash.moe" target="_blank" rel="noopener">flashwave</a> 2020-2024
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,8 +1,7 @@
<?php <?php
namespace EEPROM\Auth; namespace EEPROM\Auth;
use Index\Routing\Route; use Index\Http\Routing\{HttpMiddleware,RouteHandler};
use Index\Routing\RouteHandler;
use Syokuhou\IConfig; use Syokuhou\IConfig;
use EEPROM\Users\UsersContext; use EEPROM\Users\UsersContext;
@ -13,7 +12,7 @@ class AuthRoutes extends RouteHandler {
private UsersContext $usersCtx private UsersContext $usersCtx
) {} ) {}
#[Route('/')] #[HttpMiddleware('/')]
public function getIndex($response, $request) { public function getIndex($response, $request) {
$auth = $request->getHeaderLine('Authorization'); $auth = $request->getHeaderLine('Authorization');
if(empty($auth)) { if(empty($auth)) {

View file

@ -4,7 +4,7 @@ namespace EEPROM\Auth;
use stdClass; use stdClass;
final class ChatAuth { final class ChatAuth {
public static function attempt(string $endPoint, string $secret, string $cookie): object { public static function attempt(string $endPoint, string $secret, string $cookie): stdClass {
if(!empty($cookie)) { if(!empty($cookie)) {
$method = 'Misuzu'; $method = 'Misuzu';
$signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']); $signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']);

View file

@ -2,21 +2,20 @@
namespace EEPROM; namespace EEPROM;
use stdClass; use stdClass;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
class LandingRoutes extends RouteHandler { class LandingRoutes extends RouteHandler {
public function __construct( public function __construct(
private DatabaseContext $dbCtx private DatabaseContext $dbCtx
) {} ) {}
#[Route('GET', '/')] #[HttpGet('/')]
public function getIndex($response) { public function getIndex($response) {
$response->accelRedirect('/index.html'); $response->accelRedirect('/index.html');
$response->setContentType('text/html; charset=utf-8'); $response->setContentType('text/html; charset=utf-8');
} }
#[Route('GET', '/stats.json')] #[HttpGet('/stats.json')]
public function getStats() { public function getStats() {
$dbConn = $this->dbCtx->getConnection(); $dbConn = $this->dbCtx->getConnection();
@ -40,7 +39,7 @@ class LandingRoutes extends RouteHandler {
return $stats; return $stats;
} }
#[Route('GET', '/eeprom.js')] #[HttpGet('/eeprom.js')]
public function getEepromJs($response) { public function getEepromJs($response) {
$response->accelRedirect('/scripts/eepromv1.js'); $response->accelRedirect('/scripts/eepromv1.js');
$response->setContentType('application/javascript; charset=utf-8'); $response->setContentType('application/javascript; charset=utf-8');

View file

@ -1,17 +1,15 @@
<?php <?php
namespace EEPROM; namespace EEPROM;
use Index\Http\HttpFx;
use Index\Http\HttpRequest; use Index\Http\HttpRequest;
use Index\Routing\IRouter; use Index\Http\Routing\{HttpRouter,IRouter,IRouteHandler};
use Index\Routing\IRouteHandler;
use Syokuhou\IConfig; use Syokuhou\IConfig;
class RoutingContext { class RoutingContext {
private HttpFx $router; private HttpRouter $router;
public function __construct(private IConfig $config) { public function __construct(private IConfig $config) {
$this->router = new HttpFx; $this->router = new HttpRouter;
$this->router->use('/', $this->middleware(...)); $this->router->use('/', $this->middleware(...));
} }

View file

@ -2,9 +2,7 @@
namespace EEPROM\Uploads; namespace EEPROM\Uploads;
use RuntimeException; use RuntimeException;
use Index\Routing\IRouter; use Index\Http\Routing\{HandlerAttribute,HttpDelete,HttpGet,HttpOptions,HttpPost,IRouter,IRouteHandler};
use Index\Routing\IRouteHandler;
use Index\Routing\Route;
use EEPROM\Apps\AppsContext; use EEPROM\Apps\AppsContext;
use EEPROM\Auth\AuthInfo; use EEPROM\Auth\AuthInfo;
use EEPROM\Blacklist\BlacklistContext; use EEPROM\Blacklist\BlacklistContext;
@ -21,16 +19,16 @@ class UploadsRoutes implements IRouteHandler {
public function registerRoutes(IRouter $router): void { public function registerRoutes(IRouter $router): void {
if($this->isApiDomain) { if($this->isApiDomain) {
Route::handleAttributes($router, $this); HandlerAttribute::register($router, $this);
} else { } else {
$router->options('/', $this->getUpload(...)); $router->options('/', $this->getUpload(...));
$router->get('/:filename', $this->getUpload(...)); $router->get('/([A-Za-z0-9]+)', $this->getUpload(...));
} }
} }
#[Route('OPTIONS', '/uploads/:filename')] #[HttpOptions('/uploads/([A-Za-z0-9]+)(?:\.(t|json))?')]
#[Route('GET', '/uploads/:filename')] #[HttpGet('/uploads/([A-Za-z0-9]+)(?:\.(t|json))?')]
public function getUpload($response, $request, string $fileName) { public function getUpload($response, $request, string $fileId, string $fileExt = '') {
if($this->isApiDomain) { if($this->isApiDomain) {
if($request->hasHeader('Origin')) if($request->hasHeader('Origin'))
$response->setHeader('Access-Control-Allow-Credentials', 'true'); $response->setHeader('Access-Control-Allow-Credentials', 'true');
@ -44,9 +42,6 @@ class UploadsRoutes implements IRouteHandler {
if($request->getMethod() === 'OPTIONS') if($request->getMethod() === 'OPTIONS')
return 204; return 204;
$pathInfo = pathinfo($fileName);
$fileId = $pathInfo['filename'];
$fileExt = $pathInfo['extension'] ?? '';
$isData = $fileExt === ''; $isData = $fileExt === '';
$isThumbnail = $fileExt === 't'; $isThumbnail = $fileExt === 't';
$isJson = $this->isApiDomain && $fileExt === 'json'; $isJson = $this->isApiDomain && $fileExt === 'json';
@ -113,8 +108,8 @@ class UploadsRoutes implements IRouteHandler {
$response->setFileName(addslashes($fileName)); $response->setFileName(addslashes($fileName));
} }
#[Route('OPTIONS', '/uploads')] #[HttpOptions('/uploads')]
#[Route('POST', '/uploads')] #[HttpPost('/uploads')]
public function postUpload($response, $request) { public function postUpload($response, $request) {
if($request->hasHeader('Origin')) if($request->hasHeader('Origin'))
$response->setHeader('Access-Control-Allow-Credentials', 'true'); $response->setHeader('Access-Control-Allow-Credentials', 'true');
@ -192,7 +187,7 @@ class UploadsRoutes implements IRouteHandler {
return $this->uploadsCtx->convertToClientJsonV1($uploadInfo); return $this->uploadsCtx->convertToClientJsonV1($uploadInfo);
} }
#[Route('DELETE', '/uploads/:fileid')] #[HttpDelete('/uploads/([A-Za-z0-9]+)')]
public function deleteUpload($response, $request, string $fileId) { public function deleteUpload($response, $request, string $fileId) {
if($request->hasHeader('Origin')) if($request->hasHeader('Origin'))
$response->setHeader('Access-Control-Allow-Credentials', 'true'); $response->setHeader('Access-Control-Allow-Credentials', 'true');