Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
2 changed files with 6 additions and 24 deletions
Showing only changes of commit 5db1d8b494 - Show all commits

View File

@ -57,7 +57,6 @@ class Model {
*/ */
public function get_cached_image($api_path, $series_slug, $type = "anime") public function get_cached_image($api_path, $series_slug, $type = "anime")
{ {
$api_path = str_replace("jjpg", "jpg", $api_path);
$path_parts = explode('?', basename($api_path)); $path_parts = explode('?', basename($api_path));
$path = current($path_parts); $path = current($path_parts);
$ext_parts = explode('.', $path); $ext_parts = explode('.', $path);

View File

@ -223,7 +223,7 @@ class Anime extends API {
} }
$response = $this->get("users/{$username}/library", $config); $response = $this->get("users/{$username}/library", $config);
$output = $this->_check_cache($status, $response); $output = $this->transform($status, $response);
foreach ($output as &$row) foreach ($output as &$row)
{ {
@ -234,35 +234,18 @@ class Anime extends API {
} }
/** /**
* Handle caching of transformed api data * Handle transforming of api data
* *
* @codeCoverageIgnore
* @param string $status * @param string $status
* @param \GuzzleHttp\Message\Response * @param \GuzzleHttp\Message\Response
* @return array * @return array
*/ */
protected function _check_cache($status, $response) protected function transform($status, $response)
{ {
$cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}.json");
$transformed_cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}-transformed.json");
$cached = (file_exists($cache_file))
? Json::decodeFile($cache_file)
: [];
$api_data = Json::decode($response->getBody(), TRUE); $api_data = Json::decode($response->getBody(), TRUE);
if ($api_data === $cached && file_exists($transformed_cache_file))
{
return Json::decodeFile($transformed_cache_file);
}
else
{
Json::encodeFile($cache_file, $api_data);
$transformer = new AnimeListTransformer(); $transformer = new AnimeListTransformer();
$transformed = $transformer->transform_collection($api_data); $transformed = $transformer->transform_collection($api_data);
Json::encodeFile($transformed_cache_file, $transformed);
return $transformed; return $transformed;
} }
}
} }
// End of AnimeModel.php // End of AnimeModel.php