From 9d19fc2ef4c5a53b374f29e0d1cc0636c63f2ce3 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 3 Jun 2025 13:47:22 -0400 Subject: [PATCH] Update attachment routes to use plural form and add DELETE method handling --- src/FederationServer/Classes/Enums/Method.php | 12 +++++++++--- .../Methods/Attachments/DownloadAttachment.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/FederationServer/Classes/Enums/Method.php b/src/FederationServer/Classes/Enums/Method.php index 8f08ab8..9a74988 100644 --- a/src/FederationServer/Classes/Enums/Method.php +++ b/src/FederationServer/Classes/Enums/Method.php @@ -3,6 +3,7 @@ namespace FederationServer\Classes\Enums; use FederationServer\Exceptions\RequestException; + use FederationServer\Methods\Attachments\DeleteAttachment; use FederationServer\Methods\Attachments\DownloadAttachment; use FederationServer\Methods\Attachments\UploadAttachment; use FederationServer\Methods\Operators\CreateOperator; @@ -29,6 +30,7 @@ case UPLOAD_ATTACHMENT; case DOWNLOAD_ATTACHMENT; + case DELETE_ATTACHMENT; /** * Handles the request of the method @@ -74,6 +76,9 @@ case self::DOWNLOAD_ATTACHMENT: DownloadAttachment::handleRequest(); break; + case self::DELETE_ATTACHMENT: + DeleteAttachment::handleRequest(); + break; } } @@ -90,13 +95,14 @@ { $requestMethod === 'POST' && $path === '/' => null, - preg_match('#^/attachment/([a-fA-F0-9\-]{36,})$#', $path) => Method::DOWNLOAD_ATTACHMENT, - ($requestMethod === 'POST' || $requestMethod === 'PUT') && $path === '/attachment/upload' => Method::UPLOAD_ATTACHMENT, + preg_match('#^/attachments/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::DOWNLOAD_ATTACHMENT, + preg_match('#^/attachments/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_ATTACHMENT, + ($requestMethod === 'POST' || $requestMethod === 'PUT') && $path === '/attachments/upload' => Method::UPLOAD_ATTACHMENT, ($requestMethod === 'POST' || $requestMethod === 'GET') && $path === '/operators' => Method::LIST_OPERATORS, $requestMethod === 'POST' && $path === '/operators/create' => Method::CREATE_OPERATOR, preg_match('#^/operators/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'POST' => Method::GET_OPERATOR, - preg_match('#^/operators/([a-fA-F0-9\-]{36,})/delete$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_OPERATOR, + preg_match('#^/operators/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_OPERATOR, preg_match('#^/operators/([a-fA-F0-9\-]{36,})/enable$#', $path) && $requestMethod === 'POST' => Method::ENABLE_OPERATOR, preg_match('#^/operators/([a-fA-F0-9\-]{36,})/refresh$#', $path) && $requestMethod === 'POST' => Method::REFRESH_OPERATOR_API_KEY, preg_match('#^/operators/([a-fA-F0-9\-]{36,})/manage_operators$#', $path) && $requestMethod === 'POST' => Method::MANAGE_OPERATORS_PERMISSION, diff --git a/src/FederationServer/Methods/Attachments/DownloadAttachment.php b/src/FederationServer/Methods/Attachments/DownloadAttachment.php index 20bcaf5..7306385 100644 --- a/src/FederationServer/Methods/Attachments/DownloadAttachment.php +++ b/src/FederationServer/Methods/Attachments/DownloadAttachment.php @@ -18,7 +18,7 @@ */ public static function handleRequest(): void { - if(!preg_match('#^/attachment/([a-fA-F0-9\-]{36,})$#', FederationServer::getPath(), $matches)) + if(!preg_match('#^/attachments/([a-fA-F0-9\-]{36,})$#', FederationServer::getPath(), $matches)) { throw new RequestException('Attachment UUID required', 405); }