1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-10 07:06:45 +02:00

feat(rest-api): fix files rest api #435

This commit is contained in:
Awilum
2020-07-30 13:46:10 +03:00
parent 3c119cdc69
commit 9329c7d83c

View File

@@ -55,9 +55,9 @@ $app->get('/api/files', function (Request $request, Response $response) use ($fl
$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($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'])) {
if ($files_token_file_data = $flextype['yaml']->decode(Filesystem::read($files_token_file_path))) {
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_errors['0003'], $api_errors['0003']['http_status_code']);
}
@@ -78,7 +78,7 @@ $app->get('/api/files', function (Request $request, Response $response) use ($fl
$response_code = count($response_data['data']) > 0 ? 200 : 404;
// Update calls counter
Filesystem::write($files_token_file_path, $flextype['serializer']->encode(array_replace_recursive($delivery_files_token_file_data, ['calls' => $delivery_files_token_file_data['calls'] + 1]), 'yaml'));
Filesystem::write($files_token_file_path, $flextype['yaml']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -138,8 +138,8 @@ $app->post('/api/files', function (Request $request, Response $response) use ($f
$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 = $flextype['yaml']->decode(Filesystem::read($files_token_file_path))) &&
($access_token_file_data = $flextype['yaml']->decode(Filesystem::read($access_token_file_path)))) {
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_errors['0003'], $api_errors['0003']['http_status_code']);
@@ -167,7 +167,7 @@ $app->post('/api/files', function (Request $request, Response $response) use ($f
->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'));
Filesystem::write($files_token_file_path, $flextype['yaml']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -228,8 +228,8 @@ $app->put('/api/files', function (Request $request, Response $response) use ($fl
$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 = $flextype['yaml']->decode(Filesystem::read($files_token_file_path))) &&
($access_token_file_data = $flextype['yaml']->decode(Filesystem::read($access_token_file_path)))) {
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_errors['0003'], $api_errors['0003']['http_status_code']);
@@ -257,7 +257,7 @@ $app->put('/api/files', function (Request $request, Response $response) use ($fl
->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'));
Filesystem::write($files_token_file_path, $flextype['yaml']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -315,8 +315,8 @@ $app->delete('/api/files', function (Request $request, Response $response) use (
$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 = $flextype['yaml']->decode(Filesystem::read($files_token_file_path))) &&
($access_token_file_data = $flextype['yaml']->decode(Filesystem::read($access_token_file_path)))) {
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_errors['0003'], $api_errors['0003']['http_status_code']);
@@ -334,7 +334,7 @@ $app->delete('/api/files', function (Request $request, Response $response) use (
$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'));
Filesystem::write($files_token_file_path, $flextype['yaml']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -396,8 +396,8 @@ $app->patch('/api/files/meta', function (Request $request, Response $response) u
$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 = $flextype['yaml']->decode(Filesystem::read($files_token_file_path))) &&
($access_token_file_data = $flextype['yaml']->decode(Filesystem::read($access_token_file_path)))) {
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_errors['0003'], $api_errors['0003']['http_status_code']);
@@ -425,7 +425,7 @@ $app->patch('/api/files/meta', function (Request $request, Response $response) u
->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'));
Filesystem::write($files_token_file_path, $flextype['yaml']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -487,8 +487,8 @@ $app->post('/api/files/meta', function (Request $request, Response $response) us
$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 = $flextype['yaml']->decode(Filesystem::read($files_token_file_path))) &&
($access_token_file_data = $flextype['yaml']->decode(Filesystem::read($access_token_file_path)))) {
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_errors['0003'], $api_errors['0003']['http_status_code']);
@@ -516,7 +516,7 @@ $app->post('/api/files/meta', function (Request $request, Response $response) us
->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'));
Filesystem::write($files_token_file_path, $flextype['yaml']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -577,8 +577,8 @@ $app->delete('/api/files/meta', function (Request $request, Response $response)
$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 = $flextype['yaml']->decode(Filesystem::read($files_token_file_path))) &&
($access_token_file_data = $flextype['yaml']->decode(Filesystem::read($access_token_file_path)))) {
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_errors['0003'], $api_errors['0003']['http_status_code']);
@@ -606,7 +606,7 @@ $app->delete('/api/files/meta', function (Request $request, Response $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'));
Filesystem::write($files_token_file_path, $flextype['yaml']->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response