adds media thumbnail

This commit is contained in:
buttle 2021-06-27 12:25:47 +02:00
parent 1b9b6a6f15
commit 191087a1e4
2 changed files with 20 additions and 3 deletions

View File

@ -5,16 +5,24 @@ use Omeka\Api\Request;
use Omeka\Entity\Media;
use Omeka\Media\Ingester\IngesterInterface;
use Omeka\Stdlib\ErrorStore;
use Omeka\File\Downloader;
use Zend\Form\Element\Text;
use Zend\Http\Client;
use Zend\View\Renderer\PhpRenderer;
class SketchfabMediaIngester implements IngesterInterface
{
/**
* @var Downloader
*/
protected $downloader;
protected $client;
public function __construct($client)
public function __construct($client, Downloader $downloader)
{
$this->client = $client;
$this->downloader = $downloader;
}
public function getLabel()
{
@ -54,8 +62,14 @@ class SketchfabMediaIngester implements IngesterInterface
));
return false;
}
$response_body = json_decode($response->getBody());
$thumbnail_url = $response_body->thumbnail_url;
$tempFile = $this->downloader->download($thumbnail_url);
if ($tempFile) {
$tempFile->mediaIngestFile($media, $request, $errorStore, false);
}
// Set the Media source and data.
$media->setSource($data['o:source']);
$media->setData(json_decode($response->getBody(), true));;
$media->setData($response_body, true));
}
}

View File

@ -11,6 +11,9 @@ class SketchfabMediaFactory implements FactoryInterface
$requestedName,
array $options = null)
{
return new SketchfabMediaIngester($services->get('Omeka\HttpClient'));
return new SketchfabMediaIngester(
$services->get('Omeka\HttpClient'),
$services->get('Omeka\File\Downloader')
);
}
}