Merge pull request #280 from eai04191/feature/remove-status-200
不要な成否判定の削除
This commit is contained in:
commit
92847fefe0
@ -25,7 +25,6 @@ class CienResolver extends MetadataResolver
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
// 画像URLから有効期限の起点を拾う
|
||||
@ -36,8 +35,5 @@ class CienResolver extends MetadataResolver
|
||||
$metadata->expires_at = Carbon::createFromTimestamp($params['px-time'])->addHour(1);
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ class DLsiteResolver implements Resolver
|
||||
}
|
||||
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@ -124,8 +123,5 @@ class DLsiteResolver implements Resolver
|
||||
$metadata->tags = $this->extractTags($res->getBody());
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class FC2ContentsResolver implements Resolver
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@ -37,8 +36,5 @@ class FC2ContentsResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ class FantiaResolver implements Resolver
|
||||
$postId = $match[0];
|
||||
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@ -49,8 +48,5 @@ class FantiaResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,14 +24,10 @@ class FanzaResolver implements Resolver
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
$metadata->image = preg_replace("~(pr|ps)\.jpg$~", 'pl.jpg', $metadata->image);
|
||||
$metadata->description = str_replace('<>', '', $metadata->description);
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ class IwaraResolver implements Resolver
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = new Metadata();
|
||||
$html = (string) $res->getBody();
|
||||
$crawler = new Crawler($html);
|
||||
@ -57,8 +56,5 @@ class IwaraResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,14 +24,12 @@ class KomifloResolver implements Resolver
|
||||
$id = $matches[1];
|
||||
|
||||
$res = $this->client->get('https://api.komiflo.com/content/id/' . $id);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$json = json_decode($res->getBody()->getContents(), true);
|
||||
$metadata = new Metadata();
|
||||
|
||||
$metadata->title = $json['content']['data']['title'] ?? '';
|
||||
$metadata->description = ($json['content']['attributes']['artists']['children'][0]['data']['name'] ?? '?') .
|
||||
' - ' .
|
||||
($json['content']['parents'][0]['data']['title'] ?? '?');
|
||||
' - ' . ($json['content']['parents'][0]['data']['title'] ?? '?');
|
||||
$metadata->image = 'https://t.komiflo.com/564_mobile_large_3x/' . $json['content']['named_imgs']['cover']['filename'];
|
||||
|
||||
// 作者情報
|
||||
@ -49,8 +47,5 @@ class KomifloResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ class MelonbooksResolver implements Resolver
|
||||
$cookieJar = CookieJar::fromArray(['AUTH_ADULT' => '1'], 'www.melonbooks.co.jp');
|
||||
|
||||
$res = $this->client->get($url, ['cookies' => $cookieJar]);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@ -65,8 +64,5 @@ class MelonbooksResolver implements Resolver
|
||||
$metadata->description = trim($description);
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ class NarouResolver implements Resolver
|
||||
$cookieJar = CookieJar::fromArray(['over18' => 'yes'], '.syosetu.com');
|
||||
|
||||
$res = $this->client->get($url, ['cookies' => $cookieJar]);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
$metadata->description = '';
|
||||
|
||||
@ -53,8 +52,5 @@ class NarouResolver implements Resolver
|
||||
$metadata->description = implode(' / ', $description);
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ class NijieResolver implements Resolver
|
||||
}
|
||||
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$html = (string) $res->getBody();
|
||||
$metadata = $this->ogpResolver->parse($html);
|
||||
$crawler = new Crawler($html);
|
||||
@ -56,8 +55,5 @@ class NijieResolver implements Resolver
|
||||
$metadata->tags = $crawler->filter('#view-tag span.tag_name')->extract('_text');
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,7 @@ class OGPResolver implements Resolver, Parser
|
||||
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
return $this->parse($res->getBody());
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
return $this->parse($this->client->get($url)->getBody());
|
||||
}
|
||||
|
||||
public function parse(string $html): Metadata
|
||||
|
@ -25,7 +25,6 @@ class PatreonResolver implements Resolver
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
parse_str(parse_url($metadata->image, PHP_URL_QUERY), $query);
|
||||
@ -35,8 +34,5 @@ class PatreonResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,14 +38,10 @@ class PixivResolver implements Resolver
|
||||
{
|
||||
if (preg_match('~www\.pixiv\.net/user/\d+/series/\d+~', $url, $matches)) {
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
$metadata->image = $this->proxize($metadata->image);
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
|
||||
parse_str(parse_url($url, PHP_URL_QUERY), $params);
|
||||
@ -58,7 +54,6 @@ class PixivResolver implements Resolver
|
||||
}
|
||||
|
||||
$res = $this->client->get('https://www.pixiv.net/ajax/illust/' . $illustId);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$json = json_decode($res->getBody()->getContents(), true);
|
||||
$metadata = new Metadata();
|
||||
|
||||
@ -68,7 +63,7 @@ class PixivResolver implements Resolver
|
||||
|
||||
// ページ数の指定がある場合は画像URLをそのページにする
|
||||
if ($page != 0) {
|
||||
$metadata->image = str_replace('_p0', '_p'.$page, $metadata->image);
|
||||
$metadata->image = str_replace('_p0', '_p' . $page, $metadata->image);
|
||||
}
|
||||
|
||||
// タグ
|
||||
@ -82,8 +77,5 @@ class PixivResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class PlurkResolver implements Resolver
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@ -37,8 +36,5 @@ class PlurkResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class SteamResolver implements Resolver
|
||||
$appid = $matches[1];
|
||||
|
||||
$res = $this->client->get('https://store.steampowered.com/api/appdetails/?l=japanese&appids=' . $appid);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$json = json_decode($res->getBody()->getContents(), true);
|
||||
if ($json[$appid]['success'] === false) {
|
||||
throw new \RuntimeException("API response [$appid][success] is false: $url");
|
||||
@ -37,8 +36,5 @@ class SteamResolver implements Resolver
|
||||
$metadata->image = $data['header_image'] ?? '';
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ class ToranoanaResolver implements Resolver
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@ -37,8 +36,5 @@ class ToranoanaResolver implements Resolver
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace Tests\Unit\MetadataResolver;
|
||||
use App\MetadataResolver\Resolver;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Monolog\Handler\AbstractHandler;
|
||||
|
||||
@ -41,7 +42,7 @@ trait CreateMockedResolver
|
||||
|
||||
$mockResponse = new Response($status, $headers, $responseText);
|
||||
$this->handler = new MockHandler([$mockResponse]);
|
||||
$client = new Client(['handler' => $this->handler]);
|
||||
$client = new Client(['handler' => HandlerStack::create($this->handler)]);
|
||||
$this->resolver = app()->make($resolverClass, ['client' => $client]);
|
||||
|
||||
return $this->resolver;
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace Tests\Unit\MetadataResolver;
|
||||
|
||||
use App\MetadataResolver\OGPResolver;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\BadResponseException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OGPResolverTest extends TestCase
|
||||
@ -14,7 +14,7 @@ class OGPResolverTest extends TestCase
|
||||
{
|
||||
$this->createResolver(OGPResolver::class, '', [], 404);
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectException(BadResponseException::class);
|
||||
$this->resolver->resolve('http://example.com/404');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user