dc8a70291d
なんかもともと入っているurlが十分大きいので置換する必要がないことに気が付きました
40 lines
941 B
PHP
40 lines
941 B
PHP
<?php
|
|
|
|
namespace App\MetadataResolver;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
class DeviantArtResolver implements Resolver
|
|
{
|
|
/**
|
|
* @var Client
|
|
*/
|
|
private $client;
|
|
/**
|
|
* @var OGPResolver
|
|
*/
|
|
private $ogpResolver;
|
|
|
|
public function __construct(Client $client, OGPResolver $ogpResolver)
|
|
{
|
|
$this->client = $client;
|
|
$this->ogpResolver = $ogpResolver;
|
|
}
|
|
|
|
public function resolve(string $url): Metadata
|
|
{
|
|
$res = $this->client->get('https://backend.deviantart.com/oembed?url=' . $url);
|
|
$data = json_decode($res->getBody()->getContents(), true);
|
|
$metadata = new Metadata();
|
|
|
|
$metadata->title = $data['title'] ?? '';
|
|
$metadata->description = 'By ' . $data['author_name'];
|
|
$metadata->image = $data['url'];
|
|
if (isset($data['tags'])) {
|
|
$metadata->tags = explode(', ', $data['tags']);
|
|
}
|
|
|
|
return $metadata;
|
|
}
|
|
}
|