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.
Redistribution and use in source and binary forms, with or without

50
composer.lock generated
View file

@ -12,7 +12,7 @@
"source": {
"type": "git",
"url": "https://patchii.net/flash/index.git",
"reference": "e31781c69f0b13fe251771c8e7e529222630a44f"
"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": "2023-11-20T19:01:19+00:00"
"time": "2024-03-28T23:27:04+00:00"
},
{
"name": "flashwave/syokuhou",
@ -58,7 +58,7 @@
"source": {
"type": "git",
"url": "https://patchii.net/flash/syokuhou.git",
"reference": "fdf3c38cc216bf7024af331cbe1758532355c22f"
"reference": "c1fe9371ada20fcea51c225cc53b9ceae4642bc4"
},
"require": {
"flashwave/index": "dev-master",
@ -89,7 +89,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",
@ -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.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": {
@ -558,7 +558,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": {
@ -598,7 +598,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": [
{
@ -610,7 +610,7 @@
"type": "custom"
}
],
"time": "2023-12-04T12:41:21+00:00"
"time": "2024-03-08T08:18:09+00:00"
},
{
"name": "symfony/deprecation-contracts",
@ -750,16 +750,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": {
@ -808,7 +808,7 @@
"type": "tidelift"
}
],
"time": "2023-12-13T10:59:42+00:00"
"time": "2024-03-28T16:17:31+00:00"
}
],
"aliases": [],
@ -821,5 +821,5 @@
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}

View file

@ -56,7 +56,7 @@
</div>
</div>
<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>

View file

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

View file

@ -4,7 +4,7 @@ namespace EEPROM\Auth;
use stdClass;
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)) {
$method = 'Misuzu';
$signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']);

View file

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

View file

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

View file

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