Modifs cache
This commit is contained in:
@@ -4,7 +4,6 @@ namespace Meoran\Images\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Intervention\Image\Exception\NotReadableException;
|
||||
use Intervention\Image\Image as InterventionImage;
|
||||
use Meoran\Images\Exception\InvalidContent;
|
||||
@@ -81,10 +80,10 @@ class Image extends Model
|
||||
static function getAbsolutePath($filename)
|
||||
{
|
||||
$basePath = config('image.path');
|
||||
|
||||
if (empty($basePath)) {
|
||||
throw new \Exception('You must defined config image.path');
|
||||
}
|
||||
$parts = array_slice(str_split(mb_strtolower(str_slug($filename, '')), 2), 0, 2);
|
||||
|
||||
|
||||
$path = $basePath . '/' . implode('/', $parts) . '/' . $filename;
|
||||
|
||||
return $path;
|
||||
@@ -126,24 +125,33 @@ class Image extends Model
|
||||
public function setContentAttribute($content)
|
||||
{
|
||||
$this->_content = app('image')->make($content);
|
||||
$this->setHash();
|
||||
}
|
||||
|
||||
public function getHashAttribute()
|
||||
{
|
||||
if (!array_key_exists('hash', $this->attributes)) {
|
||||
$this->setHash();
|
||||
if (empty($this->content)) {
|
||||
return null;
|
||||
}
|
||||
return $this->attributes['hash'];
|
||||
if (empty($this->content->getEncoded())) {
|
||||
$this->content->encode();
|
||||
}
|
||||
return sha1($this->content->getEncoded());
|
||||
}
|
||||
|
||||
protected function setHash()
|
||||
public function getExtensionAttribute()
|
||||
{
|
||||
if (empty($this->content)) {
|
||||
$this->attributes['hash'] = null;
|
||||
return;
|
||||
$mime = $this->content->mime();
|
||||
if (empty($mime)) {
|
||||
return null;
|
||||
}
|
||||
$this->attributes['hash'] = sha1($this->content->getEncoded());
|
||||
return str_replace('image/', '', $mime);
|
||||
}
|
||||
|
||||
public function getMimeAttribute() {
|
||||
if (empty($this->content)) {
|
||||
return null;
|
||||
}
|
||||
return $this->content->mime();
|
||||
}
|
||||
|
||||
public function same(Image $image)
|
||||
@@ -230,7 +238,4 @@ class Image extends Model
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
public function scopeContent(Builder $builder, Image $image) {
|
||||
$builder->where('hash', $image->hash);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user