mirror of
https://github.com/flextype/flextype.git
synced 2025-08-09 14:46:53 +02:00
feat(rest-api): Moving from CDA and CMA to more universal format of REST API'S #435
This commit is contained in:
20
src/flextype/Endpoints/Utils/access.php
Normal file
20
src/flextype/Endpoints/Utils/access.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (http://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Validate access token
|
||||
*/
|
||||
function validate_access_token($token) : bool
|
||||
{
|
||||
return Filesystem::has(PATH['project'] . '/tokens/access/' . $token . '/token.yaml');
|
||||
}
|
110
src/flextype/Endpoints/Utils/errors.php
Normal file
110
src/flextype/Endpoints/Utils/errors.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (http://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
/**
|
||||
* API errors
|
||||
*/
|
||||
$api_errors = [
|
||||
'0000' => [
|
||||
'http_status_code' => 500,
|
||||
'message' => 'Internal Error',
|
||||
],
|
||||
'0001' => [
|
||||
'http_status_code' => 404,
|
||||
'message' => 'Not Found',
|
||||
],
|
||||
'0002' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Bad Request',
|
||||
],
|
||||
'0003' => [
|
||||
'http_status_code' => 401,
|
||||
'message' => 'Unauthorized',
|
||||
],
|
||||
'0100' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong query params or not defined',
|
||||
],
|
||||
'0101' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong body params or not defined',
|
||||
],
|
||||
'0102' => [
|
||||
'http_status_code' => 404,
|
||||
'message' => 'Entry not found',
|
||||
],
|
||||
'0200' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong query params or not defined',
|
||||
],
|
||||
'0201' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong body params or not defined',
|
||||
],
|
||||
'0202' => [
|
||||
'http_status_code' => 404,
|
||||
'message' => 'Config item not found',
|
||||
],
|
||||
'0300' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong query params or not defined',
|
||||
],
|
||||
'0301' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong body params or not defined',
|
||||
],
|
||||
'0302' => [
|
||||
'http_status_code' => 404,
|
||||
'message' => 'Registry item not found',
|
||||
],
|
||||
'0400' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong query params or not defined',
|
||||
],
|
||||
'0401' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong body params or not defined',
|
||||
],
|
||||
'0402' => [
|
||||
'http_status_code' => 404,
|
||||
'message' => 'Image not found',
|
||||
],
|
||||
|
||||
'0501' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong query params or not defined',
|
||||
],
|
||||
'0501' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong body params or not defined',
|
||||
],
|
||||
'0502' => [
|
||||
'http_status_code' => 404,
|
||||
'message' => 'File not found',
|
||||
],
|
||||
|
||||
'0601' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong query params or not defined',
|
||||
],
|
||||
'0601' => [
|
||||
'http_status_code' => 400,
|
||||
'message' => 'Wrong body params or not defined',
|
||||
],
|
||||
'0602' => [
|
||||
'http_status_code' => 404,
|
||||
'message' => 'Folder not found',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$api_sys_messages['AccessTokenInvalid'] = ['sys' => ['type' => 'Error', 'id' => 'AccessTokenInvalid'], 'message' => 'The access token you sent could not be found or is invalid.'];
|
||||
$api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound'], 'message' => 'The resource could not be found.'];
|
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (http://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
/**
|
||||
* API sys messages
|
||||
*/
|
||||
$api_sys_messages['AccessTokenInvalid'] = ['sys' => ['type' => 'Error', 'id' => 'AccessTokenInvalid'], 'message' => 'The access token you sent could not be found or is invalid.'];
|
||||
$api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound'], 'message' => 'The resource could not be found.'];
|
||||
|
||||
/**
|
||||
* Validate access token
|
||||
*/
|
||||
function validate_access_token($token) : bool
|
||||
{
|
||||
return Filesystem::has(PATH['project'] . '/tokens/access/' . $token . '/token.yaml');
|
||||
}
|
@@ -13,7 +13,6 @@ use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function array_replace_recursive;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Validate config token
|
||||
@@ -36,18 +35,20 @@ function validate_config_token($token) : bool
|
||||
* Returns:
|
||||
* An array of config item objects.
|
||||
*/
|
||||
$app->get('/api/config', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
$app->get('/api/config', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
if (! isset($query['id']) || ! isset($query['config']) || ! isset($query['token'])) {
|
||||
return $response->withJson($api_errors['0200'], $api_errors['0200']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$key = $query['key'];
|
||||
$config = $query['config'];
|
||||
$token = $query['token'];
|
||||
$key = $query['key'];
|
||||
$config = $query['config'];
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.config.enabled')) {
|
||||
|
||||
// Validate config token
|
||||
if (validate_config_token($token)) {
|
||||
$delivery_config_token_file_path = PATH['project'] . '/tokens/config/' . $token . '/token.yaml';
|
||||
@@ -56,7 +57,7 @@ $app->get('/api/config', function (Request $request, Response $response) use ($f
|
||||
if ($delivery_config_token_file_data = $flextype['serializer']->decode(Filesystem::read($delivery_config_token_file_path), 'yaml')) {
|
||||
if ($delivery_config_token_file_data['state'] === 'disabled' ||
|
||||
($delivery_config_token_file_data['limit_calls'] !== 0 && $delivery_config_token_file_data['calls'] >= $delivery_config_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Fetch config
|
||||
@@ -66,7 +67,6 @@ $app->get('/api/config', function (Request $request, Response $response) use ($f
|
||||
|
||||
// Set response code
|
||||
$response_code = 200;
|
||||
|
||||
} else {
|
||||
$response_data = [];
|
||||
$response_code = 404;
|
||||
@@ -75,11 +75,10 @@ $app->get('/api/config', function (Request $request, Response $response) use ($f
|
||||
// Update calls counter
|
||||
Filesystem::write($delivery_config_token_file_path, $flextype['serializer']->encode(array_replace_recursive($delivery_config_token_file_data, ['calls' => $delivery_config_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0202'], $api_errors['0202']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -88,15 +87,15 @@ $app->get('/api/config', function (Request $request, Response $response) use ($f
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
|
||||
@@ -114,11 +113,14 @@ $app->get('/api/config', function (Request $request, Response $response) use ($f
|
||||
* Returns:
|
||||
* Returns the config item object for the config item that was just created.
|
||||
*/
|
||||
$app->post('/api/config', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
$app->post('/api/config', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['config']) || ! isset($post_data['data'])) {
|
||||
return $response->withJson($api_errors['0201'], $api_errors['0201']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -126,7 +128,6 @@ $app->post('/api/config', function (Request $request, Response $response) use ($
|
||||
$data = $post_data['data'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.config.enabled')) {
|
||||
|
||||
// Validate config and access token
|
||||
if (validate_config_token($token) && validate_access_token($access_token)) {
|
||||
$config_token_file_path = PATH['project'] . '/tokens/config/' . $token . '/token.yaml';
|
||||
@@ -135,15 +136,14 @@ $app->post('/api/config', function (Request $request, Response $response) use ($
|
||||
// Set config and access token file
|
||||
if (($config_token_file_data = $flextype['serializer']->decode(Filesystem::read($config_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($config_token_file_data['state'] === 'disabled' ||
|
||||
($config_token_file_data['limit_calls'] !== 0 && $config_token_file_data['calls'] >= $config_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Create config
|
||||
@@ -151,7 +151,7 @@ $app->post('/api/config', function (Request $request, Response $response) use ($
|
||||
|
||||
if ($create_config) {
|
||||
$response_data['data']['key'] = $data['key'];
|
||||
$response_data['data']['value'] = $flextype['config']->get($config, $data['key']);;
|
||||
$response_data['data']['value'] = $flextype['config']->get($config, $data['key']);
|
||||
|
||||
// Set response code
|
||||
$response_code = 200;
|
||||
@@ -161,16 +161,15 @@ $app->post('/api/config', function (Request $request, Response $response) use ($
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($create_config) ? 200 : 404;
|
||||
$response_code = $create_config ? 200 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($config_token_file_path, $flextype['serializer']->encode(array_replace_recursive($config_token_file_data, ['calls' => $config_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0202'], $api_errors['0202']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -179,15 +178,15 @@ $app->post('/api/config', function (Request $request, Response $response) use ($
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -204,11 +203,14 @@ $app->post('/api/config', function (Request $request, Response $response) use ($
|
||||
* Returns:
|
||||
* Returns the config item object for the config item that was just created.
|
||||
*/
|
||||
$app->patch('/api/config', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
$app->patch('/api/config', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['config']) || ! isset($post_data['data'])) {
|
||||
return $response->withJson($api_errors['0201'], $api_errors['0201']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -216,25 +218,22 @@ $app->patch('/api/config', function (Request $request, Response $response) use (
|
||||
$config = $post_data['config'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.config.enabled')) {
|
||||
|
||||
// Validate config and access token
|
||||
if (validate_config_token($token) && validate_access_token($access_token)) {
|
||||
|
||||
$config_token_file_path = PATH['project'] . '/tokens/config/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set config and access token file
|
||||
if (($config_token_file_data = $flextype['serializer']->decode(Filesystem::read($config_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($config_token_file_data['state'] === 'disabled' ||
|
||||
($config_token_file_data['limit_calls'] !== 0 && $config_token_file_data['calls'] >= $config_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Update config
|
||||
@@ -252,16 +251,15 @@ $app->patch('/api/config', function (Request $request, Response $response) use (
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($update_config) ? 200 : 404;
|
||||
$response_code = $update_config ? 200 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($config_token_file_path, $flextype['serializer']->encode(array_replace_recursive($config_token_file_data, ['calls' => $config_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0202'], $api_errors['0202']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -270,16 +268,15 @@ $app->patch('/api/config', function (Request $request, Response $response) use (
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -296,11 +293,14 @@ $app->patch('/api/config', function (Request $request, Response $response) use (
|
||||
* Returns:
|
||||
* Returns an empty body with HTTP status 204
|
||||
*/
|
||||
$app->delete('/api/config', function (Request $request, Response $response) use ($flextype) {
|
||||
|
||||
$app->delete('/api/config', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['config']) || ! isset($post_data['data'])) {
|
||||
return $response->withJson($api_errors['0201'], $api_errors['0201']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -308,7 +308,6 @@ $app->delete('/api/config', function (Request $request, Response $response) use
|
||||
$config = $post_data['config'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.config.enabled')) {
|
||||
|
||||
// Validate config and access token
|
||||
if (validate_config_token($token) && validate_access_token($access_token)) {
|
||||
$config_token_file_path = PATH['project'] . '/tokens/config/' . $token . '/token.yaml';
|
||||
@@ -317,31 +316,29 @@ $app->delete('/api/config', function (Request $request, Response $response) use
|
||||
// Set config and access token file
|
||||
if (($config_token_file_data = $flextype['serializer']->decode(Filesystem::read($config_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($config_token_file_data['state'] === 'disabled' ||
|
||||
($config_token_file_data['limit_calls'] !== 0 && $config_token_file_data['calls'] >= $config_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Delete entry
|
||||
$delete_config = $flextype['config']->delete($config, $data['key']);
|
||||
|
||||
// Set response code
|
||||
$response_code = ($delete_config) ? 204 : 404;
|
||||
$response_code = $delete_config ? 204 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($config_token_file_path, $flextype['serializer']->encode(array_replace_recursive($config_token_file_data, ['calls' => $config_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0202'], $api_errors['0202']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -350,13 +347,13 @@ $app->delete('/api/config', function (Request $request, Response $response) use
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
@@ -13,6 +13,7 @@ use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function array_replace_recursive;
|
||||
use function collect_filter;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
@@ -36,31 +37,38 @@ function validate_entries_token($token) : bool
|
||||
* Returns:
|
||||
* An array of entry item objects.
|
||||
*/
|
||||
$app->get('/api/entries', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
$app->get('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
if (! isset($query['id']) || ! isset($query['token'])) {
|
||||
return $response->withJson($api_errors['0100'], $api_errors['0100']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$id = $query['id'];
|
||||
$token = $query['token'];
|
||||
$filter = $query['filter'] ?? null;
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
|
||||
// Validate entries token
|
||||
if (validate_entries_token($token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/' . $token. '/token.yaml';
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
|
||||
// Set entries token file
|
||||
if ($entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($entries_token_file_path), 'yaml')) {
|
||||
if ($entries_token_file_data['state'] === 'disabled' ||
|
||||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Fetch entry
|
||||
$response_data['data'] = $flextype['entries']->fetch($id, $filter);
|
||||
// Fetch entries collection
|
||||
if ($filter !== null) {
|
||||
$response_data['data'] = collect_filter($flextype['entries']->fetch($id, true), $filter);
|
||||
}
|
||||
|
||||
// Fetch single entry
|
||||
$response_data['data'] = $flextype['entries']->fetch($id);
|
||||
|
||||
// Set response code
|
||||
$response_code = count($response_data['data']) > 0 ? 200 : 404;
|
||||
@@ -68,28 +76,22 @@ $app->get('/api/entries', function (Request $request, Response $response) use ($
|
||||
// Update calls counter
|
||||
Filesystem::write($entries_token_file_path, $flextype['serializer']->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
return $response->withJson($api_errors['0102'], $api_errors['0102']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($response_data, $response_code);
|
||||
return $response->withJson($response_data, $response_code);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -106,11 +108,14 @@ $app->get('/api/entries', function (Request $request, Response $response) use ($
|
||||
* Returns:
|
||||
* Returns the entry item object for the entry item that was just created.
|
||||
*/
|
||||
$app->post('/api/entries', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
$app->post('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['data'])) {
|
||||
return $response->withJson($api_errors['0101'], $api_errors['0101']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -118,24 +123,22 @@ $app->post('/api/entries', function (Request $request, Response $response) use (
|
||||
$data = $post_data['data'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set entries and access token file
|
||||
if (($entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($entries_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($entries_token_file_data['state'] === 'disabled' ||
|
||||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Create entry
|
||||
@@ -148,16 +151,15 @@ $app->post('/api/entries', function (Request $request, Response $response) use (
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($create_entry) ? 200 : 404;
|
||||
$response_code = $create_entry ? 200 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($entries_token_file_path, $flextype['serializer']->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0102'], $api_errors['0102']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -166,15 +168,15 @@ $app->post('/api/entries', function (Request $request, Response $response) use (
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -191,11 +193,14 @@ $app->post('/api/entries', function (Request $request, Response $response) use (
|
||||
* Returns:
|
||||
* Returns the entry item object for the entry item that was just updated.
|
||||
*/
|
||||
$app->patch('/api/entries', function (Request $request, Response $response) use ($flextype) {
|
||||
|
||||
$app->patch('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['data'])) {
|
||||
return $response->withJson($api_errors['0101'], $api_errors['0101']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -203,24 +208,22 @@ $app->patch('/api/entries', function (Request $request, Response $response) use
|
||||
$data = $post_data['data'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set entries and access token file
|
||||
if (($entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($entries_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($entries_token_file_data['state'] === 'disabled' ||
|
||||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Update entry
|
||||
@@ -233,16 +236,15 @@ $app->patch('/api/entries', function (Request $request, Response $response) use
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($update_entry) ? 200 : 404;
|
||||
$response_code = $update_entry ? 200 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($entries_token_file_path, $flextype['serializer']->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0102'], $api_errors['0102']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -251,15 +253,15 @@ $app->patch('/api/entries', function (Request $request, Response $response) use
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -276,36 +278,37 @@ $app->patch('/api/entries', function (Request $request, Response $response) use
|
||||
* Returns:
|
||||
* Returns the entry item object for the entry item that was just renamed.
|
||||
*/
|
||||
$app->put('/api/entries', function (Request $request, Response $response) use ($flextype) {
|
||||
|
||||
$app->put('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['new_id'])) {
|
||||
return $response->withJson($api_errors['0101'], $api_errors['0101']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set entries and access token file
|
||||
if (($entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($entries_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($entries_token_file_data['state'] === 'disabled' ||
|
||||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Rename entry
|
||||
@@ -319,16 +322,15 @@ $app->put('/api/entries', function (Request $request, Response $response) use ($
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($rename_entry) ? 200 : 404;
|
||||
$response_code = $rename_entry ? 200 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($entries_token_file_path, $flextype['serializer']->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0102'], $api_errors['0102']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -337,15 +339,15 @@ $app->put('/api/entries', function (Request $request, Response $response) use ($
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -362,36 +364,37 @@ $app->put('/api/entries', function (Request $request, Response $response) use ($
|
||||
* Returns:
|
||||
* Returns the entry item object for the entry item that was just copied.
|
||||
*/
|
||||
$app->put('/api/entries/copy', function (Request $request, Response $response) use ($flextype) {
|
||||
|
||||
$app->put('/api/entries/copy', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['new_id'])) {
|
||||
return $response->withJson($api_errors['0101'], $api_errors['0101']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set entries and access token file
|
||||
if (($entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($entries_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($entries_token_file_data['state'] === 'disabled' ||
|
||||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Copy entry
|
||||
@@ -405,16 +408,15 @@ $app->put('/api/entries/copy', function (Request $request, Response $response) u
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($copy_entry) ? 200 : 404;
|
||||
$response_code = $copy_entry ? 200 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($entries_token_file_path, $flextype['serializer']->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0102'], $api_errors['0102']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -423,15 +425,15 @@ $app->put('/api/entries/copy', function (Request $request, Response $response) u
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -447,51 +449,51 @@ $app->put('/api/entries/copy', function (Request $request, Response $response) u
|
||||
* Returns:
|
||||
* Returns an empty body with HTTP status 204
|
||||
*/
|
||||
$app->delete('/api/entries', function (Request $request, Response $response) use ($flextype) {
|
||||
|
||||
$app->delete('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) {
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id'])) {
|
||||
return $response->withJson($api_errors['0101'], $api_errors['0101']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set entries and access token file
|
||||
if (($entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($entries_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($entries_token_file_data['state'] === 'disabled' ||
|
||||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Delete entry
|
||||
$delete_entry = $flextype['entries']->delete($id);
|
||||
|
||||
// Set response code
|
||||
$response_code = ($delete_entry) ? 204 : 404;
|
||||
$response_code = $delete_entry ? 204 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($entries_token_file_path, $flextype['serializer']->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0102'], $api_errors['0102']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -500,13 +502,13 @@ $app->delete('/api/entries', function (Request $request, Response $response) use
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
@@ -13,6 +13,9 @@ use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function array_replace_recursive;
|
||||
use function basename;
|
||||
use function count;
|
||||
use function is_dir;
|
||||
|
||||
/**
|
||||
* Validate files token
|
||||
@@ -35,25 +38,27 @@ function validate_files_token($token) : bool
|
||||
* An array of file item objects.
|
||||
*/
|
||||
$app->get('/api/files', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
if (! isset($query['path']) || ! isset($query['token'])) {
|
||||
return $response->withJson($api_errors['0500'], $api_errors['0500']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$path = $query['path'];
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
|
||||
// Validate delivery token
|
||||
if (validate_files_token($token)) {
|
||||
$delivery_files_token_file_path = PATH['project'] . '/tokens/files/' . $token. '/token.yaml';
|
||||
$delivery_files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
|
||||
// Set delivery token file
|
||||
if ($delivery_files_token_file_data = $flextype['serializer']->decode(Filesystem::read($delivery_files_token_file_path), 'yaml')) {
|
||||
if ($delivery_files_token_file_data['state'] === 'disabled' ||
|
||||
($delivery_files_token_file_data['limit_calls'] !== 0 && $delivery_files_token_file_data['calls'] >= $delivery_files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Create files array
|
||||
@@ -75,8 +80,7 @@ $app->get('/api/files', function (Request $request, Response $response) use ($fl
|
||||
// Update calls counter
|
||||
Filesystem::write($delivery_files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($delivery_files_token_file_data, ['calls' => $delivery_files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
@@ -114,10 +118,13 @@ $app->get('/api/files', function (Request $request, Response $response) use ($fl
|
||||
* Returns the file object for the file that was just created.
|
||||
*/
|
||||
$app->post('/api/files', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['path']) || ! isset($post_data['access_token']) || ! isset($post_data['folder']) || !isset($_FILES['file'])) {
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -125,24 +132,22 @@ $app->post('/api/files', function (Request $request, Response $response) use ($f
|
||||
$file = $_FILES['file'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Create file
|
||||
@@ -155,7 +160,7 @@ $app->post('/api/files', function (Request $request, Response $response) use ($f
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = (Filesystem::has($create_file)) ? 200 : 404;
|
||||
$response_code = Filesystem::has($create_file) ? 200 : 404;
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
@@ -164,8 +169,7 @@ $app->post('/api/files', function (Request $request, Response $response) use ($f
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
@@ -204,10 +208,13 @@ $app->post('/api/files', function (Request $request, Response $response) use ($f
|
||||
* Returns the file object for the file that was just created.
|
||||
*/
|
||||
$app->put('/api/files', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['path']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['new_id'])) {
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -215,24 +222,22 @@ $app->put('/api/files', function (Request $request, Response $response) use ($fl
|
||||
$new_id = $post_data['new_id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Rename file
|
||||
@@ -245,7 +250,7 @@ $app->put('/api/files', function (Request $request, Response $response) use ($fl
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = (Filesystem::has($rename_file)) ? 200 : 404;
|
||||
$response_code = Filesystem::has($rename_file) ? 200 : 404;
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
@@ -254,8 +259,7 @@ $app->put('/api/files', function (Request $request, Response $response) use ($fl
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
@@ -292,47 +296,47 @@ $app->put('/api/files', function (Request $request, Response $response) use ($fl
|
||||
* Returns an empty body with HTTP status 204
|
||||
*/
|
||||
$app->delete('/api/files', function (Request $request, Response $response) use ($flextype) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['path']) || ! isset($post_data['access_token']) || ! isset($post_data['id'])) {
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Delete file
|
||||
$delete_file = $flextype['media_files']->delete($id);
|
||||
|
||||
// Set response code
|
||||
$response_code = ($delete_file) ? 204 : 404;
|
||||
$response_code = $delete_file ? 204 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
@@ -371,10 +375,13 @@ $app->delete('/api/files', function (Request $request, Response $response) use (
|
||||
* Returns the file object for the file that was just created.
|
||||
*/
|
||||
$app->patch('/api/files/meta', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['field']) || ! isset($post_data['value'])) {
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -383,24 +390,22 @@ $app->patch('/api/files/meta', function (Request $request, Response $response) u
|
||||
$value = $post_data['value'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Update file meta
|
||||
@@ -413,7 +418,7 @@ $app->patch('/api/files/meta', function (Request $request, Response $response) u
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($update_file_meta) ? 200 : 404;
|
||||
$response_code = $update_file_meta ? 200 : 404;
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
@@ -422,8 +427,7 @@ $app->patch('/api/files/meta', function (Request $request, Response $response) u
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
@@ -462,10 +466,13 @@ $app->patch('/api/files/meta', function (Request $request, Response $response) u
|
||||
* Returns the file object for the file that was just created.
|
||||
*/
|
||||
$app->post('/api/files/meta', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['field']) || ! isset($post_data['value'])) {
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -474,24 +481,22 @@ $app->post('/api/files/meta', function (Request $request, Response $response) us
|
||||
$value = $post_data['value'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Add file meta
|
||||
@@ -504,7 +509,7 @@ $app->post('/api/files/meta', function (Request $request, Response $response) us
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($add_file_meta) ? 200 : 404;
|
||||
$response_code = $add_file_meta ? 200 : 404;
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
@@ -513,8 +518,7 @@ $app->post('/api/files/meta', function (Request $request, Response $response) us
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
@@ -553,10 +557,13 @@ $app->post('/api/files/meta', function (Request $request, Response $response) us
|
||||
* Returns the file object for the file that was just created.
|
||||
*/
|
||||
$app->delete('/api/files/meta', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['field'])) {
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
@@ -564,24 +571,22 @@ $app->delete('/api/files/meta', function (Request $request, Response $response)
|
||||
$field = $post_data['field'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Delete file meta
|
||||
@@ -594,7 +599,7 @@ $app->delete('/api/files/meta', function (Request $request, Response $response)
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($delete_file_meta) ? 200 : 404;
|
||||
$response_code = $delete_file_meta ? 200 : 404;
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
@@ -603,8 +608,7 @@ $app->delete('/api/files/meta', function (Request $request, Response $response)
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
|
@@ -13,6 +13,7 @@ use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function array_replace_recursive;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Validate folders token
|
||||
@@ -36,7 +37,6 @@ function validate_folders_token($token) : bool
|
||||
* An array of folder(s) item objects.
|
||||
*/
|
||||
$app->get('/api/folders', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
@@ -46,25 +46,24 @@ $app->get('/api/folders', function (Request $request, Response $response) use ($
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.folders.enabled')) {
|
||||
|
||||
// Validate delivery token
|
||||
if (validate_folders_token($token)) {
|
||||
$folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token. '/token.yaml';
|
||||
$folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml';
|
||||
|
||||
// Set delivery token file
|
||||
if ($folders_token_file_data = $flextype['serializer']->decode(Filesystem::read($folders_token_file_path), 'yaml')) {
|
||||
if ($folders_token_file_data['state'] === 'disabled' ||
|
||||
($folders_token_file_data['limit_calls'] !== 0 && $folders_token_file_data['calls'] >= $folders_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Create folders array
|
||||
$folders = [];
|
||||
|
||||
// Get list if folder or fodlers for specific folder
|
||||
if ($mode == 'collection') {
|
||||
if ($mode === 'collection') {
|
||||
$folders = $flextype['media_folders']->fetchCollection($path);
|
||||
} elseif ($mode == 'single') {
|
||||
} elseif ($mode === 'single') {
|
||||
$folders = $flextype['media_folders']->fetchSingle($path);
|
||||
}
|
||||
|
||||
@@ -77,8 +76,7 @@ $app->get('/api/folders', function (Request $request, Response $response) use ($
|
||||
// Update calls counter
|
||||
Filesystem::write($folders_token_file_path, $flextype['serializer']->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
@@ -116,76 +114,72 @@ $app->get('/api/folders', function (Request $request, Response $response) use ($
|
||||
* Returns the file object for the file that was just created.
|
||||
*/
|
||||
$app->post('/api/folders', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$path = $post_data['path'];
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$path = $post_data['path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Create folder
|
||||
$create_folder = $flextype['media_folders']->create($path);
|
||||
// Create folder
|
||||
$create_folder = $flextype['media_folders']->create($path);
|
||||
|
||||
if ($create_folder) {
|
||||
$response_data['data'] = $flextype['media_folders']->fetch($path);
|
||||
} else {
|
||||
$response_data['data'] = [];
|
||||
}
|
||||
if ($create_folder) {
|
||||
$response_data['data'] = $flextype['media_folders']->fetch($path);
|
||||
} else {
|
||||
$response_data['data'] = [];
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($create_folder) ? 200 : 404;
|
||||
// Set response code
|
||||
$response_code = $create_folder ? 200 : 404;
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($response_data, $response_code);
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
}
|
||||
}
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($response_data, $response_code);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
});
|
||||
|
||||
@@ -204,77 +198,73 @@ $app->post('/api/folders', function (Request $request, Response $response) use (
|
||||
* Returns the file object for the file that was just created.
|
||||
*/
|
||||
$app->put('/api/folders', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Rename folder
|
||||
$rename_folder = $flextype['media_folders']->rename($id, $new_id);
|
||||
// Rename folder
|
||||
$rename_folder = $flextype['media_folders']->rename($id, $new_id);
|
||||
|
||||
if ($rename_folder) {
|
||||
$response_data['data'] = $flextype['media_folders']->fetch($new_id);
|
||||
} else {
|
||||
$response_data['data'] = [];
|
||||
}
|
||||
if ($rename_folder) {
|
||||
$response_data['data'] = $flextype['media_folders']->fetch($new_id);
|
||||
} else {
|
||||
$response_data['data'] = [];
|
||||
}
|
||||
|
||||
// Set response code
|
||||
$response_code = ($rename_folder) ? 200 : 404;
|
||||
// Set response code
|
||||
$response_code = $rename_folder ? 200 : 404;
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($response_data, $response_code);
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
}
|
||||
}
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($response_data, $response_code);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
});
|
||||
|
||||
@@ -292,65 +282,61 @@ $app->put('/api/folders', function (Request $request, Response $response) use ($
|
||||
* Returns an empty body with HTTP status 204
|
||||
*/
|
||||
$app->delete('/api/folders', function (Request $request, Response $response) use ($flextype) {
|
||||
|
||||
// Get Post Data
|
||||
$post_data = $request->getParsedBody();
|
||||
$post_data = $request->getParsedBody();
|
||||
|
||||
// Set variables
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
$token = $post_data['token'];
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
|
||||
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
// Set files and access token file
|
||||
if (($files_token_file_data = $flextype['serializer']->decode(Filesystem::read($files_token_file_path), 'yaml')) &&
|
||||
($access_token_file_data = $flextype['serializer']->decode(Filesystem::read($access_token_file_path), 'yaml'))) {
|
||||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
if ($files_token_file_data['state'] === 'disabled' ||
|
||||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
if ($access_token_file_data['state'] === 'disabled' ||
|
||||
($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
return $response->withJson($api_errors['0501'], $api_errors['0501']['http_status_code']);
|
||||
}
|
||||
|
||||
// Delete folder
|
||||
$delete_folder = $flextype['media_folders']->delete($id);
|
||||
// Delete folder
|
||||
$delete_folder = $flextype['media_folders']->delete($id);
|
||||
|
||||
// Set response code
|
||||
$response_code = ($delete_folder) ? 204 : 404;
|
||||
// Set response code
|
||||
$response_code = $delete_folder ? 204 : 404;
|
||||
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
// Update calls counter
|
||||
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
}
|
||||
}
|
||||
|
||||
// Return response
|
||||
return $response
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($delete_file, $response_code);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
}
|
||||
}
|
||||
|
||||
return $response
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
});
|
||||
|
@@ -37,26 +37,27 @@ function validate_images_token($token) : bool
|
||||
* Returns:
|
||||
* Image file
|
||||
*/
|
||||
$app->get('/api/images/{path:.+}', function (Request $request, Response $response, $args) use ($flextype, $api_sys_messages) {
|
||||
|
||||
$app->get('/api/images/{path:.+}', function (Request $request, Response $response, $args) use ($flextype) {
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
if (! isset($query['token'])) {
|
||||
return $response->withJson($api_errors['0400'], $api_errors['0400']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.images.enabled')) {
|
||||
|
||||
// Validate delivery image token
|
||||
if (validate_images_token($token)) {
|
||||
$delivery_images_token_file_path = PATH['project'] . '/tokens/images/' . $token . '/token.yaml';
|
||||
|
||||
// Set delivery token file
|
||||
if ($delivery_images_token_file_data = $flextype['serializer']->decode(Filesystem::read($delivery_images_token_file_path), 'yaml')) {
|
||||
|
||||
if ($delivery_images_token_file_data['state'] === 'disabled' ||
|
||||
($delivery_images_token_file_data['limit_calls'] !== 0 && $delivery_images_token_file_data['calls'] >= $delivery_images_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Update calls counter
|
||||
@@ -69,17 +70,17 @@ $app->get('/api/images/{path:.+}', function (Request $request, Response $respons
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], 404);
|
||||
->withJson($api_errors['0402'], $api_errors['0402']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
@@ -34,17 +34,19 @@ function validate_registry_token($token) : bool
|
||||
* Returns:
|
||||
* An array of registry item objects.
|
||||
*/
|
||||
$app->get('/api/registry', function (Request $request, Response $response) use ($flextype, $api_sys_messages) {
|
||||
|
||||
$app->get('/api/registry', function (Request $request, Response $response) use ($flextype) {
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
if (! isset($query['id']) || ! isset($query['token'])) {
|
||||
return $response->withJson($api_errors['0300'], $api_errors['0300']['http_status_code']);
|
||||
}
|
||||
|
||||
// Set variables
|
||||
$id = $query['id'];
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.registry.enabled')) {
|
||||
|
||||
// Validate token
|
||||
if (validate_registry_token($token)) {
|
||||
$registry_token_file_path = PATH['project'] . '/tokens/registry/' . $token . '/token.yaml';
|
||||
@@ -53,7 +55,7 @@ $app->get('/api/registry', function (Request $request, Response $response) use (
|
||||
if ($registry_token_file_data = $flextype['serializer']->decode(Filesystem::read($registry_token_file_path), 'yaml')) {
|
||||
if ($registry_token_file_data['state'] === 'disabled' ||
|
||||
($registry_token_file_data['limit_calls'] !== 0 && $registry_token_file_data['calls'] >= $registry_token_file_data['limit_calls'])) {
|
||||
return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
return $response->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
// Fetch registry
|
||||
@@ -63,7 +65,6 @@ $app->get('/api/registry', function (Request $request, Response $response) use (
|
||||
|
||||
// Set response code
|
||||
$response_code = 200;
|
||||
|
||||
} else {
|
||||
$response_data = [];
|
||||
$response_code = 404;
|
||||
@@ -72,11 +73,10 @@ $app->get('/api/registry', function (Request $request, Response $response) use (
|
||||
// Update calls counter
|
||||
Filesystem::write($registry_token_file_path, $flextype['serializer']->encode(array_replace_recursive($registry_token_file_data, ['calls' => $registry_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if ($response_code == 404) {
|
||||
|
||||
if ($response_code === 404) {
|
||||
// Return response
|
||||
return $response
|
||||
->withJson($api_sys_messages['NotFound'], $response_code);
|
||||
->withJson($api_errors['0302'], $api_errors['0302']['http_status_code']);
|
||||
}
|
||||
|
||||
// Return response
|
||||
@@ -85,13 +85,13 @@ $app->get('/api/registry', function (Request $request, Response $response) use (
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
}
|
||||
|
||||
return $response
|
||||
->withJson($api_sys_messages['AccessTokenInvalid'], 401);
|
||||
->withJson($api_errors['0003'], $api_errors['0003']['http_status_code']);
|
||||
});
|
||||
|
Reference in New Issue
Block a user