fix style

This commit is contained in:
shibafu 2019-03-03 00:29:43 +09:00
parent f21e58650d
commit e966995dea
9 changed files with 12 additions and 8 deletions

View File

@ -2,7 +2,6 @@
namespace App\Http\Controllers\Api;
use App\Metadata;
use App\MetadataResolver\MetadataResolver;
use App\Utilities\Formatter;

View File

@ -2,8 +2,8 @@
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{

View File

@ -2,9 +2,9 @@
namespace App\MetadataResolver;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
class ActivityPubResolver implements Resolver, Parser
{
@ -40,7 +40,7 @@ class ActivityPubResolver implements Resolver, Parser
$metadata = new Metadata();
$metadata->title = isset($object['attributedTo']) ? $this->getTitleFromActor($object['attributedTo']) : '';
$metadata->description .= isset($object['summary']) ? $object['summary'] . " | " : '';
$metadata->description .= isset($object['summary']) ? $object['summary'] . ' | ' : '';
$metadata->description .= isset($object['content']) ? $this->html2text($object['content']) : '';
$metadata->image = $object['attachment'][0]['url'] ?? '';
@ -53,6 +53,7 @@ class ActivityPubResolver implements Resolver, Parser
$res = $this->activityClient->get($url);
if ($res->getStatusCode() !== 200) {
Log::info(self::class . ': Actorの取得に失敗 URL=' . $url);
return '';
}
@ -65,6 +66,7 @@ class ActivityPubResolver implements Resolver, Parser
return $title;
} catch (TransferException $e) {
Log::info(self::class . ': Actorの取得に失敗 URL=' . $url);
return '';
}
}
@ -75,6 +77,7 @@ class ActivityPubResolver implements Resolver, Parser
$html = preg_replace('~<br\s*/?\s*>|</p>\s*<p[^>]*>~i', "\n", $html);
$dom = new \DOMDocument();
$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
return $dom->textContent;
}
}

View File

@ -21,6 +21,7 @@ class FantiaResolver implements Resolver
$this->client = $client;
$this->ogpResolver = $ogpResolver;
}
public function resolve(string $url): Metadata
{
preg_match("~\d+~", $url, $match);

View File

@ -53,6 +53,7 @@ class MetadataResolver implements Resolver
if (isset($this->defaultResolver)) {
/** @var Resolver $resolver */
$resolver = app($this->defaultResolver);
return $resolver->resolve($url);
}

View File

@ -5,4 +5,4 @@ namespace App\MetadataResolver;
interface Parser
{
public function parse(string $body): Metadata;
}
}

View File

@ -28,7 +28,6 @@ class ToranoanaResolver implements Resolver
$res = $this->client->get($url, ['cookies' => $cookieJar]);
if ($res->getStatusCode() === 200) {
return $this->ogpResolver->parse($res->getBody());
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");

View File

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddBioAndUrlToUsers extends Migration
{

View File

@ -43,6 +43,7 @@ trait CreateMockedResolver
$this->handler = new MockHandler([$mockResponse]);
$client = new Client(['handler' => $this->handler]);
$this->resolver = app()->make($resolverClass, ['client' => $client]);
return $this->resolver;
}