From 9f6973804989053197bcd9f7b6ad20065f3dfee9 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 10 Feb 2020 16:34:18 +0300 Subject: [PATCH] refactor(core): delivery api - rename api's --- flextype/routes/api/delivery.php | 67 -------------------------------- flextype/routes/api/image.php | 25 ------------ 2 files changed, 92 deletions(-) delete mode 100644 flextype/routes/api/delivery.php delete mode 100644 flextype/routes/api/image.php diff --git a/flextype/routes/api/delivery.php b/flextype/routes/api/delivery.php deleted file mode 100644 index 730c2fef..00000000 --- a/flextype/routes/api/delivery.php +++ /dev/null @@ -1,67 +0,0 @@ -getQueryParams()['delivery_token'] . '/token.yaml'); -} - -/** - * Fetch entry(entries) - * - * endpoint: /api/entries - */ -$app->get('/api/entries', function (Request $request, Response $response) use ($flextype) { - - // Get Query Params - $query = $request->getQueryParams(); - - // Set variables - $id = $query['id']; - $args = isset($query['args']) ? $query['args'] : null; - - // Validate delivery token - if (validate_delivery_token($request, $flextype)) { - - $delivery_token_file_path = PATH['tokens'] . '/delivery/' . $request->getQueryParams()['delivery_token'] . '/token.yaml'; - - // Set delivery token file - if ($delivery_token_file_data = $flextype['parser']->decode(Filesystem::read($delivery_token_file_path), 'yaml')) { - if ($delivery_token_file_data['state'] == 'disabled' || - ($delivery_token_file_data['limit_calls'] != 0 && $delivery_token_file_data['calls'] >= $delivery_token_file_data['limit_calls'])) { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); - } else { - // Fetch entry - $data = $flextype['entries']->fetch($id, $args); - - // Set response code - $response_code = (count($data) > 0) ? 200 : 404 ; - - // Update calls counter - Filesystem::write($delivery_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_token_file_data, ['calls' => $delivery_token_file_data['calls'] + 1]), 'yaml')); - - // Return response - return $response->withJson($data, $response_code); - } - } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); - } - } else { - return $response->withJson(["detail" => "Incorrect authentication credentials."], 401); - } -}); diff --git a/flextype/routes/api/image.php b/flextype/routes/api/image.php deleted file mode 100644 index abd1a79b..00000000 --- a/flextype/routes/api/image.php +++ /dev/null @@ -1,25 +0,0 @@ -get('/api/image/{path:.+}', function (Request $request, Response $response, array $args) use ($flextype) { - if (Filesystem::has(PATH['entries'] . '/' . $args['path'])) { - return $flextype['images']->getImageResponse($args['path'], $_GET); - } - - return $response->withStatus(404); -});