Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
15 changed files with 45 additions and 23 deletions
Showing only changes of commit 5d90721197 - Show all commits

View File

@ -59,9 +59,7 @@ export function renderSearchResults (type, data, isCollection = false) {
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${item.id}" ${disabled} />
<label for="${item.slug}">
<picture width="220">
<source srcset="/public/images/${type}/${item.id}.webp" type="image/webp" />
<source srcset="/public/images/${type}/${item.id}.jpg" type="image/jpeg" />
<img src="/public/images/${type}/${item.id}.jpg" alt="" width="220" />
<img src="${item.coverImage}" alt="" width="220" />
</picture>
<span class="name">
${item.canonicalTitle}<br />

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -534,6 +534,7 @@ final class Model {
$searchItem = [
'id' => $item['id'],
'slug' => $item['slug'],
'coverImage' => K::getPosterImage($item),
'canonicalTitle' => $item['titles']['canonical'],
'titles' => array_values(K::getTitles($item['titles'])),
'libraryEntry' => $item['myLibraryEntry'],

View File

@ -2,6 +2,14 @@ query ($query: String!) {
searchAnimeByTitle(title: $query, first: 20) {
nodes {
id
posterImage {
original {
url
}
views {
url
}
}
mappings(first: 10) {
nodes {
externalId

View File

@ -2,6 +2,14 @@ query ($query: String!) {
searchMangaByTitle(title: $query, first: 20) {
nodes {
id
posterImage {
original {
url
}
views {
url
}
}
mappings(first: 10) {
nodes {
externalId

View File

@ -96,9 +96,7 @@ final class AnimeListTransformer extends AbstractTransformer {
'titles' => $titles,
'slug' => $anime['slug'],
'show_type' => (string)StringType::from($anime['subtype'])->upperCaseFirst(),
'cover_image' => $anime['posterImage']['views'][1]['url']
?? $anime['posterImage']['original']['url']
?? '/public/images/placeholder.png',
'cover_image' => Kitsu::getPosterImage($anime),
'genres' => $genres,
'streaming_links' => $streamingLinks,
],

View File

@ -125,9 +125,7 @@ final class AnimeTransformer extends AbstractTransformer {
'age_rating' => $base['ageRating'],
'age_rating_guide' => $base['ageRatingGuide'],
'characters' => $characters,
'cover_image' => $base['posterImage']['views'][1]['url']
?? $base['posterImage']['original']['url']
?? '/public/images/placeholder.png',
'cover_image' => Kitsu::getPosterImage($base),
'episode_count' => $base['episodeCount'],
'episode_length' => $base['episodeLength'],
'genres' => $genres,

View File

@ -17,6 +17,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\Types\HistoryItem;
use Aviat\AnimeClient\Kitsu;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
@ -186,7 +187,6 @@ abstract class HistoryTransformer {
{
$data = $entry['media'];
$title = $this->linkTitle($data);
$imgUrl = $data['posterImage']['views'][0]['url'] ?? $data['posterImage']['original']['url'];
$item = end($entry['changedData']['progress']);
// No showing episode 0 nonsense
@ -214,7 +214,7 @@ abstract class HistoryTransformer {
return HistoryItem::from([
'action' => $action,
'coverImg' => $imgUrl,
'coverImg' => Kitsu::getPosterImage($data, 0),
'kind' => 'progressed',
'original' => $entry,
'title' => $title,
@ -227,7 +227,6 @@ abstract class HistoryTransformer {
{
$data = $entry['media'];
$title = $this->linkTitle($data);
$imgUrl = $data['posterImage']['views'][0]['url'] ?? $data['posterImage']['original']['url'];
$kind = array_key_first($entry['changedData']);
@ -245,7 +244,7 @@ abstract class HistoryTransformer {
return HistoryItem::from([
'action' => $statusName,
'coverImg' => $imgUrl,
'coverImg' => Kitsu::getPosterImage($data, 0),
'kind' => 'updated',
'original' => $entry,
'title' => $title,

View File

@ -102,9 +102,7 @@ final class LibraryEntryTransformer extends AbstractTransformer
'titles' => $titles,
'slug' => $anime['slug'],
'show_type' => (string)StringType::from($anime['subtype'])->upperCaseFirst(),
'cover_image' => $anime['posterImage']['views'][1]['url']
?? $anime['posterImage']['original']['url']
?? '/public/images/placeholder.png',
'cover_image' => Kitsu::getPosterImage($anime),
'genres' => $genres,
'streaming_links' => $streamingLinks,
],
@ -169,7 +167,7 @@ final class LibraryEntryTransformer extends AbstractTransformer
'manga' => MangaListItemDetail::from([
'genres' => $genres,
'id' => $mangaId,
'image' => $manga['posterImage']['views'][1]['url'],
'image' => Kitsu::getPosterImage($manga),
'slug' => $manga['slug'],
'title' => $title,
'titles' => $titles,

View File

@ -91,7 +91,7 @@ final class MangaListTransformer extends AbstractTransformer {
'manga' => MangaListItemDetail::from([
'genres' => $genres,
'id' => $mangaId,
'image' => $manga['posterImage']['views'][1]['url'],
'image' => Kitsu::getPosterImage($manga),
'slug' => $manga['slug'],
'title' => $title,
'titles' => $titles,

View File

@ -125,7 +125,7 @@ final class MangaTransformer extends AbstractTransformer {
'characters' => $characters,
'chapter_count' => $base['chapterCount'],
'volume_count' => $base['volumeCount'],
'cover_image' => $base['posterImage']['views'][1]['url'],
'cover_image' => Kitsu::getPosterImage($base),
'genres' => $genres,
'links' => $links,
'manga_type' => $base['subtype'],

View File

@ -84,7 +84,7 @@ final class PersonTransformer extends AbstractTransformer {
'title' => $title,
'titles' => array_merge([$title], Kitsu::getFilteredTitles($media['titles'])),
'image' => [
'original' => $media['posterImage']['views'][1]['url'] ?? '',
'original' => Kitsu::getPosterImage($media)
],
'slug' => $media['slug'],
];

View File

@ -336,6 +336,20 @@ final class Kitsu {
return $valid;
}
/**
* Get the url of the posterImage from Kitsu, with fallbacks
*
* @param array $base
* @param int $size
* @return string
*/
public static function getPosterImage(array $base, int $size = 1): string
{
return $base['posterImage']['views'][$size]['url']
?? $base['posterImage']['original']['url']
?? '/public/images/placeholder.png';
}
/**
* Get the name and logo for the streaming service of the current link
*