Skip to content

Commit

Permalink
Check if Conversion is actually needed (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschucki authored Dec 28, 2024
1 parent 034560d commit d888c30
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions app/Jobs/ConversionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function handle(): void
'status' => 'preparing',
]);

$conversionNeeded = $this->checkIfConversionIsActuallyNeeded($conversion);

if ($conversionNeeded === false) {
return;
}

$conversion = $conversion->loadMissing('file');

// the file needs to be named differently as the input can not be the same as Input
Expand Down Expand Up @@ -106,4 +112,52 @@ public function handle(): void
'downloadable' => true,
]);
}

private function checkIfConversionIsActuallyNeeded(Conversion $conversion): bool
{
$hasAdditionalOperations = false;
$hasCorrectExtension = false;
$hasCorrectSize = false;

$file = Storage::disk($conversion->file->disk)->path($conversion->file->filename);
$size = Storage::disk($conversion->file->disk)->size($conversion->file->filename);

$extension = pathinfo($file, PATHINFO_EXTENSION);

if ($extension === 'mp4' || $extension === 'webm') {
$conversion->update([
'status' => 'finished',
'downloadable' => true,
]);
Log::info('Datei ist bereits mp4 oder webm');
$hasCorrectExtension = true;
}

if ($size <= $conversion->max_size * 1024 * 1024) {
$conversion->update([
'status' => 'finished',
'downloadable' => true,
]);

$hasCorrectSize = true;
}

if (
$conversion->audio_quality !== 1 &&
$conversion->audio === false &&
$conversion->watermark === true &&
$conversion->auto_crop === true &&
$conversion->trim_start !== null &&
$conversion->trim_end !== null
) {
$conversion->update([
'status' => 'finished',
'downloadable' => true,
]);

$hasAdditionalOperations = true;
}

return ! $hasCorrectExtension || ! $hasCorrectSize || $hasAdditionalOperations;
}
}

0 comments on commit d888c30

Please sign in to comment.