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} /> <input type="radio" class="big-check" id="${item.slug}" name="id" value="${item.id}" ${disabled} />
<label for="${item.slug}"> <label for="${item.slug}">
<picture width="220"> <picture width="220">
<source srcset="/public/images/${type}/${item.id}.webp" type="image/webp" /> <img src="${item.coverImage}" alt="" width="220" />
<source srcset="/public/images/${type}/${item.id}.jpg" type="image/jpeg" />
<img src="/public/images/${type}/${item.id}.jpg" alt="" width="220" />
</picture> </picture>
<span class="name"> <span class="name">
${item.canonicalTitle}<br /> ${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 = [ $searchItem = [
'id' => $item['id'], 'id' => $item['id'],
'slug' => $item['slug'], 'slug' => $item['slug'],
'coverImage' => K::getPosterImage($item),
'canonicalTitle' => $item['titles']['canonical'], 'canonicalTitle' => $item['titles']['canonical'],
'titles' => array_values(K::getTitles($item['titles'])), 'titles' => array_values(K::getTitles($item['titles'])),
'libraryEntry' => $item['myLibraryEntry'], 'libraryEntry' => $item['myLibraryEntry'],

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -336,6 +336,20 @@ final class Kitsu {
return $valid; 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 * Get the name and logo for the streaming service of the current link
* *