Commit 00eb138b authored by Patrick Barroca's avatar Patrick Barroca 😁
Browse files

fullsize in JSON response is an absolute url

parent 9b25f3d8
Pipeline #11808 passed with stage
in 45 seconds
......@@ -11,9 +11,8 @@ class Media {
$response->getBody()->write($fetch_result->asJSON());
return $response
->withStatus($fetch_result->getStatusCode())
->withHeader('Content-Type', 'application/json');
return $response->withStatus($fetch_result->getStatusCode())
->withHeader('Content-Type', 'application/json');
}
......
......@@ -3,6 +3,7 @@ namespace Pellicule\Models;
use \Storm\Model\ModelAbstract;
use \Pellicule\StormFileSystem;
use \Pellicule\Url;
use \Pellicule\Traits\TimeSource;
......@@ -36,13 +37,18 @@ class Media extends ModelAbstract {
public function getJsonAttributes() {
return array_intersect_key($this->getRawAttributes(),
['type' => 1,
'url' => 1,
'fullsize' => 1,
'provider' => 1,
'created_at' => 1,
'updated_at' => 1]);
$attribs = array_intersect_key($this->getRawAttributes(),
['type' => 1,
'url' => 1,
'fullsize' => 1,
'provider' => 1,
'created_at' => 1,
'updated_at' => 1]);
if ($attribs['fullsize'])
$attribs['fullsize'] = (new Url)->absolute($attribs['fullsize']);
return $attribs;
}
......
......@@ -29,6 +29,7 @@ class FetchRecordResult {
: json_encode(['error' => $this->_error_code]);
}
public function getStatusCode(){
return $this->_status_code;
}
......
......@@ -3,9 +3,8 @@ namespace Pellicule\Providers;
use \Pellicule\HttpClientAware;
use \Pellicule\Models\Record;
use \Pellicule\Providers\FetchRecordResult;
use \Fig\Http\Message\StatusCodeInterface;
use \Storm\Collection;
use \Fig\Http\Message\StatusCodeInterface;
......@@ -78,7 +77,7 @@ abstract class Provider {
public function setSearchArgs($args) {
if (isset($args['isbn'])|| isset($args['ean']))
if (isset($args['isbn']) || isset($args['ean']))
$this->_search_args = $args;
return $this;
......
<?php
namespace Pellicule;
class Url {
public function absolute($path) {
if ($this->_hasScheme($path))
return $path;
if ('/' != substr($path, 0, 1))
$path = '/' . $path;
return $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $path;
}
protected function _hasScheme($url) {
return preg_match('|http[s]?://|', $url);
}
}
......@@ -150,7 +150,7 @@ abstract class MediaWithElectreTestCase extends TestCase {
[ 'media' => [
['url'=> 'http://image.org/city.jpg',
'provider' => 'Electre',
'fullsize' => '/images/fullsize/cover/2/2/5/9/2259228194',
'fullsize' => 'http://pellicule.io:8899/images/fullsize/cover/2/2/5/9/2259228194',
'type' => 'cover',
'created_at' => (new \DateTime())->format('Y-m-d H:i:s'),
'updated_at' => (new \DateTime())->format('Y-m-d H:i:s')
......@@ -428,7 +428,7 @@ abstract class MediaWithOrbTestCase extends TestCase {
[ 'media' => [
['url'=> 'https://products-images.di-static.com/image/orb-9162f416a0b7b2e64a1f5480db8d4394/2259228234-475x500-1.jpg',
'provider' => 'Orb',
'fullsize' => '/images/fullsize/cover/2/2/5/9/2259228234',
'fullsize' => 'http://pellicule.io:8899/images/fullsize/cover/2/2/5/9/2259228234',
'type' => 'cover',
'created_at' => '2020-01-01 00:00:00',
'updated_at' => '2020-01-01 00:00:00'
......
......@@ -31,6 +31,9 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
$this->_http_client = $this->mock();
Provider::setDefaultHttpClient($this->_http_client);
$_SERVER['REQUEST_SCHEME'] = 'http';
$_SERVER['HTTP_HOST'] = 'pellicule.io:8899';
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment