Skip to content

Commit

Permalink
use TemporaryFile for FileManipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech committed Sep 15, 2023
1 parent eee3ac7 commit 66d3ea8
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/Conversions/FileManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
namespace Spatie\MediaLibrary\Conversions;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\MediaLibrary\Conversions\Actions\PerformConversionAction;
use Spatie\MediaLibrary\Conversions\ImageGenerators\ImageGeneratorFactory;
use Spatie\MediaLibrary\Conversions\Jobs\PerformConversionsJob;
use Spatie\MediaLibrary\MediaCollections\Filesystem;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\ResponsiveImages\Jobs\GenerateResponsiveImagesJob;
use Spatie\MediaLibrary\Support\TemporaryDirectory;
use Spatie\MediaLibrary\Support\TemporaryFile;

class FileManipulator
{
Expand Down Expand Up @@ -50,12 +48,7 @@ public function performConversions(
return $this;
}

$temporaryDirectory = TemporaryDirectory::create();

$copiedOriginalFile = app(Filesystem::class)->copyFromMediaLibrary(
$media,
$temporaryDirectory->path(Str::random(32) . '.' . $media->extension)
);
$temporaryFile = app(TemporaryFile::class, ['media' => $media]);

$conversions
->reject(function (Conversion $conversion) use ($onlyMissing, $media) {
Expand All @@ -67,12 +60,10 @@ public function performConversions(

return $onlyMissing && Storage::disk($media->disk)->exists($relativePath);
})
->each(function (Conversion $conversion) use ($media, $copiedOriginalFile) {
(new PerformConversionAction())->execute($conversion, $media, $copiedOriginalFile);
->each(function (Conversion $conversion) use ($media, $temporaryFile) {
(new PerformConversionAction())->execute($conversion, $media, $temporaryFile->getFile());
});

$temporaryDirectory->delete();

return $this;
}

Expand Down

0 comments on commit 66d3ea8

Please sign in to comment.