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.
support deleting files and refacto jobs
- Loading branch information
1 parent
504d2c4
commit 944ba86
Showing
10 changed files
with
353 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Finller\LaravelMedia\Jobs; | ||
|
||
use Finller\LaravelMedia\Media; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Spatie\TemporaryDirectory\TemporaryDirectory; | ||
|
||
class ConversionJob implements ShouldBeUnique, ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public TemporaryDirectory $temporaryDirectory; | ||
|
||
public function __construct(public Media $media, public string $conversion) | ||
{ | ||
$this->temporaryDirectory = (new TemporaryDirectory())->deleteWhenDestroyed()->create(); | ||
} | ||
|
||
public function uniqueId() | ||
{ | ||
return "{$this->media->id}:{$this->conversion}"; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Finller\LaravelMedia\Jobs; | ||
|
||
use Finller\LaravelMedia\Media; | ||
use Spatie\Image\Image; | ||
use Spatie\Image\Manipulations; | ||
|
||
class OptimizedImageConversionJob extends ConversionJob | ||
{ | ||
public function __construct(public Media $media, public string $conversion, public ?int $width = null, public ?int $height = null) | ||
{ | ||
parent::__construct($media, $conversion); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$temporaryFilePath = $this->temporaryDirectory->path('file'); | ||
|
||
$this->media->copyFileTo($temporaryFilePath); | ||
|
||
Image::load($temporaryFilePath) | ||
->manipulate(function (Manipulations $manipulations) { | ||
if ($this->width || $this->height) { | ||
$manipulations->fit(Manipulations::FIT_MAX, $this->width, $this->height); | ||
} | ||
|
||
$manipulations->optimize(); | ||
}) | ||
->save(); | ||
|
||
$this->media->storeConversion($temporaryFilePath, $this->conversion, $this->media->name); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Finller\LaravelMedia; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
/** | ||
* @property Collection<int, MediaConversion> $conversions | ||
*/ | ||
class MediaCollection | ||
{ | ||
public function __construct( | ||
public ?array $acceptedMimeTypes = null, | ||
public Collection $conversions = new Collection() | ||
) { | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Finller\LaravelMedia; | ||
|
||
use Finller\LaravelMedia\Jobs\ConversionJob; | ||
|
||
class MediaConversion | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public string|ConversionJob $job | ||
) { | ||
} | ||
} |
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
Oops, something went wrong.