From 9497bd26c4a26ddde7080feca1e0c106fd2bf1c5 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 2 May 2022 21:44:30 +0300 Subject: [PATCH] feat(endpoints): add `cache` endpoints --- src/flextype/core/Endpoints/Cache.php | 54 +++++++++++++++++++++++++ src/flextype/routes/endpoints/cache.php | 35 ++++++++++++++++ src/flextype/routes/routes.php | 3 +- src/flextype/settings.yaml | 6 +++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/flextype/core/Endpoints/Cache.php create mode 100644 src/flextype/routes/endpoints/cache.php diff --git a/src/flextype/core/Endpoints/Cache.php b/src/flextype/core/Endpoints/Cache.php new file mode 100644 index 00000000..374da4a0 --- /dev/null +++ b/src/flextype/core/Endpoints/Cache.php @@ -0,0 +1,54 @@ +validateApiRequest([ + 'request' => $request, + 'api' => 'cache', + 'params' => ['token', 'access_token'], + ])) > 0 + ) { + return $this->getApiResponse($response, $this->getStatusCodeMessage($result['http_status_code']), $result['http_status_code']); + } + + // Clear cache + filesystem()->directory(PATH['tmp'])->delete(); + + // Return success response + return $this->getApiResponse($response, [], 204); + } +} diff --git a/src/flextype/routes/endpoints/cache.php b/src/flextype/routes/endpoints/cache.php new file mode 100644 index 00000000..177f4b25 --- /dev/null +++ b/src/flextype/routes/endpoints/cache.php @@ -0,0 +1,35 @@ +post('/api/v0/cache/clear', [Cache::class, 'clear'])->setName('cache.clear'); diff --git a/src/flextype/routes/routes.php b/src/flextype/routes/routes.php index a6f4ce41..979d6d09 100644 --- a/src/flextype/routes/routes.php +++ b/src/flextype/routes/routes.php @@ -3,7 +3,8 @@ declare(strict_types=1); // Add endpoints routes -require_once __DIR__ . '/endpoints/utils.php'; +require_once __DIR__ . '/endpoints/tokens.php'; +require_once __DIR__ . '/endpoints/cache.php'; require_once __DIR__ . '/endpoints/entries.php'; require_once __DIR__ . '/endpoints/registry.php'; diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 039e36ac..103b7dc6 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -668,3 +668,9 @@ api: # Set to true to enable Tokens API enabled: true + + # Cache API + tokens: + + # Set to true to enable Cache API + enabled: true \ No newline at end of file