generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from konnco/feature/auto-resize
Feature/auto resize
- Loading branch information
Showing
8 changed files
with
224 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Konnco\ImageCast; | ||
|
||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Str; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
class ImageCastExceptionHandler | ||
{ | ||
public function __construct($exception, $url, $callback) | ||
{ | ||
if ($exception instanceof NotFoundHttpException) { | ||
if (Str::contains($url, config('imagecast.cache.identifier'))) { | ||
// remove site url with the identifiers | ||
$url = str_replace(config('app.url')."/".config('imagecast.cache.identifier')."/", "", $url); | ||
$fullPath = $this->extractFileName($url); | ||
$fingerprint = $this->extractFingerprint($fullPath); | ||
$filters = $this->extractFilters($url); | ||
// dd(($fingerprint['class'])::get()); | ||
// dd($fileName); | ||
$eloquent = ($fingerprint['class'])::where($fingerprint['field'], 'like', "%".basename($fullPath)."%")->first(); | ||
if ($eloquent) { | ||
// dd($fingerprint['field']); | ||
$field = $fingerprint['field']; | ||
$eloquent->$field->temporaryResize($filters); | ||
} | ||
|
||
return redirect($url); | ||
} | ||
} | ||
|
||
return $callback(); | ||
} | ||
|
||
private function extractFilters($url) | ||
{ | ||
$urlArray = explode('/', $url); | ||
$filters = explode(',', $urlArray[0]); | ||
|
||
return $filters; | ||
} | ||
|
||
private function extractFileName($url) | ||
{ | ||
$urlArray = explode('/', $url); | ||
array_shift($urlArray); | ||
|
||
return implode("/", $urlArray); | ||
} | ||
|
||
private function extractFingerprint($url) | ||
{ | ||
$fingerprint = Storage::disk(config('imagecast.disk'))->get($url.".fingerprint"); | ||
|
||
return json_decode($fingerprint, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ResizeImage implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
protected $model; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters